From 0aa68bc8e732f4a51880bff121240df0aa9d327d Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Fri, 11 Apr 2025 20:32:48 -0700 Subject: [PATCH] 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. --- .../workflows/docker-publish-dockerhub.yml | 1 + .github/workflows/docker-publish.yml | 1 + Dockerfile | 23 +++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish-dockerhub.yml b/.github/workflows/docker-publish-dockerhub.yml index 01f95ac..28ef4ce 100644 --- a/.github/workflows/docker-publish-dockerhub.yml +++ b/.github/workflows/docker-publish-dockerhub.yml @@ -96,6 +96,7 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 build-args: | VERSION=${{ env.VERSION }} BUILD_TIME=${{ env.BUILD_TIME }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 479fd70..42d1589 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -97,6 +97,7 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 build-args: | VERSION=${{ env.VERSION }} BUILD_TIME=${{ env.BUILD_TIME }} diff --git a/Dockerfile b/Dockerfile index 0785d97..d0a0242 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,10 @@ WORKDIR /app ARG VERSION=dev ARG BUILD_TIME=unknown ARG COMMIT=unknown +# Architecture-related build arguments +ARG TARGETOS=linux +ARG TARGETARCH=amd64 +ARG TARGETVARIANT="" # Install build dependencies RUN apk add --no-cache git build-base @@ -66,15 +70,22 @@ COPY . . RUN templ generate # 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}" \ -o /app/gomft -# Install rclone +# Install rclone with appropriate architecture RUN apk add --no-cache curl unzip && \ - curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip && \ - unzip rclone-current-linux-amd64.zip && \ - cd rclone-*-linux-amd64 && \ + if [ "$TARGETARCH" = "arm64" ]; then \ + RCLONE_ARCH="arm64"; \ + 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/ && \ chmod 755 /usr/local/bin/rclone && \ cd .. && \ @@ -87,6 +98,8 @@ FROM alpine:3.19 ARG UID=1000 ARG GID=1000 ARG USERNAME=gomft +ARG TARGETOS +ARG TARGETARCH WORKDIR /app