-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (93 loc) · 3.4 KB
/
Copy pathdocker.yml
File metadata and controls
104 lines (93 loc) · 3.4 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
name: Docker Image CI/CD
on:
push:
branches: [ "main", "develop" ]
tags: [ "v*" ]
pull_request:
branches: [ "main", "develop" ]
env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# Restrict unused permissions.
actions: none
checks: none
deployments: none
issues: none
pull-requests: none
statuses: none
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Verify version metadata
run: bash scripts/check-version.sh
- name: Determine image version
id: version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
version="pr-${{ github.event.number }}"
latest=false
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
version="${{ github.ref_name }}"
if [[ "$version" == *-* ]]; then
latest=false
else
latest=true
fi
else
version="$(tr -d '[:space:]' < VERSION)"
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
version="${version}-develop"
latest=false
else
latest=true
fi
fi
echo "tag=$version" >> "$GITHUB_OUTPUT"
echo "latest=$latest" >> "$GITHUB_OUTPUT"
# Set up Buildx for multi-architecture builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
# Login against a Docker registry except on PR
- name: Log into Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
# Do not build the image name from a secret: secrets are unavailable
# to Dependabot and fork PRs, which previously produced "/aptify".
images: ${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=ref,event=pr
type=raw,value=${{ steps.version.outputs.tag }},enable=${{ github.event_name != 'pull_request' }}
type=raw,value=latest,enable=${{ steps.version.outputs.latest == 'true' }}
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
load: ${{ github.event_name == 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.version.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max