Skip to content

Commit a8989f2

Browse files
authored
Actions: Add docker build and push (#666)
1 parent e112e32 commit a8989f2

File tree

3 files changed

+110
-11
lines changed

3 files changed

+110
-11
lines changed

.github/workflows/docker.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions: {}
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
name: Build and push dev image
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read # required to read the repository contents
21+
packages: write # required to push the built image to the package registry
22+
attestations: write # required to create attestations for the built image
23+
id-token: write # required to create attestations for the built image
24+
pull-requests: write # required to comment on the pull request
25+
steps:
26+
- name: Create image tag
27+
id: image_tag
28+
shell: bash
29+
env:
30+
REPOSITORY: ${{ github.repository }}
31+
REF_NAME: ${{ github.ref_name }}
32+
COMMIT: ${{ github.sha }}
33+
run: |
34+
set -euo pipefail
35+
TAG="$(echo -n "dev-$REF_NAME-$COMMIT" | tr '[:upper:]' '[:lower:]' | tr -d '[:blank:]' | tr -c '[:alnum:]' '-')"
36+
echo "image tag: $TAG"
37+
echo "tag=ghcr.io/$REPOSITORY:$TAG" >> "$GITHUB_OUTPUT"
38+
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
39+
with:
40+
driver-opts: env.BUILDKIT_STEP_LOG_MAX_SIZE=-1,env.BUILDKIT_STEP_LOG_MAX_SPEED=-1
41+
- name: Log into GHCR
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
ACTOR: ${{ github.actor }}
45+
run: echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin
46+
- name: docker build & push
47+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
48+
with:
49+
push: true
50+
tags: ${{ steps.image_tag.outputs.tag }}
51+
provenance: mode=max
52+
sbom: true
53+
- name: Comment on PR
54+
if: github.event_name == 'pull_request'
55+
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
56+
continue-on-error: true # just check the actions log if ratelimits or whatever
57+
with:
58+
message: |
59+
:whale: Docker image built and pushed to GitHub Container Registry.
60+
61+
You can pull it using:
62+
63+
```bash
64+
docker pull ${{ steps.image_tag.outputs.tag }}
65+
```
66+
67+
> [!WARNING]
68+
> This is a development image and should not be used in production.
69+
> It will be automatically removed after 2 weeks.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: GHCR Clean-up
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "25 2 * * *" # every day at 02:25 UTC
7+
8+
permissions: {}
9+
10+
jobs:
11+
clean:
12+
runs-on: ubuntu-latest
13+
name: Delete old test images
14+
permissions:
15+
packages: write # required to delete images from the package registry
16+
steps:
17+
- uses: snok/container-retention-policy@4f22ef80902ad409ed55a99dc5133cc1250a0d03 # v3.0.0
18+
id: retention
19+
with:
20+
account: grafana
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
image-names: "grafana-image-renderer"
23+
image-tags: "dev*"
24+
cut-off: 2w
25+
dry-run: false
26+
- name: Summary
27+
uses: actions/github-script@v7
28+
if: success() || failure()
29+
env:
30+
LIST: ${{ steps.retention.outputs.deleted }}
31+
FAILED: ${{ steps.retention.outputs.failed }}
32+
with:
33+
script: |
34+
const list = process.env.LIST.split(',').filter(Boolean);
35+
const failed = process.env.FAILED.split(',').filter(Boolean);
36+
await core.summary.addHeading('GHCR Clean-up')
37+
.addRaw(`Deleted images: ${list.length}`, true)
38+
.addList(list)
39+
.addRaw(`Failed to delete images: ${failed.length}`, true)
40+
.addList(failed)
41+
.write();

.github/workflows/test.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,3 @@ jobs:
6363

6464
- run: yarn install --frozen-lockfile
6565
- run: yarn run prettier:check
66-
67-
docker:
68-
name: Build Docker image
69-
runs-on: ubuntu-latest
70-
permissions:
71-
contents: read # clone the repository
72-
steps:
73-
- uses: actions/checkout@v4
74-
with:
75-
persist-credentials: false
76-
- run: docker build .

0 commit comments

Comments
 (0)