-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update Docker image build process
- Loading branch information
Showing
4 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
# Builder stage | ||
FROM golang:1.23-alpine AS builder | ||
|
||
ENV APP_NAME=app | ||
ARG APP_NAME | ||
ARG VERSION | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the source code into the container | ||
COPY --link . . | ||
# Copy go.mod and go.sum first for better caching | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Now copy the rest of the source code | ||
COPY . . | ||
|
||
# Build the Go app with version argument | ||
ARG VERSION | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o ./bin/${APP_NAME} | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o ./bin/${APP_NAME} ./cmd/${APP_NAME}/main.go | ||
|
||
# Final stage | ||
FROM debian:buster-slim | ||
#FROM debian:buster-slim | ||
FROM alpine:latest | ||
|
||
ARG APP_NAME | ||
ENV APP_NAME=${APP_NAME} | ||
|
||
# Install CA certificates | ||
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg curl | ||
#RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg curl | ||
RUN apk update && apk add --no-cache ca-certificates curl | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the Pre-built binary file from the previous stage | ||
COPY --from=builder /app/bin . | ||
|
||
# Copy the entrypoint script | ||
COPY scripts/docker-entrypoint.sh /app/docker-entrypoint.sh | ||
RUN chmod +x /app/docker-entrypoint.sh | ||
|
||
# Command to run the executable | ||
ENTRYPOINT ["./${APP_NAME}"] | ||
ENTRYPOINT ["./docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Execute the application with the APP_NAME environment variable | ||
exec /app/"$APP_NAME" "$@" |