Skip to content

Commit 48efbd5

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

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