diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9723484..febf267 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index fcc5a0d..0000000 --- a/Dockerfile +++ /dev/null @@ -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"] diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..d6a2122 --- /dev/null +++ b/build/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3fca69a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.8" + +services: + web-humas-be: + build: + context: . + dockerfile: build/Dockerfile + volumes: + - .:/app + ports: + - "8800:8800" \ No newline at end of file