From 219db04215cce32a189d023ca8e05bd15a07ecb6 Mon Sep 17 00:00:00 2001 From: rjonczy Date: Fri, 26 Apr 2024 17:12:09 +0200 Subject: [PATCH] build and push docker --- .github/workflows/docker-build.yml | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..ab34dc2 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,72 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Check out the code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker (tag) + id: meta-tag + if: github.ref_type == 'tag' + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + + - name: Extract metadata (tags, labels) for Docker (branch) + id: meta-branch + if: github.ref_type == 'branch' + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=sha,prefix={{branch}}-{{date 'YYYYMMDDHHmmss'}}- + + - name: Build and Push Docker Image (tag) + if: github.ref_type == 'tag' + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta-tag.outputs.tags }} + labels: ${{ steps.meta-tag.outputs.labels }} + + - name: Build and Push Docker Image (branch) + if: github.ref_type == 'branch' + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta-branch.outputs.tags }} + labels: ${{ steps.meta-branch.outputs.labels }} \ No newline at end of file