feat: update gitlab-ci and dockerfile

This commit is contained in:
hanif salafi 2024-03-06 22:19:09 +07:00
parent 0abbd98af2
commit 70c428a225
4 changed files with 28 additions and 25 deletions

View File

@ -18,7 +18,8 @@ build-image:
- docker:dind - docker:dind
script: script:
- docker login -u $DEPLOY_USERNAME -p $DEPLOY_TOKEN registry.gitlab.com - docker login -u $DEPLOY_USERNAME -p $DEPLOY_TOKEN registry.gitlab.com
- docker build -t registry.gitlab.com/hanifsalafi/web-humas-be:dev . # - docker build -t registry.gitlab.com/hanifsalafi/web-humas-be:dev .
- docker-compose build
- docker push registry.gitlab.com/hanifsalafi/web-humas-be:dev - docker push registry.gitlab.com/hanifsalafi/web-humas-be:dev
deploy: deploy:

View File

@ -1,24 +0,0 @@
# Menggunakan Go image resmi dari Docker Hub sebagai base image
FROM golang:alpine AS builder
# Menentukan direktori kerja
WORKDIR /app
# Menyalin file Go mod dan Go sum untuk mendownload dependensi
COPY go.mod ./
COPY go.sum ./
# Mendownload dependensi menggunakan Go module
RUN go mod download
# Menyalin seluruh file ke dalam image
COPY . .
# Mengcompile aplikasi Go
RUN go build -o main .
# Memindahkan binary hasil compile ke direktori yang lebih kecil
FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
CMD ["./main"]

15
build/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM golang:alpine as builder
WORKDIR /app
COPY go.* ./
RUN go mod download
COPY . .
RUN apk update && apk add upx ca-certificates openssl && update-ca-certificates
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o /bin/api-binary ./cmd/example/main.go
RUN upx -9 /bin/api-binary
FROM gcr.io/distroless/static:nonroot
WORKDIR /app/
COPY --from=builder /bin/api-binary /bin/api-binary
COPY --from=builder --chown=nonroot /app/config /app/config
ENTRYPOINT ["/bin/api-binary"]

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
version: "3.8"
services:
web-humas-be:
build:
context: .
dockerfile: build/Dockerfile
volumes:
- .:/app
ports:
- "8800:8800"