Skip to content

Commit df13d5b

Browse files
committed
Change: Split building build and production container images
The build image really rarely needs a rebuild. Therefore split this job into an own workflow and only rebuild if the corresponding dockerfile or workflow has changed.
1 parent 3145e06 commit df13d5b

File tree

2 files changed

+66
-48
lines changed

2 files changed

+66
-48
lines changed

.github/workflows/build-container.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 }}

.github/workflows/container.yml

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,9 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
build:
13-
name: Build Images
14-
runs-on: ubuntu-latest
15-
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v3
18-
- name: Setup container meta information
19-
id: meta
20-
uses: docker/metadata-action@v4
21-
with:
22-
images: ${{ github.repository }}-build
23-
labels: |
24-
org.opencontainers.image.vendor=Greenbone
25-
org.opencontainers.image.base.name=debian/stable-slim
26-
flavor: latest=false # no latest container tag for git tags
27-
tags: |
28-
# create container tag for git tags
29-
type=ref,event=tag
30-
type=ref,event=pr
31-
# use latest for stable branch
32-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
33-
type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
34-
type=raw,value=oldstable,enable=${{ github.ref == format('refs/heads/{0}', 'oldstable') }}
35-
# use unstable for main branch
36-
type=raw,value=unstable,enable={{is_default_branch}}
37-
- name: Set up QEMU
38-
uses: docker/setup-qemu-action@v2
39-
- name: Set up Docker Buildx
40-
uses: docker/setup-buildx-action@v2
41-
- name: Login to DockerHub
42-
if: github.event_name != 'pull_request'
43-
uses: docker/login-action@v2
44-
with:
45-
username: ${{ secrets.DOCKERHUB_USERNAME }}
46-
password: ${{ secrets.DOCKERHUB_TOKEN }}
47-
- run: echo "Build and push ${{ steps.container.outputs.image-tags }}"
48-
- name: Build and push
49-
uses: docker/build-push-action@v3
50-
with:
51-
context: .
52-
push: ${{ github.event_name != 'pull_request' }}
53-
file: .docker/build.Dockerfile
54-
platforms: linux/amd64,linux/arm64
55-
tags: ${{ steps.meta.outputs.tags }}
56-
labels: ${{ steps.meta.outputs.labels }}
57-
5812
production:
5913
name: Production Images
6014
runs-on: ubuntu-latest
61-
needs: build
6215
steps:
6316
- name: Checkout repository
6417
uses: actions/checkout@v3
@@ -69,7 +22,7 @@ jobs:
6922
images: ${{ github.repository }}
7023
labels: |
7124
org.opencontainers.image.vendor=Greenbone
72-
org.opencontainers.image.base.name=debian/stable-slim
25+
org.opencontainers.image.base.name=debian:stable-slim
7326
flavor: latest=false # no latest container tag for git tags
7427
tags: |
7528
# create container tag for git tags

0 commit comments

Comments
 (0)