Skip to content

Commit

Permalink
ci: Publish images to ghcr.io
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak committed Mar 24, 2023
1 parent 9ba48e1 commit bb99b03
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Images
name: Build Images (Docker Hub)

on:
pull_request:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/build-images-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build Images (ghcr.io)

on:
pull_request:
branches:
- master
push:
branches:
- master
schedule:
- cron: '0 */12 * * *'
workflow_dispatch:

jobs:
build-images:
name: "VPP ${{ matrix.tag }}"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMG_NAME: ${{ github.repository }}
REPO: ${{ matrix.repo }}
TAG: ${{ matrix.tag }}
strategy:
fail-fast: false
matrix:
tag: ['master', 'latest', '23.02', '22.10', '22.06', '22.02']
include:
- tag: 'master'
repo: 'master'
- tag: 'latest'
repo: 'release'
- tag: '23.02'
repo: '2302'
- tag: '22.10'
repo: '2210'
- tag: '22.06'
repo: '2206'
- tag: '22.02'
repo: '2202'

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build image
run: |
env | sort
docker build --build-arg REPO="$REPO" --tag "$REGISTRY/$IMG_NAME:$TAG" .
docker run --rm "$REGISTRY/$IMG_NAME:$TAG" dpkg-query -f '${Version}' -W vpp
VPP_VERSION=$(docker run --rm "$REGISTRY/$IMG_NAME:$TAG" cat /vpp/version | cut -d'~' -f1,2 | sed -e 's/~/./g')
echo "VPP_VERSION=$VPP_VERSION" >> $GITHUB_ENV
- name: Check if image already published
# if: github.event_name != 'pull_request'
run: |
docker tag "$REGISTRY/$IMG_NAME:$TAG" "$REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }}"
docker images "$REGISTRY/$IMG_NAME"
GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
if [ ${{ github.event_name }} == "schedule" ] \
&& curl --head --fail -H "Authorization: Bearer ${GHCR_TOKEN}" https://$REGISTRY/v2/$IMG_NAME/manifests/${{ env.VPP_VERSION }}; then
echo "Image $REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }} has already been published"
exit 1
fi
- name: Publish image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.actor }}" --password-stdin
docker push "$REGISTRY/$IMG_NAME:${{ env.VPP_VERSION }}"
docker push "$REGISTRY/$IMG_NAME:$TAG"

0 comments on commit bb99b03

Please sign in to comment.