-
Notifications
You must be signed in to change notification settings - Fork 12
230 lines (196 loc) · 8.75 KB
/
docker-publish.yml
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Docker
on:
push:
paths-ignore:
- '*.md'
- '**/*.md'
# Publish `master` as Docker `edge` image.
branches:
- master
- develop
- 'release/*'
tags:
- 'v*.*.*'
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: ps3netsrv
IMAGE_TITLE: ps3netsrv
IMAGE_DESCRIPTION: Docker container for ps3netsrv
APP_VERSION: "20240210"
RELEASE_TAG: "1.47.45"
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx_test
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.test-buildx-cache
key: ${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-test-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-test-buildx-
- name: Test build
id: docker_build_test
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx_test.outputs.name }}
context: .
platforms: linux/amd64
push: false
build-args: |
PS3NETSRV_RELEASE=${{ env.RELEASE_TAG }}
PS3NETSRV_VERSION=${{ env.APP_VERSION }}
cache-from: type=local,src=/tmp/.test-buildx-cache
cache-to: type=local,dest=/tmp/.test-buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.test-buildx-cache
mv /tmp/.test-buildx-cache-new /tmp/.test-buildx-cache
# Build images.
build:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare
id: prep
run: |
DOCKERIO_IMAGE=docker.io/${{ github.repository_owner }}/$IMAGE_NAME
GHCRIO_IMAGE=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Strip git ref prefix from version
VERSION_FULL=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\)$,\1,')
VERSION_MINOR=$(echo "$VERSION_FULL" | sed 's,\.[^.]*$,,')
VERSION_MAJOR=$(echo "$VERSION_MINOR" | sed 's,\.[^.]*$,,')
# Use Docker `edge` tag convention and pr-<number> for pull requests
[ "$VERSION_FULL" == "master" ] && VERSION_FULL=edge
[ ${{ github.ref }} == refs/pull/* ] && VERSION_FULL=pr-${{ github.event.number }}
# Build all tags
DOCKERIO_TAGS="${DOCKERIO_IMAGE}:${VERSION_FULL}"
[ "$VERSION_FULL" != "edge" ] && DOCKERIO_TAGS="$DOCKERIO_TAGS,${DOCKERIO_IMAGE}:${VERSION_MINOR},${DOCKERIO_IMAGE}:${VERSION_MAJOR},${DOCKERIO_IMAGE}:${APP_VERSION},${DOCKERIO_IMAGE}:latest"
[ "$VERSION_FULL" == "edge" ] && DOCKERIO_TAGS="$TAGS,${DOCKERIO_IMAGE}:${VERSION_FULL}-${APP_VERSION}"
GHCRIO_TAGS="${GHCRIO_IMAGE}:${VERSION_FULL}"
[ "$VERSION_FULL" != "edge" ] && GHCRIO_TAGS="$GHCRIO_TAGS,${GHCRIO_IMAGE}:${VERSION_MINOR},${GHCRIO_IMAGE}:${VERSION_MAJOR},${GHCRIO_IMAGE}:${APP_VERSION},${GHCRIO_IMAGE}:latest"
[ "$VERSION_FULL" == "edge" ] && GHCRIO_TAGS="$GHCRIO_TAGS,${GHCRIO_IMAGE}:${VERSION_FULL}-${APP_VERSION}"
# Build tags for README.md
[ "$VERSION_FULL" != "edge" ] && README_TAGS="\`latest\`, \`${VERSION_MAJOR}\`, \`${VERSION_MINOR}\`, \`${VERSION_FULL}\`, \`${APP_VERSION}\`"
[ "$VERSION_FULL" == "edge" ] && README_TAGS="\`${VERSION_FULL}\`, \`${VERSION_FULL}-${APP_VERSION}\`"
# Replace supported latest tags in README.md
if [ "$VERSION_FULL" != "edge" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- '"${README_TAGS}"' <!-- latest tag -->' README.md
fi
# Replace supported edge tags in README.md
if [ "$VERSION_FULL" == "edge" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- '"${README_TAGS}"' <!-- edge tag -->' README.md
fi
# Use Docker `edge` tag convention and pr-<number> for pull requests
[ "$VERSION_FULL" == "master" ] && VERSION_FULL=edge
[ ${{ github.ref }} == refs/pull/* ] && VERSION_FULL=pr-${{ github.event.number }}
# Build tags for README.md
[ "$VERSION_FULL" != "edge" ] && README_TAGS="\`latest\`, \`${VERSION_MAJOR}\`, \`${VERSION_MINOR}\`, \`${VERSION_FULL}\`, \`${APP_VERSION}\`"
[ "$VERSION_FULL" == "edge" ] && README_TAGS="\`${VERSION_FULL}\`, \`${VERSION_FULL}-${APP_VERSION}\`"
echo "version=${VERSION_FULL}" >> $GITHUB_OUTPUT
echo "tags=${DOCKERIO_TAGS},${GHCRIO_TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "readme_tags=${README_TAGS}" >> $GITHUB_OUTPUT
echo "release=${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') }}" >> $GITHUB_OUTPUT
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.APP_VERSION }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.APP_VERSION }}
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ steps.prep.outputs.release == 'true' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
PS3NETSRV_RELEASE=${{ env.RELEASE_TAG }}
PS3NETSRV_VERSION=${{ env.APP_VERSION }}
labels: |
org.opencontainers.image.title=$IMAGE_TITLE
org.opencontainers.image.description=$IMAGE_DESCRIPTION
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=$APP_VERSION
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Checkout master
if: steps.prep.outputs.release == 'true'
uses: actions/checkout@v4
with:
ref: master
- name: Update README.md
if: steps.prep.outputs.release == 'true'
id: update-readme
run: |
# Replace supported latest tags in README.md
if [ "${{ steps.prep.outputs.version }}" != "edge" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- ${{ steps.prep.outputs.readme_tags }} <!-- latest tag -->' README.md
fi
# Replace supported edge tags in README.md
if [ "${{ steps.prep.outputs.version }}" == "edge" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- ${{ steps.prep.outputs.readme_tags }} <!-- edge tag -->' README.md
fi
- name: Check for modified files
if: steps.prep.outputs.release == 'true'
id: git-check
run: echo modified=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true") >> $GITHUB_OUTPUT
- name: Commit updated README.md
if: steps.git-check.outputs.modified == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "docs(README): update supported tags"
git push
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache