From c1e8ba3b2244792acac0bb76575e811ddfe91b38 Mon Sep 17 00:00:00 2001 From: Zoe <62722391+juls0730@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:20:25 -0500 Subject: [PATCH] arm64 docker image builds --- .github/workflows/docker-publish.yml | 66 ++++++++++++++++++++++++++++ Dockerfile | 22 +++++++--- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index cae9e4e..4df4107 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -10,7 +10,18 @@ on: jobs: build-and-push: + strategy: + matrix: + include: + - arch: amd64 + docker-platform: linux/amd64 + tag-suffix: "" + - arch: arm64 + docker-platform: linux/arm64 + tag-suffix: "-arm64" + runs-on: ubuntu-latest + architecture: ${{ matrix.arch }} permissions: contents: read @@ -27,11 +38,22 @@ jobs: username: ${{ github.actor }} password: ${{ env.OCI_TOKEN }} + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ vars.OCI_REGISTRY || 'ghcr.io' }}/${{ github.repository }} + tags: | + type=schedule + type=ref,event=branch + type=semver,pattern={{version}}${{ matrix.tag_suffix }} + type=semver,pattern={{major}}.{{minor}}${{ matrix.tag_suffix }} + type=semver,pattern={{major}}${{ matrix.tag_suffix }} + type=raw,value=latest${{ matrix.tag_suffix }},enable={{is_default_branch}} - name: Build and push Docker image uses: docker/build-push-action@v6 @@ -40,3 +62,47 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ matrix.docker_platform }} + build-args: TARGETARCH=${{ matrix.arch }} + + combine-manifests: + needs: build-and-push + runs-on: ubuntu-latest + steps: + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ vars.OCI_REGISTRY || 'ghcr.io' }} + username: ${{ github.actor }} + password: ${{ env.OCI_TOKEN }} + + - name: Create combined manifest + run: | + # Get the base image name + IMAGE_NAME=${{ vars.OCI_REGISTRY || 'ghcr.io' }}/${{ github.repository }} + + # Determine tags based on ref_type (branch/tag) + if [[ "${{ github.ref_type }}" == "tag" ]]; then + TAG_VERSION="${{ github.ref_name }}" # e.g., v1.0.0 + TAG_LATEST="latest" + elif [[ "${{ github.ref_name }}" == "refs/heads/main" ]]; then + TAG_VERSION="" # No version tag for main head + TAG_LATEST="latest" + else + echo "Skipping manifest for non-tag/non-main branch" + exit 0 + fi + + if [ -n "$TAG_LATEST" ]; then + docker buildx imagetools create -t ${IMAGE_NAME}:${TAG_LATEST} \ + ${IMAGE_NAME}:${TAG_LATEST}-amd64 \ + ${IMAGE_NAME}:${TAG_LATEST}-arm64 + echo "Created multi-arch manifest for ${IMAGE_NAME}:${TAG_LATEST}" + fi + + if [ -n "$TAG_VERSION" ]; then + docker buildx imagetools create -t ${IMAGE_NAME}:${TAG_VERSION} \ + ${IMAGE_NAME}:${TAG_VERSION}-amd64 \ + ${IMAGE_NAME}:${TAG_VERSION}-arm64 + echo "Created multi-arch manifest for ${IMAGE_NAME}:${TAG_VERSION}" + fi diff --git a/Dockerfile b/Dockerfile index 9310096..d9b13dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,21 +3,33 @@ FROM golang:1.25 AS builder # build dependencies RUN apt update && apt install -y upx -RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v4.1.13/tailwindcss-linux-x64 -RUN chmod +x tailwindcss-linux-x64 -RUN mv tailwindcss-linux-x64 /usr/local/bin/tailwindcss +ARG TARGETARCH +RUN set -eux; \ + echo "Building for architecture: ${TARGETARCH}"; \ + case "${TARGETARCH}" in \ + "amd64") \ + arch_suffix='x64' ;; \ + "arm64") \ + arch_suffix='arm64' ;; \ + *) \ + echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \ + esac; \ + curl -sLO "https://github.com/tailwindlabs/tailwindcss/releases/download/v4.1.13/tailwindcss-linux-${arch_suffix}"; \ + mv "tailwindcss-linux-${arch_suffix}" /usr/local/bin/tailwindcss; \ + chmod +x /usr/local/bin/tailwindcss; + RUN go install github.com/juls0730/zqdgr@latest WORKDIR /app -ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 +ARG TARGETARCH +ENV CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} COPY go.mod go.sum ./ RUN go mod download COPY . . - RUN zqdgr build RUN upx passport