Skip to content

Commit

Permalink
Merge pull request #51 from nikhilnarayanan623/fix/docker
Browse files Browse the repository at this point in the history
docker file and compse file updated
  • Loading branch information
nikhilnarayanan623 authored Aug 7, 2023
2 parents 05bed17 + ebf394b commit 4e49d25
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
29 changes: 20 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
56 changes: 18 additions & 38 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e49d25

Please sign in to comment.