Skip to content

Commit 434e003

Browse files
committed
feat: add bake build and beta releases
1 parent 977b73b commit 434e003

File tree

9 files changed

+190
-75
lines changed

9 files changed

+190
-75
lines changed

.github/workflows/check-pr.yaml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313

1414
permissions:
1515
contents: read
16-
pull-requests: write
1716

1817
steps:
1918
- name: Checkout repository
@@ -34,27 +33,3 @@ jobs:
3433
working-directory: backend
3534
run: |
3635
task test-container
37-
38-
- name: Build backend image
39-
working-directory: backend
40-
run: |
41-
task image-build
42-
43-
- name: Scan backend image
44-
id: scan
45-
uses: ovsds/run-with-output-action@v1
46-
continue-on-error: true
47-
with:
48-
run: task backend:image-scan
49-
50-
- name: Report vulnerabilities
51-
uses: ovsds/create-or-update-unique-comment-action@v1
52-
with:
53-
issue-number: ${{ github.event.number }}
54-
body: |
55-
## Vulnerabilities found
56-
```
57-
${{ steps.scan.outputs.stdout }}
58-
```
59-
unique-body-includes: "## Vulnerabilities found"
60-
delete: ${{ steps.scan.outputs.exit_code == 0 }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 🧹 Release PR Cleanup
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * 0 # Every Sunday at 00:00 UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
release-pr-cleanup:
10+
runs-on: ubuntu-22.04
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- uses: ovsds/package-lifecycle-action@v1
18+
with:
19+
package-name: ${{ github.event.repository.name }}-beta
20+
expire-period-days: 7
21+
untagged: true
22+
retained-tagged-top: 1
23+
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release-pr.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
jobs:
11+
release-pr:
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
packages: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Environment
24+
uses: ./.github/actions/setup_environment
25+
with:
26+
with-python: "false"
27+
with-poetry: "false"
28+
29+
- name: Get Image Data
30+
id: get-image-data
31+
run: |
32+
echo "registry=ghcr.io/${{ github.repository_owner }}" >> $GITHUB_OUTPUT
33+
echo "name=${{ github.event.repository.name }}-beta" >> $GITHUB_OUTPUT
34+
echo "tag=${{ github.event.number }}-${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
35+
36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Configure Docker Builder
44+
run: task configure-builder
45+
46+
- name: Build backend images
47+
working-directory: backend
48+
env:
49+
IMAGE_REGISTRY: ${{ steps.get-image-data.outputs.registry }}
50+
IMAGE_NAME: ${{ steps.get-image-data.outputs.name }}
51+
IMAGE_TAG: ${{ steps.get-image-data.outputs.tag }}
52+
run: |
53+
task ci-image-push
54+
55+
- name: Scan backend image
56+
id: scan
57+
uses: ovsds/run-with-output-action@v1
58+
continue-on-error: true
59+
with:
60+
run: |
61+
IMAGE_REGISTRY="${{ steps.get-image-data.outputs.registry }}" \
62+
IMAGE_NAME="${{ steps.get-image-data.outputs.name }}" \
63+
IMAGE_TAG="${{ steps.get-image-data.outputs.tag }}" \
64+
task backend:ci-image-scan
65+
66+
- name: Report vulnerabilities
67+
uses: ovsds/create-or-update-unique-comment-action@v1
68+
with:
69+
issue-number: ${{ github.event.number }}
70+
body: |
71+
## Vulnerabilities found
72+
```
73+
${{ steps.scan.outputs.stdout }}
74+
```
75+
unique-body-includes: "## Vulnerabilities found"
76+
delete: ${{ steps.scan.outputs.exit_code == 0 }}

.github/workflows/release-scan.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
continue-on-error: true
3939
with:
4040
run: |
41-
task backend:ci-image-scan \
42-
IMAGE_REGISTRY="ghcr.io/${{ github.repository_owner }}" \
43-
IMAGE_NAME="${{ github.event.repository.name }}" \
44-
IMAGE_TAG="${{ steps.get_tag.outputs.release }}"
41+
IMAGE_REGISTRY="ghcr.io/${{ github.repository_owner }}" \
42+
IMAGE_NAME="${{ github.event.repository.name }}" \
43+
IMAGE_TAG="${{ steps.get_tag.outputs.release }}" \
44+
task backend:ci-image-scan
4545
4646
- name: Report vulnerabilities
4747
uses: ovsds/create-or-update-unique-issue-action@v1

.github/workflows/release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ jobs:
3030
username: ${{ github.actor }}
3131
password: ${{ secrets.GITHUB_TOKEN }}
3232

33+
- name: Configure Docker Builder
34+
run: task configure-builder
35+
3336
- name: Build backend images
3437
working-directory: backend
3538
env:
3639
IMAGE_TAG: ${{ github.event.release.tag_name }}
40+
IMAGE_NAME: ${{ github.event.repository.name }}
3741
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
3842
run: |
39-
task ci-image-build
4043
task ci-image-push

Taskfile.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ tasks:
134134
services='backend'
135135
vars:
136136
TEMPLATE_PATH: '{{.TEMPLATE_PATH | default "https://github.com/ovsds/template-repository"}}'
137+
138+
configure-builder:
139+
desc: Configure buildx for multi-arch builds
140+
cmds:
141+
- echo 'Configuring buildx...'
142+
- docker buildx create
143+
--driver docker-container
144+
--use

backend/Dockerfile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
ARG BASE_BUILDER_IMAGE=python:3.12.7-bookworm
2-
ARG BASE_RUNTIME_IMAGE=python:3.12.7-slim-bookworm
3-
4-
FROM ${BASE_BUILDER_IMAGE} AS builder
1+
FROM base_builder AS builder
52

63
RUN python -m pip install 'poetry>=1.7.0,<1.8.0'
74

85
RUN mkdir --parents /opt/app
9-
COPY pyproject.toml /opt/app/pyproject.toml
10-
COPY poetry.lock /opt/app/poetry.lock
11-
COPY poetry.toml /opt/app/poetry.toml
6+
COPY --from=sources pyproject.toml /opt/app/pyproject.toml
7+
COPY --from=sources poetry.lock /opt/app/poetry.lock
8+
COPY --from=sources poetry.toml /opt/app/poetry.toml
129

1310
WORKDIR /opt/app
1411
RUN poetry install
1512

16-
FROM ${BASE_RUNTIME_IMAGE} AS runtime
13+
FROM base_runtime AS runtime
1714

1815
RUN mkdir --parents /opt/app
1916
COPY --from=builder /opt/app/.venv /opt/app/.venv
20-
COPY bin /opt/app/bin
21-
COPY lib /opt/app/lib
17+
COPY --from=sources bin /opt/app/bin
18+
COPY --from=sources lib /opt/app/lib
2219

2320
WORKDIR /opt/app
2421
CMD [".venv/bin/python", "-m", "bin.main"]
@@ -27,18 +24,18 @@ FROM builder AS builder_dev
2724

2825
RUN poetry install --with dev
2926

30-
FROM ${BASE_RUNTIME_IMAGE} AS runtime_dev
27+
FROM base_runtime AS runtime_dev
3128

3229
RUN mkdir --parents /opt/app
3330
COPY --from=builder_dev /opt/app/.venv /opt/app/.venv
34-
COPY bin /opt/app/bin
35-
COPY lib /opt/app/lib
36-
COPY pyproject.toml /opt/app/pyproject.toml
31+
COPY --from=sources bin /opt/app/bin
32+
COPY --from=sources lib /opt/app/lib
33+
COPY --from=sources pyproject.toml /opt/app/pyproject.toml
3734

3835
WORKDIR /opt/app
3936

4037
FROM runtime_dev AS tests
4138

42-
COPY tests /opt/app/tests
39+
COPY --from=sources tests /opt/app/tests
4340

4441
CMD [".venv/bin/python", "-m", "pytest", "tests"]

backend/Taskfile.yaml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,9 @@ tasks:
114114
- echo 'Running pyright fixes...'
115115
- task: _pyright
116116

117-
image-build:
118-
desc: Build image target for local usage
117+
bake:
119118
cmds:
120-
- echo 'Building image {{.TARGET}} target...'
121-
- docker build
122-
--tag {{.IMAGE_NAME}}:{{.TARGET}}
123-
{{ if .TAG }}--tag {{.TAG}}{{ end }}
124-
--target {{.TARGET}}
125-
--load
126-
.
127-
vars:
128-
TARGET: '{{.TARGET | default "runtime"}}'
119+
- docker buildx bake {{.COMMAND}}
129120

130121
image-scan:
131122
desc: Scan image for vulnerabilities
@@ -146,8 +137,8 @@ tasks:
146137
test-container:
147138
desc: Run tests in container
148139
cmds:
149-
- task: image-build
150-
vars: { TARGET: tests }
140+
- task: bake
141+
vars: { COMMAND: tests_docker }
151142

152143
- echo 'Running tests...'
153144
- docker run
@@ -212,11 +203,13 @@ tasks:
212203
dev-server-start-container:
213204
desc: Start development application in container
214205
cmds:
215-
- task: image-build
216-
vars: { TARGET: runtime }
206+
- task: bake
207+
vars: { COMMAND: runtime_docker }
217208

218209
- echo 'Running container...'
219210
- docker run
211+
-e GITHUB_WATCHER_SETTINGS_YAML=example/settings.yaml
212+
-v $(pwd)/example:/opt/app/example
220213
{{.IMAGE_NAME}}:runtime
221214

222215
update-from-template:
@@ -234,27 +227,15 @@ tasks:
234227
vars:
235228
TEMPLATE_PATH: '{{.TEMPLATE_PATH | default "https://github.com/ovsds/template-service-python"}}'
236229

237-
ci-image-build:
238-
desc: Build image target for CI usage
239-
requires:
240-
vars:
241-
- IMAGE_TAG
242-
- IMAGE_REGISTRY
243-
cmds:
244-
- task: image-build
245-
vars:
246-
TARGET: runtime
247-
TAG: "{{.IMAGE_REGISTRY}}/{{.IMAGE_NAME}}:{{.IMAGE_TAG}}"
248-
249230
ci-image-push:
250231
desc: Push image to registry for CI usage
251232
requires:
252233
vars:
253234
- IMAGE_TAG
254235
- IMAGE_REGISTRY
255236
cmds:
256-
- echo 'Uploading backend image...'
257-
- docker push {{.IMAGE_REGISTRY}}/{{.IMAGE_NAME}}:{{.IMAGE_TAG}}
237+
- task: bake
238+
vars: { COMMAND: runtime }
258239

259240
ci-image-scan:
260241
desc: Scan image for vulnerabilities
@@ -263,7 +244,6 @@ tasks:
263244
- IMAGE_TAG
264245
- IMAGE_REGISTRY
265246
cmds:
266-
- echo 'Scanning image for vulnerabilities...'
267247
- trivy image
268248
--config trivy.yaml
269249
{{.IMAGE_REGISTRY}}/{{.IMAGE_NAME}}:{{.IMAGE_TAG}}

backend/docker-bake.hcl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
variable "IMAGE_REGISTRY" {}
2+
variable "IMAGE_NAME" { default = "github-watcher" }
3+
variable "IMAGE_TAG" {}
4+
variable "PLATFORMS" {
5+
default = [
6+
"linux/amd64",
7+
"linux/arm64",
8+
]
9+
}
10+
variable "LABELS" {
11+
default = [
12+
"org.opencontainers.image.source=http://github.com/ovsds/github-watcher",
13+
"org.opencontainers.image.description=GitHub Watcher",
14+
"org.opencontainers.image.licenses=MIT",
15+
]
16+
}
17+
18+
target "base" {
19+
dockerfile = "Dockerfile"
20+
contexts = {
21+
"base_builder" = "docker-image://docker.io/library/python:3.12.7-bookworm"
22+
"base_runtime" = "docker-image://docker.io/library/python:3.12.7-slim-bookworm"
23+
"sources" = "."
24+
}
25+
labels = LABELS
26+
}
27+
28+
target "runtime" {
29+
inherits = ["base"]
30+
target = "runtime"
31+
tags = ["${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"]
32+
output = ["type=image,push=true"]
33+
platforms = PLATFORMS
34+
attest = [
35+
"type=provenance,mode=max",
36+
"type=sbom",
37+
]
38+
}
39+
40+
target "runtime_docker" {
41+
inherits = ["base"]
42+
target = "runtime"
43+
output = ["type=docker"]
44+
tags = ["${IMAGE_NAME}:runtime"]
45+
}
46+
47+
target "tests_docker" {
48+
inherits = ["base"]
49+
output = ["type=docker"]
50+
tags = ["${IMAGE_NAME}:tests"]
51+
target = "tests"
52+
}
53+

0 commit comments

Comments
 (0)