Skip to content

Commit 5a210e3

Browse files
committed
ci: Publish images to ghcr.io
Signed-off-by: Peter Motičák <[email protected]>
1 parent 9ba48e1 commit 5a210e3

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

.github/workflows/build-images.yml renamed to .github/workflows/build-images-dockerhub.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Images
1+
name: Build Images (Docker Hub)
22

33
on:
44
pull_request:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build Images (ghcr.io)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
schedule:
11+
- cron: '0 */12 * * *'
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-images:
16+
name: "VPP ${{ matrix.tag }}"
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
env:
22+
REGISTRY: ghcr.io
23+
IMG_NAME: ${{ github.repository }}
24+
REPO: ${{ matrix.repo }}
25+
TAG: ${{ matrix.tag }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
tag: ['master', 'latest', '23.02', '22.10', '22.06', '22.02']
30+
include:
31+
- tag: 'master'
32+
repo: 'master'
33+
- tag: 'latest'
34+
repo: 'release'
35+
- tag: '23.02'
36+
repo: '2302'
37+
- tag: '22.10'
38+
repo: '2210'
39+
- tag: '22.06'
40+
repo: '2206'
41+
- tag: '22.02'
42+
repo: '2202'
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v3
47+
48+
- name: Build image
49+
run: |
50+
env | sort
51+
docker build --build-arg REPO="$REPO" --tag "$REGISTRY/$IMG_NAME:$TAG" .
52+
docker run --rm "$REGISTRY/$IMG_NAME:$TAG" dpkg-query -f '${Version}' -W vpp
53+
VPP_VERSION=$(docker run --rm "$REGISTRY/$IMG_NAME:$TAG" cat /vpp/version | cut -d'~' -f1,2 | sed -e 's/~/./g')
54+
echo "VPP_VERSION=$VPP_VERSION" >> $GITHUB_ENV
55+
56+
- name: Check if image already published
57+
if: github.event_name != 'pull_request'
58+
run: |
59+
docker tag "$REGISTRY/$IMG_NAME:$TAG" "$REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }}"
60+
docker images "$REGISTRY/$IMG_NAME"
61+
GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
62+
if [ ${{ github.event_name }} == "schedule" ] \
63+
&& curl --head --fail -H "Authorization: Bearer ${GHCR_TOKEN}" https://$REGISTRY/v2/$IMG_NAME/manifests/${{ env.VPP_VERSION }}; then
64+
echo "Image $REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }} has already been published"
65+
exit 1
66+
fi
67+
68+
- name: Publish image
69+
if: github.event_name != 'pull_request' && success()
70+
run: |
71+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.actor }}" --password-stdin
72+
docker push "$REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }}"
73+
docker push "$REGISTRY/$IMG_NAME:$TAG"

0 commit comments

Comments
 (0)