From ce138fb4068cdddad679b78aba0f6a80da2f1832 Mon Sep 17 00:00:00 2001 From: KoalaGeo Date: Tue, 7 May 2024 13:14:42 +0100 Subject: [PATCH] add workflow --- .github/workflows/main.yml | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..17eaf92 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,61 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Build and Push Container + +on: + push: + branches: + - main + release: + types: + - released + +env: + REGISTRY: ghcr.io + IMAGE_NAME: gn-ogcapirecords + +jobs: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + build_and_push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + + - name: Log in to registry + # This is where you will update the PAT to GITHUB_TOKEN + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Rename image for publication + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + echo FULLCONTAINERNAME=$IMAGE_ID:$VERSION >> $GITHUB_ENV + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + + #- uses: Azure/container-scan@v0 + #with: + #image-name: ${{ env.FULLCONTAINERNAME }} + + - name: Push to CR + run: docker push ${{ env.FULLCONTAINERNAME }}