Skip to content

Commit d0421b5

Browse files
authored
šŸ› fix(ci): resolve GoReleaser docker build failure and migrate deprecated configs (#2)
1 parent 5a9292a commit d0421b5

4 files changed

Lines changed: 77 additions & 43 deletions

File tree

ā€Ž.github/workflows/release.ymlā€Ž

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ on:
44
push:
55
tags:
66
- 'v*.*.*'
7+
pull_request:
8+
paths:
9+
- '.goreleaser.yml'
10+
- 'Dockerfile*'
11+
- '.github/workflows/release.yml'
12+
- 'go.mod'
13+
- 'go.sum'
14+
- 'cmd/**'
15+
- 'internal/**'
16+
workflow_dispatch:
17+
inputs:
18+
dry_run:
19+
description: 'Run in dry-run mode (no publish)'
20+
required: false
21+
default: true
22+
type: boolean
723

824
permissions:
925
contents: write
@@ -32,17 +48,29 @@ jobs:
3248
uses: docker/setup-buildx-action@v3
3349

3450
- name: Login to GitHub Container Registry
51+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
3552
uses: docker/login-action@v3
3653
with:
3754
registry: ghcr.io
3855
username: ${{ github.actor }}
3956
password: ${{ secrets.GITHUB_TOKEN }}
4057

41-
- name: Run GoReleaser
58+
- name: Run GoReleaser (Release)
59+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
4260
uses: goreleaser/goreleaser-action@v6
4361
with:
4462
distribution: goreleaser
4563
version: '~> v2'
4664
args: release --clean
4765
env:
4866
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Run GoReleaser (Dry Run)
69+
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.dry_run)
70+
uses: goreleaser/goreleaser-action@v6
71+
with:
72+
distribution: goreleaser
73+
version: '~> v2'
74+
args: release --snapshot --skip=publish --clean
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ā€Ž.goreleaser.ymlā€Ž

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ builds:
3030
archives:
3131
- id: default
3232
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
33-
format: tar.gz
33+
formats:
34+
- tar.gz
3435
format_overrides:
3536
- goos: windows
36-
format: zip
37+
formats:
38+
- zip
3739
files:
3840
- LICENSE
3941
- README.md
@@ -42,7 +44,7 @@ checksum:
4244
name_template: 'checksums.txt'
4345

4446
snapshot:
45-
name_template: '{{ incpatch .Version }}-next'
47+
version_template: '{{ incpatch .Version }}-next'
4648

4749
changelog:
4850
sort: desc
@@ -86,42 +88,19 @@ release:
8688
go install github.com/l2D/azswitch/cmd/azswitch@{{ .Tag }}
8789
```
8890
89-
dockers:
90-
- image_templates:
91-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64'
92-
dockerfile: Dockerfile
93-
use: buildx
94-
build_flag_templates:
95-
- '--pull'
96-
- '--platform=linux/amd64'
97-
- '--label=org.opencontainers.image.created={{.Date}}'
98-
- '--label=org.opencontainers.image.title={{.ProjectName}}'
99-
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
100-
- '--label=org.opencontainers.image.version={{.Version}}'
101-
- '--label=org.opencontainers.image.source={{.GitURL}}'
102-
goarch: amd64
103-
104-
- image_templates:
105-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64'
106-
dockerfile: Dockerfile
107-
use: buildx
108-
build_flag_templates:
109-
- '--pull'
110-
- '--platform=linux/arm64'
111-
- '--label=org.opencontainers.image.created={{.Date}}'
112-
- '--label=org.opencontainers.image.title={{.ProjectName}}'
113-
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
114-
- '--label=org.opencontainers.image.version={{.Version}}'
115-
- '--label=org.opencontainers.image.source={{.GitURL}}'
116-
goarch: arm64
117-
118-
docker_manifests:
119-
- name_template: 'ghcr.io/l2d/azswitch:{{ .Tag }}'
120-
image_templates:
121-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64'
122-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64'
123-
124-
- name_template: 'ghcr.io/l2d/azswitch:latest'
125-
image_templates:
126-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-amd64'
127-
- 'ghcr.io/l2d/azswitch:{{ .Tag }}-arm64'
91+
dockers_v2:
92+
- images:
93+
- 'ghcr.io/l2d/azswitch'
94+
dockerfile: Dockerfile.goreleaser
95+
tags:
96+
- '{{ .Tag }}'
97+
- '{{ if not .IsNightly }}latest{{ end }}'
98+
platforms:
99+
- linux/amd64
100+
- linux/arm64
101+
labels:
102+
'org.opencontainers.image.created': '{{.Date}}'
103+
'org.opencontainers.image.title': '{{.ProjectName}}'
104+
'org.opencontainers.image.revision': '{{.FullCommit}}'
105+
'org.opencontainers.image.version': '{{.Version}}'
106+
'org.opencontainers.image.source': '{{.GitURL}}'

ā€Ž.mise.tomlā€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ azure-cli = "2.82.0"
55
gitleaks = "8.24.3"
66
go = "1.25.6"
77
golangci-lint = "2.8.0"
8+
goreleaser = "2.13.3"
89
pre-commit = "4.5.1"
910
trivy = "0.68.2"
1011
yamlfmt = "0.21.0"

ā€ŽDockerfile.goreleaserā€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dockerfile for GoReleaser - uses pre-built binary
2+
FROM mcr.microsoft.com/azure-cli:2.82.0
3+
4+
LABEL org.opencontainers.image.title="azswitch"
5+
LABEL org.opencontainers.image.description="TUI for switching Azure tenants and subscriptions"
6+
LABEL org.opencontainers.image.source="https://github.com/l2D/azswitch"
7+
LABEL org.opencontainers.image.licenses="MIT"
8+
9+
# Create non-root user
10+
RUN tdnf install -y shadow-utils && \
11+
groupadd -g 1000 azswitch && \
12+
useradd -u 1000 -g azswitch -d /home/azswitch -s /bin/sh -m azswitch && \
13+
tdnf clean all
14+
15+
# Copy pre-built binary from GoReleaser (dockers_v2 places binaries in $TARGETPLATFORM/)
16+
ARG TARGETPLATFORM
17+
COPY ${TARGETPLATFORM}/azswitch /usr/local/bin/azswitch
18+
19+
# Set up Azure CLI cache directory with proper ownership
20+
RUN mkdir -p /home/azswitch/.azure && \
21+
chown -R azswitch:azswitch /home/azswitch/.azure
22+
23+
USER azswitch
24+
WORKDIR /home/azswitch
25+
26+
ENTRYPOINT ["/usr/local/bin/azswitch"]

0 commit comments

Comments
Ā (0)