-
Notifications
You must be signed in to change notification settings - Fork 44
144 lines (131 loc) · 4.67 KB
/
docker.yml
File metadata and controls
144 lines (131 loc) · 4.67 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
134
135
136
137
138
139
140
141
142
143
144
name: Dockerize
on:
push:
pull_request:
env:
REGISTRY_IMAGE: specifyconsortium/specify7-service
jobs:
prep:
name: prepare tag names
runs-on: ubuntu-latest
# "push" event is not triggered for forks, so need to listen for
# pull_requests, but only for external ones, so as not to run the action
# twice
if: github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.fork == true
outputs:
tags: ${{ steps.prep.outputs.tags }}
version: ${{ steps.prep.outputs.version }}
steps:
- name: Prepare tags and version for manifest
id: prep
run: |
DOCKER_IMAGE=${{ env.REGISTRY_IMAGE }}
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
# Docker does not like / in tag names, so replace them with -
# See https://github.com/specify/specify7-test-panel/issues/110#issuecomment-1943045253
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=main
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
HOTFIX=${VERSION%.*}
MINOR=${HOTFIX%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${HOTFIX},${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS"
fi
echo "Tags: ${TAGS}"
echo "Version: ${VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
build:
name: build & push
needs: prep
strategy:
fail-fast: false
matrix:
include:
- name: amd64
platform: linux/amd64
runner: ubuntu-latest
- name: arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
build-args: |
BUILD_VERSION=${{ needs.prep.outputs.version }}
GIT_SHA=${{ github.sha }}
tags: ${{ needs.prep.outputs.tags }}
push: true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.name }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: create & push manifest
needs:
- prep
- build
runs-on: ubuntu-latest
steps:
- name: Download all digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
env:
TAGS: ${{ needs.prep.outputs.tags }}
run: |
echo "Pushing manifests on tags: ${TAGS}"
TAG_ARGS=$(echo "$TAGS" | tr ',' '\n' | sed 's/^/-t /' | xargs)
docker buildx imagetools create $TAG_ARGS \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ needs.prep.outputs.version }}