feat: update gitlab-ci and dockerfile
This commit is contained in:
parent
0abbd98af2
commit
70c428a225
|
|
@ -18,7 +18,8 @@ build-image:
|
|||
- docker:dind
|
||||
script:
|
||||
- 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
|
||||
|
||||
deploy:
|
||||
|
|
|
|||
24
Dockerfile
24
Dockerfile
|
|
@ -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"]
|
||||
|
|
@ -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"]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
version: "3.8"
|
||||
|
||||
services:
|
||||
web-humas-be:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: build/Dockerfile
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- "8800:8800"
|
||||
Loading…
Reference in New Issue