From ebf394b0c08f7b2bf53c53c46cd5642e1e3cbb8e Mon Sep 17 00:00:00 2001 From: nikhilnarayanan623 Date: Mon, 7 Aug 2023 14:52:17 +0530 Subject: [PATCH] docker file and compse file updated --- .air.toml | 2 +- Dockerfile | 29 ++++++++++++++++-------- docker-compose.yml | 56 +++++++++++++++------------------------------- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/.air.toml b/.air.toml index ceebe2c..5aa87c3 100644 --- a/.air.toml +++ b/.air.toml @@ -5,7 +5,7 @@ tmp_dir = "tmp" [build] args_bin = [] bin = "./build/bin/api-linux-amd64" - cmd = "go build -o ./build/bin/api-linux-amd64 ./cmd/api/" + cmd = "go build -o ./build/bin/api-linux-amd64 ./cmd/api/main.go" delay = 1000 exclude_dir = ["assets", "tmp", "vendor", "testdata"] exclude_file = [] diff --git a/Dockerfile b/Dockerfile index 8f519b5..58570cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,23 @@ -FROM golang:1.20.4-alpine3.18 AS build-stage -WORKDIR /home/app -COPY ./ /home/app -RUN mkdir -p /home/build -RUN go mod download -RUN go build -v -o /home/build/api ./cmd/api +# build stage +FROM golang:1.20.6-alpine3.18 AS build-stage +WORKDIR /app +# download the dependancy +COPY go.mod go.sum ./ +RUN go mod download +# copy the source code and html files +COPY cmd cmd/ +COPY pkg pkg/ +COPY views views/ +# build the executable file +RUN go build -v -o ./build/api ./cmd/api +# final stage FROM gcr.io/distroless/static-debian11 -COPY --from=build-stage /home/build/api /api -COPY --from=build-stage /home/app/views /views -CMD ["/api"] + +WORKDIR /app +# copy the binay file and html files +COPY --from=build-stage /app/build/api api +COPY --from=build-stage /app/views views/ + +CMD ["/app/api"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e17c1cb..ba9fb55 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,56 +1,36 @@ version: '3' services: -#database container +# database container postgresdb: image: postgres - # ports: - # - 5454:5432 - environment: - - POSTGRES_USER=${DB_USER} - - POSTGRES_PASSWORD=password - - POSTGRES_DB=${DB_NAME} + env_file: + - .env volumes: - database:/var/lib/postgresql/data + networks: + - ecommerce-network # webapp container app: + build: + context: . + dockerfile: Dockerfile image: nikhil382/ecommerce-gin-clean-arch ports: - 8000:8000 + env_file: + - .env environment: - - ADMIN_EMAIL=${ADMIN_EMAIL} - - ADMIN_USER_NAME=${ADMIN_USER_NAME} - - ADMIN_PASSWORD=${ADMIN_PASSWORD} - DB_HOST=postgresdb - - DB_USER=${DB_USER} - - DB_PASSWORD=password - - DB_NAME=${DB_NAME} - - DB_PORT=5432 - - ADMIN_AUTH_KEY=${ADMIN_AUTH_KEY} - - USER_AUTH_KEY=${USER_AUTH_KEY} - - AUTH_TOKEN=${AUTH_TOKEN} - - ACCOUNT_SID=${ACCOUNT_SID} - - SERVICE_SID=${SERVICE_SID} - - RAZOR_PAY_KEY=${RAZOR_PAY_KEY} - - RAZOR_PAY_SECRET=${RAZOR_PAY_SECRET} - - STRIPE_SECRET=${STRIPE_SECRET} - - STRIPE_PUBLISH_KEY=${STRIPE_PUBLISH_KEY} - - STRIPE_WEBHOOK=${STRIPE_WEBHOOK} - - GOAUTH_CLIENT_ID=${GOAUTH_CLIENT_ID} - - GOAUTH_CLIENT_SECRET=${GOAUTH_CLIENT_SECRET} - - GOAUTH_CALL_BACK_URL=${GOAUTH_CALL_BACK_URL} depends_on: - postgresdb + restart: always + networks: + - ecommerce-network -# # pg admin for showing the database on GUI -# pg-admin: -# image: dpage/pgadmin4 -# ports: -# - 8080:80 -# environment: -# - PGADMIN_DEFAULT_EMAIL=nikhil@gmail.com -# - PGADMIN_DEFAULT_PASSWORD=password - -# storing datas on docker side +# for persistent data storage volumes: database: - driver: local + +networks: + ecommerce-network: + driver: bridge