From 1a65525cd4729751e95ef746cfc78780c8b03b47 Mon Sep 17 00:00:00 2001 From: l2D <20911264+l2D@users.noreply.github.com> Date: Thu, 29 Jan 2026 00:33:15 +0700 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20fix(ci):=20resolve=20GoRelea?= =?UTF-8?q?ser=20docker=20build=20context=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add Dockerfile.goreleaser that copies pre-built binary directly - update .goreleaser.yml to use dedicated Dockerfile for releases - original Dockerfile preserved for local development builds Fixes docker build failure caused by missing go.sum in build context --- .goreleaser.yml | 4 ++-- Dockerfile.goreleaser | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.goreleaser diff --git a/.goreleaser.yml b/.goreleaser.yml index 7390603..ea1f17c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -89,7 +89,7 @@ release: dockers: - image_templates: - 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64' - dockerfile: Dockerfile + dockerfile: Dockerfile.goreleaser use: buildx build_flag_templates: - '--pull' @@ -103,7 +103,7 @@ dockers: - image_templates: - 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64' - dockerfile: Dockerfile + dockerfile: Dockerfile.goreleaser use: buildx build_flag_templates: - '--pull' diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..548fd39 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,25 @@ +# Dockerfile for GoReleaser - uses pre-built binary +FROM mcr.microsoft.com/azure-cli:2.82.0 + +LABEL org.opencontainers.image.title="azswitch" +LABEL org.opencontainers.image.description="TUI for switching Azure tenants and subscriptions" +LABEL org.opencontainers.image.source="https://github.com/l2D/azswitch" +LABEL org.opencontainers.image.licenses="MIT" + +# Create non-root user +RUN tdnf install -y shadow-utils && \ + groupadd -g 1000 azswitch && \ + useradd -u 1000 -g azswitch -d /home/azswitch -s /bin/sh -m azswitch && \ + tdnf clean all + +# Copy pre-built binary from GoReleaser +COPY azswitch /usr/local/bin/azswitch + +# Set up Azure CLI cache directory with proper ownership +RUN mkdir -p /home/azswitch/.azure && \ + chown -R azswitch:azswitch /home/azswitch/.azure + +USER azswitch +WORKDIR /home/azswitch + +ENTRYPOINT ["/usr/local/bin/azswitch"] From 6abd59d6d428b578722bf535405b02dd04ccffe3 Mon Sep 17 00:00:00 2001 From: l2D <20911264+l2D@users.noreply.github.com> Date: Thu, 29 Jan 2026 00:37:15 +0700 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20feat(docker):=20add=20dedicated?= =?UTF-8?q?=20Dockerfile=20for=20GoReleaser=20builds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - create Dockerfile.goreleaser using TARGETPLATFORM for multi-arch support - use Azure CLI base image with non-root user setup - resolve docker build context missing go.sum error Signed-off-by: l2D <20911264+l2D@users.noreply.github.com> --- Dockerfile.goreleaser | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser index 548fd39..a259d81 100644 --- a/Dockerfile.goreleaser +++ b/Dockerfile.goreleaser @@ -12,8 +12,9 @@ RUN tdnf install -y shadow-utils && \ useradd -u 1000 -g azswitch -d /home/azswitch -s /bin/sh -m azswitch && \ tdnf clean all -# Copy pre-built binary from GoReleaser -COPY azswitch /usr/local/bin/azswitch +# Copy pre-built binary from GoReleaser (dockers_v2 places binaries in $TARGETPLATFORM/) +ARG TARGETPLATFORM +COPY ${TARGETPLATFORM}/azswitch /usr/local/bin/azswitch # Set up Azure CLI cache directory with proper ownership RUN mkdir -p /home/azswitch/.azure && \ From 8538b8d04a4fbe1038327298e6afb9f40b9fdf81 Mon Sep 17 00:00:00 2001 From: l2D <20911264+l2D@users.noreply.github.com> Date: Thu, 29 Jan 2026 00:37:17 +0700 Subject: [PATCH 3/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(goreleaser):?= =?UTF-8?q?=20migrate=20to=20non-deprecated=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rename snapshot.name_template to version_template - change archives.format to formats list - change archives.format_overrides.format to formats list - migrate dockers + docker_manifests to dockers_v2 Signed-off-by: l2D <20911264+l2D@users.noreply.github.com> --- .goreleaser.yml | 61 ++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index ea1f17c..c26fd35 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -30,10 +30,12 @@ builds: archives: - id: default name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' - format: tar.gz + formats: + - tar.gz format_overrides: - goos: windows - format: zip + formats: + - zip files: - LICENSE - README.md @@ -42,7 +44,7 @@ checksum: name_template: 'checksums.txt' snapshot: - name_template: '{{ incpatch .Version }}-next' + version_template: '{{ incpatch .Version }}-next' changelog: sort: desc @@ -86,42 +88,19 @@ release: go install github.com/l2D/azswitch/cmd/azswitch@{{ .Tag }} ``` -dockers: - - image_templates: - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64' +dockers_v2: + - images: + - 'ghcr.io/l2d/azswitch' dockerfile: Dockerfile.goreleaser - use: buildx - build_flag_templates: - - '--pull' - - '--platform=linux/amd64' - - '--label=org.opencontainers.image.created={{.Date}}' - - '--label=org.opencontainers.image.title={{.ProjectName}}' - - '--label=org.opencontainers.image.revision={{.FullCommit}}' - - '--label=org.opencontainers.image.version={{.Version}}' - - '--label=org.opencontainers.image.source={{.GitURL}}' - goarch: amd64 - - - image_templates: - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64' - dockerfile: Dockerfile.goreleaser - use: buildx - build_flag_templates: - - '--pull' - - '--platform=linux/arm64' - - '--label=org.opencontainers.image.created={{.Date}}' - - '--label=org.opencontainers.image.title={{.ProjectName}}' - - '--label=org.opencontainers.image.revision={{.FullCommit}}' - - '--label=org.opencontainers.image.version={{.Version}}' - - '--label=org.opencontainers.image.source={{.GitURL}}' - goarch: arm64 - -docker_manifests: - - name_template: 'ghcr.io/l2d/azswitch:{{ .Tag }}' - image_templates: - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64' - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64' - - - name_template: 'ghcr.io/l2d/azswitch:latest' - image_templates: - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64' - - 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64' + tags: + - '{{ .Tag }}' + - '{{ if not .IsNightly }}latest{{ end }}' + platforms: + - linux/amd64 + - linux/arm64 + labels: + 'org.opencontainers.image.created': '{{.Date}}' + 'org.opencontainers.image.title': '{{.ProjectName}}' + 'org.opencontainers.image.revision': '{{.FullCommit}}' + 'org.opencontainers.image.version': '{{.Version}}' + 'org.opencontainers.image.source': '{{.GitURL}}' From 973df8cfe1a768d4676cdcfdc9ad76206bb7ff99 Mon Sep 17 00:00:00 2001 From: l2D <20911264+l2D@users.noreply.github.com> Date: Thu, 29 Jan 2026 00:37:30 +0700 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A7=20chore:=20adds=20goreleaser?= =?UTF-8?q?=20to=20mise=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adds goreleaser to the mise config to ensure consistent tool versions across environments --- .mise.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.mise.toml b/.mise.toml index 939f37e..65847b1 100644 --- a/.mise.toml +++ b/.mise.toml @@ -5,6 +5,7 @@ azure-cli = "2.82.0" gitleaks = "8.24.3" go = "1.25.6" golangci-lint = "2.8.0" +goreleaser = "2.13.3" pre-commit = "4.5.1" trivy = "0.68.2" yamlfmt = "0.21.0" From 32a1126cf297f578a03e53326fe85236208153ca Mon Sep 17 00:00:00 2001 From: l2D <20911264+l2D@users.noreply.github.com> Date: Thu, 29 Jan 2026 00:38:58 +0700 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=91=B7=20ci(release):=20add=20dry-run?= =?UTF-8?q?=20mode=20for=20PRs=20and=20manual=20triggers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - trigger on PRs touching release-related files - add workflow_dispatch with dry_run input - use --snapshot --skip=publish for non-tag builds Signed-off-by: l2D <20911264+l2D@users.noreply.github.com> --- .github/workflows/release.yml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ada1b5d..928e48c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,22 @@ on: push: tags: - 'v*.*.*' + pull_request: + paths: + - '.goreleaser.yml' + - 'Dockerfile*' + - '.github/workflows/release.yml' + - 'go.mod' + - 'go.sum' + - 'cmd/**' + - 'internal/**' + workflow_dispatch: + inputs: + dry_run: + description: 'Run in dry-run mode (no publish)' + required: false + default: true + type: boolean permissions: contents: write @@ -32,13 +48,15 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Run GoReleaser + - name: Run GoReleaser (Release) + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser @@ -46,3 +64,13 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser (Dry Run) + if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.dry_run) + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --snapshot --skip=publish --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}