action.yml RawHistoryFolder
1name: 'Gordon Deploy'
2description: 'Build and push container images to a Gordon registry on tag push'
3author: 'Gordon Contributors'
4
5branding:
6 icon: 'upload-cloud'
7 color: 'blue'
8
9inputs:
10 registry:
11 description: 'Gordon registry URL (e.g., registry.mydomain.com)'
12 required: true
13 username:
14 description: 'Registry username (token subject for token auth)'
15 required: true
16 password:
17 description: 'Registry password or token'
18 required: true
19 image:
20 description: 'Image name (defaults to repository name)'
21 required: false
22 default: ''
23 tag:
24 description: 'Override image tag (defaults to git tag or short SHA)'
25 required: false
26 default: ''
27 dockerfile:
28 description: 'Path to Dockerfile (defaults to ./Dockerfile)'
29 required: false
30 default: './Dockerfile'
31 context:
32 description: 'Build context path (defaults to .)'
33 required: false
34 default: '.'
35 build-args:
36 description: 'Build arguments (one per line, KEY=value format)'
37 required: false
38 default: ''
39 platforms:
40 description: 'Target platforms (e.g., linux/amd64,linux/arm64)'
41 required: false
42 default: ''
43 push-latest:
44 description: 'Also push with :latest tag'
45 required: false
46 default: 'true'
47 cache-from:
48 description: 'Cache source (e.g., type=gha)'
49 required: false
50 default: 'type=gha'
51 cache-to:
52 description: 'Cache destination (e.g., type=gha,mode=max)'
53 required: false
54 default: 'type=gha,mode=max'
55
56outputs:
57 image:
58 description: 'Full image reference that was pushed'
59 value: ${{ steps.meta.outputs.image }}
60 tag:
61 description: 'Tag that was pushed'
62 value: ${{ steps.meta.outputs.tag }}
63 digest:
64 description: 'Image digest'
65 value: ${{ steps.push.outputs.digest }}
66
67runs:
68 using: 'composite'
69 steps:
70 - name: Validate inputs
71 shell: bash
72 run: |
73 if [[ ! -f "${{ inputs.dockerfile }}" ]]; then
74 echo "::error::Dockerfile not found at ${{ inputs.dockerfile }}"
75 exit 1
76 fi
77
78 - name: Extract metadata
79 id: meta
80 shell: bash
81 run: |
82 # Determine image name
83 IMAGE_NAME="${{ inputs.image }}"
84 if [[ -z "$IMAGE_NAME" ]]; then
85 IMAGE_NAME="${GITHUB_REPOSITORY#*/}"
86 fi
87
88 # Extract tag from ref (or override)
89 if [[ -n "${{ inputs.tag }}" ]]; then
90 TAG="${{ inputs.tag }}"
91 elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
92 TAG="${GITHUB_REF#refs/tags/}"
93 else
94 TAG="$(echo "$GITHUB_SHA" | head -c 7)"
95 fi
96
97 # Full image reference
98 FULL_IMAGE="${{ inputs.registry }}/${IMAGE_NAME}:${TAG}"
99
100 echo "image=${FULL_IMAGE}" >> $GITHUB_OUTPUT
101 echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
102 echo "tag=${TAG}" >> $GITHUB_OUTPUT
103 echo "registry=${{ inputs.registry }}" >> $GITHUB_OUTPUT
104
105 echo "Building: ${FULL_IMAGE}"
106
107 - name: Set up QEMU
108 uses: docker/setup-qemu-action@v3
109
110 - name: Set up Docker Buildx
111 uses: docker/setup-buildx-action@v3
112
113 - name: Log in to Gordon registry
114 uses: docker/login-action@v3
115 with:
116 registry: ${{ inputs.registry }}
117 username: ${{ inputs.username }}
118 password: ${{ inputs.password }}
119
120 - name: Build tags
121 id: tags
122 shell: bash
123 run: |
124 TAGS="${{ steps.meta.outputs.image }}"
125 if [[ "${{ inputs.push-latest }}" == "true" ]]; then
126 TAGS="${TAGS}"$'\n'"${{ inputs.registry }}/${{ steps.meta.outputs.image_name }}:latest"
127 fi
128 printf "tags<<EOF\n%s\nEOF\n" "$TAGS" >> "$GITHUB_OUTPUT"
129
130 - name: Build and push
131 id: push
132 uses: docker/build-push-action@v6
133 env:
134 DOCKER_BUILD_SUMMARY: false
135 with:
136 context: ${{ inputs.context }}
137 file: ${{ inputs.dockerfile }}
138 push: true
139 tags: ${{ steps.tags.outputs.tags }}
140 build-args: ${{ inputs.build-args }}
141 platforms: ${{ inputs.platforms }}
142 cache-from: ${{ inputs.cache-from }}
143 cache-to: ${{ inputs.cache-to }}
144 provenance: false
145
146 - name: Summary
147 shell: bash
148 run: |
149 echo "## Gordon Deploy Summary" >> $GITHUB_STEP_SUMMARY
150 echo "" >> $GITHUB_STEP_SUMMARY
151 echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
152 echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY
153 echo "| Image | \`${{ steps.meta.outputs.image }}\` |" >> $GITHUB_STEP_SUMMARY
154 echo "| Tag | \`${{ steps.meta.outputs.tag }}\` |" >> $GITHUB_STEP_SUMMARY
155 echo "| Digest | \`${{ steps.push.outputs.digest }}\` |" >> $GITHUB_STEP_SUMMARY
156 echo "" >> $GITHUB_STEP_SUMMARY
157 echo "Container deployed to Gordon registry and will be automatically deployed." >> $GITHUB_STEP_SUMMARY