-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (117 loc) · 4.32 KB
/
docker.yml
File metadata and controls
134 lines (117 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: 🐳 Reusable Docker Build
on:
workflow_call:
inputs:
version:
required: true
type: string
registry:
required: false
type: string
default: 'docker.io'
image_name:
required: false
type: string
default: ""
push:
required: false
type: boolean
default: true
provenance:
required: false
type: boolean
default: true
sbom:
required: false
type: boolean
default: true
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
env:
ORGANISATION: ${{ github.repository_owner }}
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Resolve Image Name
id: prep
run: |
if [ -n "${{ inputs.image_name }}" ]; then
FULL_NAME="${{ inputs.image_name }}"
else
FULL_NAME="${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}"
fi
# Force lowercase for Docker Hub compatibility
FINAL_NAME=$(echo "$FULL_NAME" | tr '[:upper:]' '[:lower:]')
REPO_ONLY=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
echo "image_full_name=$FINAL_NAME" >> $GITHUB_OUTPUT
echo "repo_only=$REPO_ONLY" >> $GITHUB_OUTPUT
echo "ℹ️ Resolved Image Name: $FINAL_NAME"
- name: Log in to ${{ inputs.registry }}
if: inputs.push == true
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Generate metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ steps.prep.outputs.image_full_name }}
tags: |
# Tag based on the version input provided
type=raw,value=${{ inputs.version }}
# Also tag with 'latest' if on default branch
type=raw,value=latest,enable={{is_default_branch}}
# Git Short SHA
type=sha,prefix=sha-
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.vendor=${{ env.ORGANISATION }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.licenses=MIT
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
# Multi-arch support
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push }}
provenance: ${{ inputs.provenance }}
sbom: ${{ inputs.sbom }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# GitHub Actions Cache (extremely fast)
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate image summary
if: inputs.push == true
run: |
echo "## Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** \`${{ inputs.registry }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ steps.prep.outputs.image_full_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Tags" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pull Command" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ inputs.registry }}/${{ steps.prep.outputs.image_full_name }}:latest" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY