-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from codeclubvn/docker
change locate docker file
- Loading branch information
Showing
4 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
FROM golang:1.19-alpine as build-env | ||
# Stage 1: Install dependencies | ||
FROM golang:1.21 as installer | ||
|
||
# cache dependencies first | ||
WORKDIR /app | ||
|
||
COPY go.mod /app | ||
COPY go.sum /app | ||
RUN go mod download | ||
|
||
# Stage 2: Build the application | ||
FROM installer as builder | ||
|
||
COPY . /app | ||
|
||
# build | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /app/main ./main.go | ||
|
||
FROM alpine:latest | ||
# Stage 3: Create a lightweight runtime image | ||
FROM ubuntu:20.04 as runner | ||
|
||
WORKDIR /app | ||
COPY ./config/config.yml /app/config/config.yml | ||
COPY --from=builder /app/main /app/main | ||
COPY --from=builder /app/config/config.yml /app/config/config.yml | ||
|
||
COPY --from=build-env /app/main /app/main | ||
|
||
ENTRYPOINT ["/app/main"] | ||
RUN apt-get update \ | ||
&& DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata ca-certificates --no-install-recommends \ | ||
&& ln -fs /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime \ | ||
&& rm -fr /var/lib/apt/lists/* | ||
|
||
EXPOSE $PORT | ||
|
||
ENTRYPOINT ["/app/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.19-alpine as build-env | ||
|
||
# cache dependencies first | ||
WORKDIR /app | ||
COPY ../go.mod /app | ||
COPY ../go.sum /app | ||
RUN go mod download | ||
|
||
COPY .. /app | ||
|
||
# build | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /app/main ./main.go | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /app | ||
COPY ./config/config.yml /app/config/config.yml | ||
|
||
COPY --from=build-env /app/main /app/main | ||
|
||
ENTRYPOINT ["/app/main"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3.9' | ||
services: | ||
database: | ||
image: postgres:16 | ||
container_name: erp_database | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: erp_server | ||
ports: | ||
- 5432:5432 | ||
|
||
server: | ||
image: erp_server:latest | ||
container_name: erp_server | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- 8008:8008 | ||
depends_on: | ||
- database | ||
restart: always |