From 414e0e18f7a27b08a36c48c1e6d6a7837c1e95a5 Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Wed, 3 Jan 2024 23:29:58 +0100 Subject: [PATCH] add workflow build container --- .github/workflows/build_container.yml | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/build_container.yml diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml new file mode 100644 index 0000000..bfa2b84 --- /dev/null +++ b/.github/workflows/build_container.yml @@ -0,0 +1,76 @@ +--- +# template source: https://github.com/bretfisher/docker-build-workflow/blob/main/templates/call-docker-build.yaml +name: Docker Build + +on: + push: + branches: + - main + tags: + - '*' + # pull_request: + # branches: + # - main + +env: + IMAGE_NAME: sonarqube-ecocode-python + IMAGES: | + ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode-python + +jobs: + Build: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + images: ${{ env.IMAGES }} + flavor: | + latest=auto + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,event=tag,pattern={{version}} + type=semver,event=tag,pattern={{major}}.{{minor}} + type=semver,event=tag,pattern={{major}} + type=ref,event=branch + type=ref,event=pr + type=sha + + - name: Publish image + id: push + uses: docker/build-push-action@v4 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + pull: true + cache-to: type=gha,mode=max + cache-from: type=gha,mode=max