Skip to content

Commit 02b40fa

Browse files
Update docker-build.yml
1 parent 67d48d1 commit 02b40fa

1 file changed

Lines changed: 57 additions & 124 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 57 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ on:
1919
required: false
2020
type: boolean
2121
default: false
22-
build_strategy:
23-
description: 'Build strategy'
24-
required: false
25-
type: choice
26-
default: 'buildx-multi'
27-
options:
28-
- 'buildx-multi'
29-
- 'buildx-single'
30-
- 'legacy'
3122

3223
env:
3324
REGISTRY: ghcr.io
@@ -77,21 +68,13 @@ jobs:
7768
id: repo
7869
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
7970

80-
- name: Set up QEMU (for multi-platform builds)
81-
if: github.event.inputs.build_strategy != 'legacy'
71+
- name: Set up QEMU (for ARM builds)
8272
uses: docker/setup-qemu-action@v3
8373
with:
84-
platforms: linux/amd64,linux/arm64
74+
platforms: linux/arm64
8575

8676
- name: Set up Docker Buildx
87-
if: github.event.inputs.build_strategy != 'legacy'
8877
uses: docker/setup-buildx-action@v3
89-
with:
90-
driver-opts: |
91-
network=host
92-
buildkitd-flags: |
93-
--allow-insecure-entitlement security.insecure
94-
--allow-insecure-entitlement network.host
9578

9679
- name: Log in to Container Registry
9780
uses: docker/login-action@v3
@@ -100,105 +83,70 @@ jobs:
10083
username: ${{ github.actor }}
10184
password: ${{ secrets.GITHUB_TOKEN }}
10285

