feat: Add architecture support and improve Dockerfile for multi-platform builds

- Introduced architecture-related build arguments (TARGETOS, TARGETARCH, TARGETVARIANT) to the Dockerfile.
- Updated the build command to use dynamic OS and architecture values.
- Enhanced rclone installation to support multiple architectures (amd64, arm64, arm-v7).
- Updated GitHub workflows to specify supported platforms for Docker builds.
This commit is contained in:
StarFleetCPTN
2025-04-11 20:32:48 -07:00
parent e9a005b658
commit 0aa68bc8e7
3 changed files with 20 additions and 5 deletions
@@ -96,6 +96,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }} push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: | build-args: |
VERSION=${{ env.VERSION }} VERSION=${{ env.VERSION }}
BUILD_TIME=${{ env.BUILD_TIME }} BUILD_TIME=${{ env.BUILD_TIME }}
+1
View File
@@ -97,6 +97,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }} push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: | build-args: |
VERSION=${{ env.VERSION }} VERSION=${{ env.VERSION }}
BUILD_TIME=${{ env.BUILD_TIME }} BUILD_TIME=${{ env.BUILD_TIME }}
+18 -5
View File
@@ -35,6 +35,10 @@ WORKDIR /app
ARG VERSION=dev ARG VERSION=dev
ARG BUILD_TIME=unknown ARG BUILD_TIME=unknown
ARG COMMIT=unknown ARG COMMIT=unknown
# Architecture-related build arguments
ARG TARGETOS=linux
ARG TARGETARCH=amd64
ARG TARGETVARIANT=""
# Install build dependencies # Install build dependencies
RUN apk add --no-cache git build-base RUN apk add --no-cache git build-base
@@ -66,15 +70,22 @@ COPY . .
RUN templ generate RUN templ generate
# Compile the application with version information # Compile the application with version information
RUN CGO_ENABLED=0 GOOS=linux go build \ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags "-X github.com/starfleetcptn/gomft/components.AppVersion=${VERSION} -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.Commit=${COMMIT} -X github.com/starfleetcptn/gomft/components.BuildTime=${BUILD_TIME} -X github.com/starfleetcptn/gomft/components.Commit=${COMMIT}" \ -ldflags "-X github.com/starfleetcptn/gomft/components.AppVersion=${VERSION} -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.Commit=${COMMIT} -X github.com/starfleetcptn/gomft/components.BuildTime=${BUILD_TIME} -X github.com/starfleetcptn/gomft/components.Commit=${COMMIT}" \
-o /app/gomft -o /app/gomft
# Install rclone # Install rclone with appropriate architecture
RUN apk add --no-cache curl unzip && \ RUN apk add --no-cache curl unzip && \
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip && \ if [ "$TARGETARCH" = "arm64" ]; then \
unzip rclone-current-linux-amd64.zip && \ RCLONE_ARCH="arm64"; \
cd rclone-*-linux-amd64 && \ elif [ "$TARGETARCH" = "arm" ]; then \
RCLONE_ARCH="arm-v7"; \
else \
RCLONE_ARCH="amd64"; \
fi && \
curl -O https://downloads.rclone.org/rclone-current-linux-${RCLONE_ARCH}.zip && \
unzip rclone-current-linux-${RCLONE_ARCH}.zip && \
cd rclone-*-linux-${RCLONE_ARCH} && \
cp rclone /usr/local/bin/ && \ cp rclone /usr/local/bin/ && \
chmod 755 /usr/local/bin/rclone && \ chmod 755 /usr/local/bin/rclone && \
cd .. && \ cd .. && \
@@ -87,6 +98,8 @@ FROM alpine:3.19
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
ARG USERNAME=gomft ARG USERNAME=gomft
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app WORKDIR /app