From 27cab1505c3d72a52909938f4a406d72c5a355df Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 28 Aug 2024 14:24:16 +0200 Subject: [PATCH] Dockerize auth service --- .gitignore | 3 +- .../authentication-service.dockerfile | 8 +++++ project/Makefile | 17 +++++++--- project/docker-compose.yml | 33 +++++++++++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 authentication-service/authentication-service.dockerfile diff --git a/.gitignore b/.gitignore index 7c344c4..193499e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ cred.txt dist/ .air.toml tmp/ -broker-service/brokerApp -front-end/frontApp +*/*App diff --git a/authentication-service/authentication-service.dockerfile b/authentication-service/authentication-service.dockerfile new file mode 100644 index 0000000..6e53b7f --- /dev/null +++ b/authentication-service/authentication-service.dockerfile @@ -0,0 +1,8 @@ +FROM alpine:latest + +RUN mkdir /app + +COPY authApp /app + +CMD ["/app/authApp"] + diff --git a/project/Makefile b/project/Makefile index 43618b8..2c76856 100644 --- a/project/Makefile +++ b/project/Makefile @@ -1,24 +1,25 @@ FRONT_END_BINARY=frontApp BROKER_BINARY=brokerApp +AUTH_BINARY=authApp ## up: starts all containers in the background without forcing build up: @echo "Starting Docker images..." - sudo docker compose up -d + docker compose up -d @echo "Docker images started!" ## up_build: stops docker-compose (if running), builds all projects and starts docker compose -up_build: build_broker +up_build: build_broker build_auth @echo "Stopping docker images (if running...)" - sudo docker compose down + docker compose down @echo "Building (when required) and starting docker images..." - sudo docker compose up --build -d + docker compose up --build -d @echo "Docker images built and started!" ## down: stop docker compose down: @echo "Stopping docker compose..." - sudo docker compose down + docker compose down @echo "Done!" ## build_broker: builds the broker binary as a linux executable @@ -27,6 +28,12 @@ build_broker: cd ../broker-service && env GOOS=linux CGO_ENABLED=0 go build -o ${BROKER_BINARY} ./cmd/api @echo "Done!" +## build_auth: builds the auth binary as a linux executable +build_auth: + @echo "Building auth binary..." + cd ../authentication-service && env GOOS=linux CGO_ENABLED=0 go build -o ${AUTH_BINARY} ./cmd/api + @echo "Done!" + ## build_front: builds the frone end binary build_front: @echo "Building front end binary..." diff --git a/project/docker-compose.yml b/project/docker-compose.yml index 6e4f159..5229a01 100644 --- a/project/docker-compose.yml +++ b/project/docker-compose.yml @@ -9,3 +9,36 @@ services: deploy: mode: replicated replicas: 1 + + authentication-service: + build: + context: ./../authentication-service/ + dockerfile: ./../authentication-service/authentication-service.dockerfile + ports: + - "8081:4000" + deploy: + mode: replicated + replicas: 1 + environment: + DSN: "host=postgres port=5432 user=postgres password=password dbname=users timezone=UTC connect_timeout=5" + + postgres: + image: postgres + ports: + - "5432:5432" + restart: always + deploy: + mode: replicated + replicas: 1 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: users + volumes: + - ./db-data/postgres:/var/lib/postgresql/data + + adminer: + image: adminer + restart: always + ports: + - 8090:8080