diff --git a/.github/workflows/build_and_push_dockerimage.yml b/.github/workflows/build_and_push_dockerimage.yml new file mode 100644 index 0000000..2533569 --- /dev/null +++ b/.github/workflows/build_and_push_dockerimage.yml @@ -0,0 +1,50 @@ +name: Build and Publish + +on: + push: + branches: + - '**' + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + # define job to build and publish docker image + build-and-push-docker-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build image and push to Docker Hub and GitHub Container Registry + id: build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Image digest + run: echo ${{ steps.build.outputs.digest }} \ No newline at end of file