103-
- name: Extract metadata
104-
id: meta
105-
uses: docker/metadata-action@v5
106-
with:
107-
images: ${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}
108-
tags: |
109-
type=ref,event=branch
110-
type=ref,event=pr
111-
type=semver,pattern={{version}}
112-
type=semver,pattern={{major}}.{{minor}}
113-
type=semver,pattern={{major}}
114-
type=raw,value=latest,enable={{is_default_branch}}
115-
labels: |
116-
org.opencontainers.image.title=Changerawr
117-
org.opencontainers.image.description=Ship, Change, Rawr 🦖 - Changelog management made cute and simple
118-
org.opencontainers.image.vendor=Supernova3339
119-
org.opencontainers.image.url=https://github.com/${{ github.repository }}
120-
org.opencontainers.image.source=https://github.com/${{ github.repository }}
121-
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}#readme
122-
123-
- name: Determine final tags and build args
124-
id: build_config
86+
- name: Determine version and tags
87+
id: version
12588
run: |
89+
# Set defaults
90+
VERSION="unknown"
91+
REVISION="${{ github.sha }}"
92+
BUILDTIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
93+
94+
# Determine version from different sources
12695
if [ -n "${{ github.event.inputs.tag_override }}" ]; then
127-
echo "tags=${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${{ github.event.inputs.tag_override }}" >> $GITHUB_OUTPUT
96+
VERSION="${{ github.event.inputs.tag_override }}"
97+
TAGS="${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${{ github.event.inputs.tag_override }}"
98+
elif [ "${{ github.event_name }}" = "release" ] && [ -n "${{ github.event.release.tag_name }}" ]; then
99+
VERSION="${{ github.event.release.tag_name }}"
100+
# Remove 'v' prefix if present
101+
CLEAN_VERSION="${VERSION#v}"
102+
TAGS="${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${CLEAN_VERSION},${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:latest"
103+
elif [ "${{ github.ref_type }}" = "tag" ]; then
104+
VERSION="${{ github.ref_name }}"
105+
# Remove 'v' prefix if present
106+
CLEAN_VERSION="${VERSION#v}"
107+
TAGS="${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${CLEAN_VERSION},${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:latest"
108+
elif [ "${{ github.ref_name }}" = "main" ] || [ "${{ github.ref_name }}" = "master" ]; then
109+
VERSION="latest"
110+
TAGS="${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:latest"
128111
else
129-
echo "tags=${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT
112+
VERSION="${{ github.ref_name }}"
113+
TAGS="${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${{ github.ref_name }}"
130114
fi
131115
132-
# Set build args
133-
echo "buildtime=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}" >> $GITHUB_OUTPUT
134-
echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_OUTPUT
135-
echo "revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}" >> $GITHUB_OUTPUT
116+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
117+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
118+
echo "buildtime=${BUILDTIME}" >> $GITHUB_OUTPUT
119+
echo "revision=${REVISION}" >> $GITHUB_OUTPUT
120+
121+
echo "✅ Version: ${VERSION}"
122+
echo "✅ Tags: ${TAGS}"
123+
echo "✅ Build time: ${BUILDTIME}"
124+
echo "✅ Revision: ${REVISION}"
136125
137-
# Strategy 1: Multi-platform buildx (default)
138-
- name: Build and push Docker image (Multi-platform)
139-
if: github.event.inputs.build_strategy == 'buildx-multi' || github.event.inputs.build_strategy == ''
126+
- name: Build and push Docker image
140127
uses: docker/build-push-action@v5
141128
with:
142129
context: .
143130
file: ./Dockerfile
144131
platforms: linux/amd64,linux/arm64
145132
push: true
146-
tags: ${{ steps.build_config.outputs.tags }}
147-
labels: ${{ steps.meta.outputs.labels }}
148-
cache-from: type=gha
149-
cache-to: type=gha,mode=max
150-
build-args: |
151-
BUILDTIME=${{ steps.build_config.outputs.buildtime }}
152-
VERSION=${{ steps.build_config.outputs.version }}
153-
REVISION=${{ steps.build_config.outputs.revision }}
154-
provenance: false
155-
sbom: false
156-
157-
# Strategy 2: Single platform buildx (fallback)
158-
- name: Build and push Docker image (Single platform)
159-
if: github.event.inputs.build_strategy == 'buildx-single'
160-
uses: docker/build-push-action@v5
161-
with:
162-
context: .
163-
file: ./Dockerfile
164-
platforms: linux/amd64
165-
push: true
166-
tags: ${{ steps.build_config.outputs.tags }}
167-
labels: ${{ steps.meta.outputs.labels }}
133+
tags: ${{ steps.version.outputs.tags }}
134+
labels: |
135+
org.opencontainers.image.title=Changerawr
136+
org.opencontainers.image.description=Ship, Change, Rawr 🦖 - Changelog management made cute and simple
137+
org.opencontainers.image.vendor=Supernova3339
138+
org.opencontainers.image.url=https://github.com/${{ github.repository }}
139+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
140+
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}#readme
141+
org.opencontainers.image.version=${{ steps.version.outputs.version }}
142+
org.opencontainers.image.revision=${{ steps.version.outputs.revision }}
143+
org.opencontainers.image.created=${{ steps.version.outputs.buildtime }}
168144
cache-from: type=gha
169145
cache-to: type=gha,mode=max
170146
build-args: |
171-
BUILDTIME=${{ steps.build_config.outputs.buildtime }}
172-
VERSION=${{ steps.build_config.outputs.version }}
173-
REVISION=${{ steps.build_config.outputs.revision }}
174-
provenance: false
175-
sbom: false
176-
177-
# Strategy 3: Legacy docker build (last resort)
178-
- name: Build Docker image (Legacy)
179-
if: github.event.inputs.build_strategy == 'legacy'
180-
run: |
181-
# Get the first tag for legacy build
182-
FIRST_TAG=$(echo "${{ steps.build_config.outputs.tags }}" | head -n1)
183-
184-
docker build \
185-
--build-arg BUILDTIME="${{ steps.build_config.outputs.buildtime }}" \
186-
--build-arg VERSION="${{ steps.build_config.outputs.version }}" \
187-
--build-arg REVISION="${{ steps.build_config.outputs.revision }}" \
188-
--tag "$FIRST_TAG" \
189-
--file ./Dockerfile \
190-
.
191-
192-
- name: Push Docker image (Legacy)
193-
if: github.event.inputs.build_strategy == 'legacy'
194-
run: |
195-
# Push all tags for legacy build
196-
echo "${{ steps.build_config.outputs.tags }}" | while IFS= read -r tag; do
197-
if [ -n "$tag" ]; then
198-
echo "Pushing $tag"
199-
docker push "$tag"
200-
fi
201-
done
147+
BUILDTIME=${{ steps.version.outputs.buildtime }}
148+
VERSION=${{ steps.version.outputs.version }}
149+
REVISION=${{ steps.version.outputs.revision }}
202150
203151
- name: Generate image summary
204152
run: |
@@ -210,32 +158,18 @@ jobs:
210158
echo "" >> $GITHUB_STEP_SUMMARY
211159
fi
212160
213-
BUILD_STRATEGY="${{ github.event.inputs.build_strategy }}"
214-
if [ -z "$BUILD_STRATEGY" ]; then
215-
BUILD_STRATEGY="buildx-multi"
216-
fi
217-
echo "**Build Strategy:** $BUILD_STRATEGY" >> $GITHUB_STEP_SUMMARY
218-
echo "" >> $GITHUB_STEP_SUMMARY
219-
220161
echo "**Image:** \`${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}\`" >> $GITHUB_STEP_SUMMARY
162+
echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
163+
echo "**Platform:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
221164
echo "" >> $GITHUB_STEP_SUMMARY
222165
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
223166
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
224-
echo "${{ steps.build_config.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY
167+
echo "${{ steps.version.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY
225168
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
226169
echo "" >> $GITHUB_STEP_SUMMARY
227-
228-
if [ "$BUILD_STRATEGY" = "legacy" ]; then
229-
echo "**Platforms:** linux/amd64" >> $GITHUB_STEP_SUMMARY
230-
elif [ "$BUILD_STRATEGY" = "buildx-single" ]; then
231-
echo "**Platforms:** linux/amd64" >> $GITHUB_STEP_SUMMARY
232-
else
233-
echo "**Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
234-
fi
235-
echo "" >> $GITHUB_STEP_SUMMARY
236170
echo "**Pull Command:**" >> $GITHUB_STEP_SUMMARY
237171
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
238-
echo "docker pull ${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:latest" >> $GITHUB_STEP_SUMMARY
172+
echo "docker pull ${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
239173
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
240174
241175
skip-build:
@@ -251,8 +185,7 @@ jobs:
251185
echo "" >> $GITHUB_STEP_SUMMARY
252186
echo "**To enable Docker builds:**" >> $GITHUB_STEP_SUMMARY
253187
echo "1. Make the repository public, or" >> $GITHUB_STEP_SUMMARY
254-
echo "2. Run workflow manually with 'Force build' option enabled, or" >> $GITHUB_STEP_SUMMARY
255-
echo "3. Modify the workflow to allow private builds by default" >> $GITHUB_STEP_SUMMARY
188+
echo "2. Run workflow manually with 'Force build' option enabled" >> $GITHUB_STEP_SUMMARY
256189
echo "" >> $GITHUB_STEP_SUMMARY
257190
echo "**Repository:** \`${{ github.repository }}\`" >> $GITHUB_STEP_SUMMARY
258-
echo "**Trigger:** \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY
191+
echo "**Trigger:** \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)