From ac3415f653a771d8ec12647461a7336ee1387102 Mon Sep 17 00:00:00 2001 From: Timofey Myagkikh Date: Tue, 9 Apr 2024 22:25:27 +0300 Subject: [PATCH] scripts replaced with makefile --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++ README.md | 34 ++++++++++++++-------------- deploy_helm.sh | 3 --- generate_cert.sh | 10 --------- src/Makefile | 38 +++++++++++++++++++++++++++++++ src/analyze.sh | 4 ---- src/api/src/endpoints.rs | 2 +- src/build.sh | 3 --- src/build_images.sh | 3 --- src/format.sh | 4 ---- src/run.sh | 3 --- src/run_tests.sh | 4 ---- 12 files changed, 103 insertions(+), 53 deletions(-) create mode 100644 Makefile delete mode 100755 deploy_helm.sh delete mode 100755 generate_cert.sh create mode 100644 src/Makefile delete mode 100755 src/analyze.sh delete mode 100755 src/build.sh delete mode 100755 src/build_images.sh delete mode 100755 src/format.sh delete mode 100755 src/run.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c22f90 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +setup: +# install brew if not installed +ifeq (, $(shell which brew)) + $(info "brew not found, install...") + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +endif +# install docker if not installed +ifeq (, $(shell which docker)) + $(info "docker not found, install...") + brew install --cask docker +endif +# install helm if not installed +ifeq (, $(shell which helm)) + $(info "helm not found, install...") + brew install helm +endif +# install rust if not installed +ifeq (, $(shell which rustc)) + $(info "rust not found, install...") + curl https://sh.rustup.rs -sSf | sh +endif +# update /etc/hosts (required for deploy with helm) +ifeq (, $(shell cat /etc/hosts | grep dev-wep-api.com)) + $(info "update /etc/hosts...") + echo "127.0.0.1 dev-wep-api.com" | sudo tee -a /etc/hosts +endif + rustup component add rustfmt + rustup component add clippy + rustup component add llvm-tools-preview + cargo install grcov + +deploy: + openssl req \ + -x509 -newkey rsa:4096 -sha256 -nodes \ + -keyout tls.key -out tls.crt \ + -subj "/CN=ingress.local" -days 365 + + kubectl create secret tls api-secret \ + --cert=tls.crt \ + --key=tls.key + + helm upgrade --install --atomic --timeout 300s --wait web-api-dev helm + +delete: + helm delete web-api-dev --purge + +uninstall: + rustup self uninstall -y \ No newline at end of file diff --git a/README.md b/README.md index fb4702f..7a12387 100644 --- a/README.md +++ b/README.md @@ -24,27 +24,25 @@ Web api application prototype written in rust - `host` - host process for application with composition root - `integration-tests` - integration tests for application -## Dev environment - -- `docker` v24.0.6 -- `docker-compose` v2.23.0 -- `kubernetes` v1.28.2 -- `rustc` 1.72.1 -- `cargo` 1.72.1 - -For deploing with helm `/etc/hosts` require `127.0.0.1 dev-wep-api.com` entry for access to application in browser. - ## Up & Running +From root folder: +- `make setup` - setup environment (brew, docker, helm, rust) +- `make deploy` - deploy to kubernetes with helm (you should enable k8s support manually) +- `make delete` - delete helm chart +- `make uninstall` - uninstall rust from machine + From src folder: -- `docker-compose up -d` - up dev environment -- `run.sh` - run api application for local debuging -- `build.sh` - build all workspaces -- `build_images.sh` - build `acl` and `api` dev images -- `docker-compose --profile dev-build up -d` - up `acl` and `api` dev images with compose -- `format.sh` - format code -- `analyze.sh` - static analysis -- `run_tests.sh` - build and run tests +- `make up flag=e` - up environment only +- `make up flag=a` - up all include applications +- `make down flag=e` - down environment only +- `make down flag=a` - down all include applications +- `make build flag=l` - build local binaries +- `make build flag=i` - build apps images +- `make lint` - run clippy for static analysis +- `make format` - run fmt for code formatting +- `make tests` - run tests +- `make run` - run local build From root folder: - `generate_cert.sh` - generate self signed cert and create kubernetes secret diff --git a/deploy_helm.sh b/deploy_helm.sh deleted file mode 100755 index 2013a29..0000000 --- a/deploy_helm.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -helm upgrade --install --atomic --timeout 300s --wait web-api-dev helm \ No newline at end of file diff --git a/generate_cert.sh b/generate_cert.sh deleted file mode 100755 index ac49064..0000000 --- a/generate_cert.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -openssl req \ --x509 -newkey rsa:4096 -sha256 -nodes \ --keyout tls.key -out tls.crt \ --subj "/CN=ingress.local" -days 365 - -kubectl create secret tls api-secret \ - --cert=tls.crt \ - --key=tls.key diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..7416e86 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,38 @@ +up: +ifeq ($(flag),e) + docker-compose up -d +else ifeq ($(flag),a) + docker-compose --profile dev-build up -d +else + $(warning "pass flag=e (environment only) or flag=a (all include applications)") +endif + +down: +ifeq ($(flag),e) + docker-compose down +else ifeq ($(flag),a) + docker-compose --profile dev-build down +else + $(warning "pass flag=e (environment only) or flag=a (all include applications)") +endif + +build: +ifeq ($(flag),l) + cargo build --workspace +else ifeq ($(flag),i) + docker-compose --profile dev-build build +else + $(warning "pass flag=l (for build local) or flag=i (for build images)") +endif + +lint: + cargo clippy + +format: + cargo fmt + +run: + ./target/debug/host + +tests: + ./run_tests.sh \ No newline at end of file diff --git a/src/analyze.sh b/src/analyze.sh deleted file mode 100755 index fcd2f04..0000000 --- a/src/analyze.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -rustup component add clippy -cargo clippy \ No newline at end of file diff --git a/src/api/src/endpoints.rs b/src/api/src/endpoints.rs index 69cc39b..b8c83ca 100644 --- a/src/api/src/endpoints.rs +++ b/src/api/src/endpoints.rs @@ -93,6 +93,6 @@ pub async fn track_activity( match result { Some(_) => HttpResponse::Ok().json(()), - None => HttpResponse::BadRequest().json(ErrorResponse { code: 103 }) + None => HttpResponse::BadRequest().json(ErrorResponse { code: 103 }), } } diff --git a/src/build.sh b/src/build.sh deleted file mode 100755 index aeb32ea..0000000 --- a/src/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cargo build --workspace \ No newline at end of file diff --git a/src/build_images.sh b/src/build_images.sh deleted file mode 100755 index 0b6dff2..0000000 --- a/src/build_images.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -docker-compose --profile dev-build build \ No newline at end of file diff --git a/src/format.sh b/src/format.sh deleted file mode 100755 index ea78c1c..0000000 --- a/src/format.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -rustup component add rustfmt -cargo fmt \ No newline at end of file diff --git a/src/run.sh b/src/run.sh deleted file mode 100755 index 265b335..0000000 --- a/src/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -./target/debug/host \ No newline at end of file diff --git a/src/run_tests.sh b/src/run_tests.sh index 4d24163..3fcc6fb 100755 --- a/src/run_tests.sh +++ b/src/run_tests.sh @@ -1,9 +1,5 @@ #!/bin/bash -# install tools -cargo install grcov -rustup component add llvm-tools-preview - # set coverage directory path timestamp="$(date '+%Y-%m-%d_%H-%M-%S')" directory_path="target/coverage/${timestamp}"