1+ name : Reusable Local Build Workflow
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ image_name :
7+ description : ' Name of the container image (e.g., glowing-bear)'
8+ required : true
9+ type : string
10+ platforms :
11+ description : ' Target platforms for build'
12+ required : false
13+ type : string
14+ default : ' linux/amd64,linux/arm64'
15+ registry :
16+ description : ' Container registry to push to'
17+ required : false
18+ type : string
19+ default : ' ghcr.io'
20+ tags_extra :
21+ description : ' Additional tags to apply'
22+ required : false
23+ type : string
24+ default : ' '
25+
26+ jobs :
27+ build :
28+ runs-on : ubuntu-latest
29+ steps :
30+ - name : Set variables useful for later
31+ id : useful_vars
32+ run : |-
33+ echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
34+ echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
35+
36+ - name : Checkout
37+ uses : actions/checkout@v4
38+
39+ - name : Docker meta
40+ id : docker_meta
41+ uses : docker/metadata-action@v5
42+ with :
43+ images : ${{ inputs.registry }}/${{ github.repository }}/${{ inputs.image_name }}
44+ tags : |
45+ type=schedule
46+ type=ref,event=branch
47+ type=ref,event=pr
48+ type=semver,pattern={{version}}
49+ type=semver,pattern={{major}}.{{minor}}
50+ type=semver,pattern={{major}}
51+ type=sha,prefix=,format=long,event=tag
52+ type=sha
53+ type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
54+ type=raw,value=${{ github.ref_name }}-${{ steps.useful_vars.outputs.short_sha }}-${{ steps.useful_vars.outputs.timestamp }},enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
55+ ${{ inputs.tags_extra }}
56+
57+ - name : Set up QEMU
58+ uses : docker/setup-qemu-action@v3
59+
60+ - name : Set up Docker Buildx
61+ uses : docker/setup-buildx-action@v3
62+
63+ - name : Login to GHCR
64+ if : github.event_name != 'pull_request'
65+ uses : docker/login-action@v3
66+ with :
67+ registry : ${{ inputs.registry }}
68+ username : ${{ github.repository_owner }}
69+ password : ${{ secrets.GITHUB_TOKEN }}
70+
71+ - name : Cache Docker layers
72+ uses : actions/cache@v4
73+ with :
74+ path : /tmp/.buildx-cache
75+ key : ${{ runner.os }}-${{ inputs.image_name }}-buildx-${{ github.sha }}
76+ restore-keys : |
77+ ${{ runner.os }}-${{ inputs.image_name }}-buildx-
78+
79+ - name : Build and push
80+ uses : docker/build-push-action@v6
81+ with :
82+ context : ${{ inputs.image_name }}
83+ push : ${{ github.event_name != 'pull_request' }}
84+ tags : ${{ steps.docker_meta.outputs.tags }}
85+ labels : ${{ steps.docker_meta.outputs.labels }}
86+ platforms : ${{ inputs.platforms }}
87+ cache-from : type=local,src=/tmp/.buildx-cache
88+ cache-to : type=local,dest=/tmp/.buildx-cache,mode=max
0 commit comments