From 8e5a3c73ab4193622b7e4fcced93bcf78fda8e84 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Tue, 7 Jul 2020 22:02:58 +0200 Subject: [PATCH] refactor: project dev structure --- .dockerignore | 1 + .gitignore | 3 +++ Makefile | 4 ++-- Makefile.toml | 12 ++++++++++++ Tasks.Dev.toml | 21 --------------------- Tasks.Prod.toml | 53 ----------------------------------------------------- docker/envoy/.dockerignore | 9 --------- docker/envoy/docker-compose.yml | 36 ------------------------------------ docker/envoy/docker-entrypoint.sh | 6 ------ docker/envoy/sw.envoy.dockerfile | 15 --------------- sample.env | 9 +++++++++ 11 files changed, 27 insertions(+), 142 deletions(-) create mode 100644 Makefile.toml delete mode 100644 Tasks.Dev.toml delete mode 100644 Tasks.Prod.toml delete mode 100644 docker/envoy/.dockerignore delete mode 100644 docker/envoy/docker-compose.yml delete mode 100644 docker/envoy/docker-entrypoint.sh delete mode 100644 docker/envoy/sw.envoy.dockerfile create mode 100644 sample.env diff --git a/.dockerignore b/.dockerignore index 9aaa585..48b8c0d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,4 @@ *docker-compose* Makefile target +**/*.env diff --git a/.gitignore b/.gitignore index baba3f0..e2a69c5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ **/*.tar **/*.gz **/.DS_Store +**/*.env release + +!sample.env diff --git a/Makefile b/Makefile index 60db5c6..26a580b 100644 --- a/Makefile +++ b/Makefile @@ -26,12 +26,12 @@ install: run: @rustc -vV - @cargo make --makefile Tasks.Dev.toml run + @cargo make --makefile Makefile.toml run .PHONY: run dev: @rustc -vV - @cargo make --makefile Tasks.Dev.toml watch + @cargo make --makefile Makefile.toml watch .PHONY: dev build: diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..5bfe690 --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,12 @@ +env_files = [ + { path = "./development.env", profile = "development" }, + { path = "./production.env", profile = "production" } +] + +[tasks.watch] +command = "cargo" +args = ["watch", "-cx", "run -- ${E_ARGS}"] + +[tasks.run] +command = "cargo" +args = ["run", "--", "${E_ARGS}"] diff --git a/Tasks.Dev.toml b/Tasks.Dev.toml deleted file mode 100644 index 300554b..0000000 --- a/Tasks.Dev.toml +++ /dev/null @@ -1,21 +0,0 @@ -[env] -E_ARGS = "--port=8787" -E_URL = "http://locahost" -SERVER_LOG_LEVEL = "trace" -SERVER_ROOT = "./public" -SERVER_ASSETS = "./public/assets" -SERVER_CORS_ALLOW_ORIGINS = "*" - -[tasks.watch] -command = "cargo" -args = ["watch", "-cx", "run -- ${E_ARGS}"] - -[tasks.run] -command = "cargo" -args = ["run", "--", "${E_ARGS}"] - -[tasks.loadtest] -script = [ - "echo GET $E_URL | vegeta -cpus=12 attack -workers=10 -duration=60s -connections=10000 -rate=200 -http2=true | tee results.bin | vegeta report", - "cat results.bin | vegeta report -reporter=plot > plot.html" -] diff --git a/Tasks.Prod.toml b/Tasks.Prod.toml deleted file mode 100644 index fe0a82b..0000000 --- a/Tasks.Prod.toml +++ /dev/null @@ -1,53 +0,0 @@ -[env] -PKG_PLATFORM = "x86_64-unknown-linux-musl" -PKG_NAME = { script = ["cat Cargo.toml | awk 'match($0, /name = \"(.*)\"/, v) {print v[1]}'"] } -PKG_VERSION = { script = ["cat Cargo.toml | awk 'match($0, /version = \"([0-9.].+)\"/, v) {print v[1]}'"] } -PKG_BIN_DIR = "./bin" -PKG_BIN_PATH = "${PKG_BIN_DIR}/${PKG_NAME}" - -[tasks.clean_artifacts] -command = "cargo" -args = ["clean"] - -[tasks.clean_bin] -script = ["rm -rf bin"] - -[tasks.clean] -dependencies = [ - "clean_artifacts", - "clean_bin" -] - -[tasks.test] -command = "cargo" -args = ["test"] -dependencies = ["clean"] - -[tasks.mkdir] -script = ["mkdir -p ${PKG_BIN_DIR}"] - -[tasks.copy] -script = ["cp -rf target/${PKG_PLATFORM}/release/${PKG_NAME} ${PKG_BIN_DIR}"] - -[tasks.strip] -script = ["strip ${PKG_BIN_PATH}"] - -[tasks.size] -script = ["du -sh ${PKG_BIN_PATH}"] - -[tasks.build] -command = "cargo" -args = ["build", "--release", "--target", "${PKG_PLATFORM}"] - -[tasks.docker_image] -script = ["docker build -t ${PKG_NAME} -f ./docker/sws.dockerfile ."] - -[tasks.release] -dependencies = [ - "clean", - "build", - "mkdir", - "copy", - "strip", - "size" -] diff --git a/docker/envoy/.dockerignore b/docker/envoy/.dockerignore deleted file mode 100644 index e1acb5a..0000000 --- a/docker/envoy/.dockerignore +++ /dev/null @@ -1,9 +0,0 @@ -*.~ -.git -**/*.gz -**/*.log -**/*.tar -**/.DS_Store -.gitignore -*docker-compose* -Makefile diff --git a/docker/envoy/docker-compose.yml b/docker/envoy/docker-compose.yml deleted file mode 100644 index 35e2160..0000000 --- a/docker/envoy/docker-compose.yml +++ /dev/null @@ -1,36 +0,0 @@ -version: "3.3" - -services: - - service1: - image: static-web-server:latest - environment: - - SERVER_HOST=127.0.0.1 - - SERVER_PORT=8080 - - SERVER_NAME=Server-1 - - SERVICE_NAME=service1 - - # configs: - # - source: docker_registry_service - # target: /etc/envoy-service.yaml - volumes: - - ./envoy-service.yaml:/etc/envoy-service.yaml - deploy: - replicas: 1 - update_config: - parallelism: 1 - restart_policy: - condition: on-failure - networks: - envoymesh: - aliases: - - service1 - -#configs: -# docker_registry_service: -# external: true - -networks: - envoymesh: - external: - name: envoymesh diff --git a/docker/envoy/docker-entrypoint.sh b/docker/envoy/docker-entrypoint.sh deleted file mode 100644 index 9780215..0000000 --- a/docker/envoy/docker-entrypoint.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -set -e - -/bin/static-web-server & -/usr/local/bin/envoy -c /etc/envoy-service.yaml --service-cluster ${SERVICE_NAME} diff --git a/docker/envoy/sw.envoy.dockerfile b/docker/envoy/sw.envoy.dockerfile deleted file mode 100644 index 9819d6a..0000000 --- a/docker/envoy/sw.envoy.dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM envoyproxy/envoy-alpine:36f39c746eb7d03b762099b206403935b11972d8 - -LABEL maintainer=https://git.io/joseluisq - -RUN set -ex \ - && apk update && apk add --no-cache bash ca-certificates - -ADD bin /bin -ADD public /public -ADD docker/docker-entrypoint.sh /entrypoint.sh - -RUN chmod u+x /bin/static-web-server \ - && chmod u+x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..5b981e7 --- /dev/null +++ b/sample.env @@ -0,0 +1,9 @@ +# Server binary arguments (development) +E_ARGS = "--port=8787" + +# Server configuration + +SERVER_LOG_LEVEL = "trace" +SERVER_ROOT = "./public" +SERVER_ASSETS = "./public/assets" +SERVER_CORS_ALLOW_ORIGINS = "*" -- libgit2 1.7.2