diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 27ee0f1..99915e3 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -1,4 +1,4 @@ -name: Docker +name: Build Image on: push: @@ -51,9 +51,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME - - name: Log in to GitHub Container Registry uses: docker/login-action@v1 with: @@ -61,34 +58,27 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push image to Container Registry - uses: docker/build-push-action@v2 - with: - push: true - tags: | - ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ github.sha }} - ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}:${{ github.ref }} - #- name: Log into registry - # run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - - #- name: Push image - # run: | - # IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME - + - name: Create Tagged Image Name + 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]') - + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version - # VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - + 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//') - + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention - # [ "$VERSION" == "master" ] && VERSION=latest + [ "$VERSION" == "master" ] && VERSION=latest - # echo IMAGE_ID=$IMAGE_ID - # echo VERSION=$VERSION + echo "TAGGED_IMAGE_NAME=$IMAGE_ID:$VERSION" >> $GITHUB_ENV - # docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - # docker push $IMAGE_ID:$VERSION + - name: Build and push image to Container Registry + uses: docker/build-push-action@v2 + with: + push: true + tags: | + ${{ env.TAGGED_IMAGE_NAME }}