Skip to content

Commit

Permalink
Merge pull request #6 from husni-zuhdi/update-docker-compose-and-post…
Browse files Browse the repository at this point in the history
…gres-envar

Update docker compose and postgres envar
  • Loading branch information
husni-zuhdi authored Aug 14, 2024
2 parents e42efc8 + e84b0ae commit 4a81233
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 43 deletions.
53 changes: 35 additions & 18 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@ tasks:
summary: Run unit test with logs
cmds:
- RUST_LOG=debug cargo test -- --nocapture
build:
run:
summary: Run application with hot-reload
cmds:
# Add tailwindcss build for hot reloading
- tailwindcss -i ./statics/input.css -o ./statics/styles.css
- cargo watch -s 'export $(cat .env | xargs) && cargo run -- -release'

docker-build:
summary: Build Docker Image
cmds:
- docker build -t husni-portfolio:$(cat version.json | jq --raw-output '.version') .
build-tailwind:
summary: Build tailwindcss
docker-run:
summary: Run Docker Image
cmds:
- tailwindcss -i ./statics/input.css -o ./statics/styles.css
run:
summary: Run application with hot-reload
- docker run --name husni-portfolio-$(date +'%Y-%m-%d-%H-%M-%S') -it -d --env-file=.env husni-portfolio:$(cat version.json | jq --raw-output '.version')
docker-compose-up:
summary: Run application in docker compose with database
deps:
- build-tailwind
- tailwind-build
- update-version
- docker-build
cmds:
- cargo watch -s 'export $(cat .env | xargs) && cargo run -- -release'
update_version:
- |
export $(cat .env | xargs)
export SVC_VERSION=$(cat version.json | jq --raw-output '.version')
cd build
docker compose up -d
docker-compose-down:
summary: Teardown docker compose
cmds:
- |
export $(cat .env | xargs)
export SVC_VERSION=$(cat version.json | jq --raw-output '.version')
cd build
docker compose down
tailwind-build:
summary: Build tailwindcss
cmds:
- tailwindcss -i ./statics/input.css -o ./statics/styles.css
update-version:
summary: Update version manifest
cmds:
- |
Expand All @@ -30,12 +56,3 @@ tasks:
"build_hash": "$(git rev-parse HEAD)"
}
EOF
compose-run:
summary: Run application in docker compose with database
deps:
- build-tailwind
cmds:
- |
export $(cat .env | xargs)
cd build
docker compose up -d
18 changes: 9 additions & 9 deletions build/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: testing-htmx
name: husni-portfolio
version: "3"

services:
# notion-dashboard:
# image: "notion-dashboard:${NOTION_DASHBOARD_VERSION}"
# env_file:
# - "../.compose.env"
husni-portfolio:
image: "husni-portfolio:${SVC_VERSION}"
env_file:
- "../.env"
ports:
- ${SVC_PORT}:${SVC_PORT}
db:
image: postgres:12-alpine
restart: always
environment:
- POSTGRES_PASSWORD
- POSTGRES_USER
- POSTGRES_DB
env_file:
- "../.env"
ports:
- 5432:5432
volumes:
Expand Down
10 changes: 5 additions & 5 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ SVC_ENDPOINT="127.0.0.1"
SVC_PORT="8080"
LOG_LEVEL="info"
ENVIRONMENT="dev"
POSTGRE_USER="admin"
POSTGRE_PASSWORD="admin-password"
POSTGRE_DB="testing"
POSTGRE_HOST="127.0.0.1"
POSTGRE_PORT="5432"
POSTGRES_USER="admin"
POSTGRES_PASSWORD="admin-password"
POSTGRES_DB="testing"
POSTGRES_HOST="127.0.0.1"
POSTGRES_PORT="5432"
22 changes: 11 additions & 11 deletions internal/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ impl Config {
let environment: String =
env::var("ENVIRONMENT").expect("Failed to load ENVIRONMENT environment variable");
let postgre_user: String =
env::var("POSTGRE_USER").expect("Failed to load POSTGRE_USER environment variable");
let postgre_password: String = env::var("POSTGRE_PASSWORD")
.expect("Failed to load POSTGRE_PASSWORD environment variable");
env::var("POSTGRES_USER").expect("Failed to load POSTGRES_USER environment variable");
let postgre_password: String = env::var("POSTGRES_PASSWORD")
.expect("Failed to load POSTGRES_PASSWORD environment variable");
let postgre_db: String =
env::var("POSTGRE_DB").expect("Failed to load POSTGRE_DB environment variable");
env::var("POSTGRES_DB").expect("Failed to load POSTGRES_DB environment variable");
let postgre_host: String =
env::var("POSTGRE_HOST").expect("Failed to load POSTGRE_DB environment variable");
env::var("POSTGRES_HOST").expect("Failed to load POSTGRES_DB environment variable");
let postgre_port: String =
env::var("POSTGRE_PORT").expect("Failed to load POSTGRE_PORT environment variable");
env::var("POSTGRES_PORT").expect("Failed to load POSTGRES_PORT environment variable");

Self {
svc_endpoint,
Expand Down Expand Up @@ -120,11 +120,11 @@ mod test {
env::set_var("SVC_PORT", svc_port);
env::set_var("LOG_LEVEL", log_level);
env::set_var("ENVIRONMENT", environment);
env::set_var("POSTGRE_USER", postgre_user);
env::set_var("POSTGRE_PASSWORD", postgre_password);
env::set_var("POSTGRE_DB", postgre_db);
env::set_var("POSTGRE_HOST", postgre_host);
env::set_var("POSTGRE_PORT", postgre_port);
env::set_var("POSTGRES_USER", postgre_user);
env::set_var("POSTGRES_PASSWORD", postgre_password);
env::set_var("POSTGRES_DB", postgre_db);
env::set_var("POSTGRES_HOST", postgre_host);
env::set_var("POSTGRES_PORT", postgre_port);

let result = Config::from_envar();
assert_eq!(result.svc_endpoint, svc_endpoint);
Expand Down

0 comments on commit 4a81233

Please sign in to comment.