From 1e73c9c7d1cd3a817d4728c7d0bb2092eba982af Mon Sep 17 00:00:00 2001 From: whysman Date: Thu, 7 Nov 2024 01:13:39 -0500 Subject: [PATCH] Updated Dockerfile & build.yaml --- .gitea/workflows/build.yaml | 17 ----------------- Dockerfile | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 34dffda..b7743da 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -17,23 +17,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.22' # Specify the desired Go version - - - name: Download Dependencies - run: | - go mod download - - - name: Build Go Binary - run: | - go build -o pogdark-api . - - - name: Confirm file presence - run: | - pwd && ls -al /workspace/public/ && ls -al . - - name: Build Docker Image run: | docker build -t localhost:5000/pogdark-api:latest . diff --git a/Dockerfile b/Dockerfile index 84a743a..31ec89c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,31 @@ -FROM scratch -COPY pogdark-api /app/pogdark-api +FROM golang:1.22-alpine AS builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy go.mod and go.sum files to the workspace +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy the source code into the container +COPY . . + +# Build the Go application +RUN go build -o pogdark-api . + +# Stage 2: Create a small image to run the Go application +FROM alpine:latest + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy the pre-built binary from the builder stage +COPY --from=builder /app/pogdark-api . + +# Expose port (change if your app uses a different port) EXPOSE 8080 -CMD ["/app/pogdark-api"] \ No newline at end of file + +# Command to run the executable +CMD ["/app/pogdark-api"]