Skip to content

Commit

Permalink
Merge pull request #17 from codeclubvn/docker
Browse files Browse the repository at this point in the history
change locate docker file
  • Loading branch information
hieuhoccode099 authored Nov 26, 2023
2 parents c8e189e + 7848e8f commit a4328b6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
24 changes: 16 additions & 8 deletions Dockerfile
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"]
8 changes: 4 additions & 4 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ services:

database:
driver: 'postgres'
host: 'localhost'
host: 'host.docker.internal'
port: 5432
username: 'erp-dev'
password: 'erp-dev'
name: 'erp-dev'
username: 'postgres'
password: 'password'
name: 'erp_server'
sslmode: 'disable'
timezone: 'Asia/Ho_Chi_Minh'
maxOpenConnections: 10
Expand Down
23 changes: 23 additions & 0 deletions deploy/Dockerfile
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"]


23 changes: 23 additions & 0 deletions docker-compose.yaml
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

0 comments on commit a4328b6

Please sign in to comment.