From bb99b030b714da2791663a2442ad336410bafeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Moti=C4=8D=C3=A1k?= Date: Thu, 23 Mar 2023 19:57:13 +0100 Subject: [PATCH] ci: Publish images to ghcr.io MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Motičák --- ...-images.yml => build-images-dockerhub.yml} | 2 +- .github/workflows/build-images-ghcr.yml | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) rename .github/workflows/{build-images.yml => build-images-dockerhub.yml} (98%) create mode 100644 .github/workflows/build-images-ghcr.yml diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images-dockerhub.yml similarity index 98% rename from .github/workflows/build-images.yml rename to .github/workflows/build-images-dockerhub.yml index 4a3e33b..de68010 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images-dockerhub.yml @@ -1,4 +1,4 @@ -name: Build Images +name: Build Images (Docker Hub) on: pull_request: diff --git a/.github/workflows/build-images-ghcr.yml b/.github/workflows/build-images-ghcr.yml new file mode 100644 index 0000000..9c053e0 --- /dev/null +++ b/.github/workflows/build-images-ghcr.yml @@ -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"