diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 3b099c6..23d2f01 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -4,6 +4,12 @@ on: push: branches: - master + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: dockerbuildpush: @@ -11,17 +17,24 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set a datetag variable - run: echo "DATETAG=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV - - name: Create image from repository - run: docker build -t ghcr.io/${{ github.actor }}/homeassistant-discord-bot:latest -t ghcr.io/${{ github.actor }}/homeassistant-discord-bot:${{ env.DATETAG }} . - - name: Push image to GitHub Container Registry with date tag - run: docker push ghcr.io/${{ github.actor }}/homeassistant-discord-bot:${{ env.DATETAG }} - - name: Push image to GitHub Container Registry as latest - run: docker push ghcr.io/${{ github.actor }}/homeassistant-discord-bot:latest + + - name: Extract metadata for the Docker image + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push the Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}