Use golang-alpine image for builds

This commit is contained in:
Dmytro Bondar 2024-03-04 09:54:47 +01:00
parent c970b81d84
commit f76b59286e
No known key found for this signature in database
GPG Key ID: C123CD37BBED8BB7

View File

@ -20,7 +20,7 @@ RUN npm run build
###### ######
# Build backend # Build backend
###### ######
FROM --platform=${BUILDPLATFORM} golang:1.21 as builder FROM --platform=${BUILDPLATFORM} golang:1.21-alpine as builder
# Set the working directory # Set the working directory
WORKDIR /build WORKDIR /build
# Download dependencies # Download dependencies
@ -30,17 +30,15 @@ RUN go mod download
COPY . . COPY . .
# Copy the frontend build result # Copy the frontend build result
COPY --from=frontend /build/dist/ ./internal/app/api/core/frontend-dist/ COPY --from=frontend /build/dist/ ./internal/app/api/core/frontend-dist/
# Set the build version and identifier from arguments # Set the build version from arguments
ARG BUILD_IDENTIFIER BUILD_VERSION ARG BUILD_VERSION
ENV ENV_BUILD_IDENTIFIER=${BUILD_IDENTIFIER}
ENV ENV_BUILD_VERSION=${BUILD_VERSION}
# Split to cross-platform build # Split to cross-platform build
ARG TARGETARCH ARG TARGETARCH
ENV GOARCH=${TARGETARCH} # Build the application
# Build the Go app RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} go build -o /build/dist/wg-portal \
RUN echo "Building version '$ENV_BUILD_IDENTIFIER-$ENV_BUILD_VERSION' for architecture $TARGETARCH" -ldflags "-w -s -extldflags '-static' -X 'github.com/h44z/wg-portal/internal.Version=${BUILD_VERSION}'" \
RUN make build -tags netgo \
cmd/wg-portal/main.go
###### ######
# Final image # Final image