|
| 1 | +name: Build Container Image Builds |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, stable, oldstable ] |
| 6 | + tags: ["v*"] |
| 7 | + paths: |
| 8 | + - .github/workflows/build-container.yml |
| 9 | + - .docker/build.Dockerfile |
| 10 | + pull_request: |
| 11 | + branches: [ main, stable, oldstable ] |
| 12 | + paths: |
| 13 | + - .github/workflows/build-container.yml |
| 14 | + - .docker/build.Dockerfile |
| 15 | + workflow_dispatch: |
| 16 | + schedule: |
| 17 | + # rebuild image every sunday |
| 18 | + - cron: "0 0 * * 0" |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: Build Images |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v3 |
| 27 | + - name: Setup container meta information |
| 28 | + id: meta |
| 29 | + uses: docker/metadata-action@v4 |
| 30 | + with: |
| 31 | + images: ${{ github.repository }}-build |
| 32 | + labels: | |
| 33 | + org.opencontainers.image.vendor=Greenbone |
| 34 | + org.opencontainers.image.base.name=debian:stable-slim |
| 35 | + flavor: latest=false # no latest container tag for git tags |
| 36 | + tags: | |
| 37 | + # create container tag for git tags |
| 38 | + type=ref,event=tag |
| 39 | + type=ref,event=pr |
| 40 | + # use latest for stable branch |
| 41 | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} |
| 42 | + type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} |
| 43 | + type=raw,value=oldstable,enable=${{ github.ref == format('refs/heads/{0}', 'oldstable') }} |
| 44 | + # use unstable for main branch |
| 45 | + type=raw,value=unstable,enable={{is_default_branch}} |
| 46 | + - name: Set up QEMU |
| 47 | + uses: docker/setup-qemu-action@v2 |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v2 |
| 50 | + - name: Login to DockerHub |
| 51 | + if: github.event_name != 'pull_request' |
| 52 | + uses: docker/login-action@v2 |
| 53 | + with: |
| 54 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 55 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 56 | + - run: echo "Build and push ${{ steps.container.outputs.image-tags }}" |
| 57 | + - name: Build and push |
| 58 | + uses: docker/build-push-action@v3 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + push: ${{ github.event_name != 'pull_request' }} |
| 62 | + file: .docker/build.Dockerfile |
| 63 | + platforms: linux/amd64,linux/arm64 |
| 64 | + tags: ${{ steps.meta.outputs.tags }} |
| 65 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments