From a41aa82673e95fa76cc20c29b1b55e5cfecc0aa8 Mon Sep 17 00:00:00 2001 From: Nick Maietta Date: Wed, 3 Aug 2022 08:44:23 -0700 Subject: [PATCH 1/3] Update release.yml Swap out patched together workflow with official version provided by Github. This is cleaner, less likely to need maintenance later. Performs exactly the same job as previous. --- .github/workflows/release.yml | 94 +++++++++++++++++------------------ 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b889826..1118867 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,60 +1,56 @@ -name: Build release +name: Create Release -on: +on: push: - branches: [ main ] - # Publish semver tags as releases. - tags: [ 'v*.*.*' ] + + # Publish `master` as Docker `latest` image. + branches: + - main + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run for any PRs. pull_request: - branches: [ main ] + # Create a button to trigger the workflow manually. workflow_dispatch: - branches: [ main ] - tags: [ 'v*.*.*' ] env: - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} + # the target name of the image. + IMAGE_NAME: deploy-from-github jobs: - buildx: + # Push image to GitHub Packages Container Registry. + push: runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@v3 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v3 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: Push image + 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" == "master" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION From 7e848760fe2227ae5a9d048b84009c458b493f20 Mon Sep 17 00:00:00 2001 From: Nick Maietta Date: Wed, 3 Aug 2022 08:53:10 -0700 Subject: [PATCH 2/3] Update release.yml Branch name correction --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1118867..0292b1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,7 +49,7 @@ jobs: # Strip "v" prefix from tag name [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest + [ "$VERSION" == "main" ] && VERSION=latest echo IMAGE_ID=$IMAGE_ID echo VERSION=$VERSION docker tag $IMAGE_NAME $IMAGE_ID:$VERSION From d6ffc1b00e2e01646d6a7460f186f241ac967af7 Mon Sep 17 00:00:00 2001 From: Nick Maietta Date: Fri, 5 Aug 2022 06:35:53 -0700 Subject: [PATCH 3/3] Update release.yml Removed unnecessary PR trigger. --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0292b1f..385059b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,9 +11,6 @@ on: tags: - v* - # Run for any PRs. - pull_request: - # Create a button to trigger the workflow manually. workflow_dispatch: