diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 7cd408fd..eaeb0fc2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -2,13 +2,8 @@ name: Docker on: push: - # Publish `main` as Docker `latest` image. - branches: - - main - - # Publish `v1.2.3` tags as releases. tags: - - v* + - '*' env: IMAGE_NAME: feature-server @@ -20,29 +15,37 @@ jobs: if: github.event_name == 'push' steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Log into registry - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin - - - name: Push image + - name: prepare tag run: | - IMAGE_ID=jambonz/$IMAGE_NAME + IMAGE_ID=jambonz/$IMAGE_NAME - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # 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//') + # 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 + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION \ No newline at end of file + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: jambonz/$IMAGE_NAME:$VERSION + build-args: | + GITHUB_REPOSITORY=$GITHUB_REPOSITORY + GITHUB_REF=$GITHUB_REF