Skip to content

Commit

Permalink
scripts replaced with makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
rdcm committed Apr 9, 2024
1 parent 1c5ace9 commit ac3415f
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 53 deletions.
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions deploy_helm.sh

This file was deleted.

10 changes: 0 additions & 10 deletions generate_cert.sh

This file was deleted.

38 changes: 38 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions src/analyze.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/api/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
}
}
3 changes: 0 additions & 3 deletions src/build.sh

This file was deleted.

3 changes: 0 additions & 3 deletions src/build_images.sh

This file was deleted.

4 changes: 0 additions & 4 deletions src/format.sh

This file was deleted.

3 changes: 0 additions & 3 deletions src/run.sh

This file was deleted.

4 changes: 0 additions & 4 deletions src/run_tests.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down

0 comments on commit ac3415f

Please sign in to comment.