Skip to content

Commit b8d651a

Browse files
committed
Add GHCR container CI
1 parent ae9f79b commit b8d651a

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

.github/workflows/container.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Energy Tracker CI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'energy-tracker-*'
7+
paths:
8+
- '**'
9+
- '.github/workflows/container.yml'
10+
pull_request:
11+
paths:
12+
- '**'
13+
- '.github/workflows/container.yml'
14+
15+
defaults:
16+
run:
17+
working-directory: .
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.13'
30+
31+
- name: Compile check
32+
run: |
33+
python -m compileall octopus_agile_tracker
34+
35+
- name: Unit tests
36+
run: python -m unittest discover -s tests -v
37+
38+
publish:
39+
runs-on: ubuntu-latest
40+
needs: test
41+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/energy-tracker-')
42+
permissions:
43+
contents: read
44+
packages: write
45+
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
50+
- name: Set up QEMU
51+
uses: docker/setup-qemu-action@v3
52+
53+
- name: Set up Docker Buildx
54+
uses: docker/setup-buildx-action@v3
55+
56+
- name: Log in to GHCR
57+
uses: docker/login-action@v3
58+
with:
59+
registry: ghcr.io
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Compute image tag
64+
id: image_tag
65+
run: |
66+
ref="${GITHUB_REF_NAME}"
67+
ver="${ref#energy-tracker-}"
68+
ver="${ver#v}"
69+
owner="${GITHUB_REPOSITORY_OWNER,,}"
70+
echo "version=${ver}" >> "$GITHUB_OUTPUT"
71+
echo "owner=${owner}" >> "$GITHUB_OUTPUT"
72+
73+
- name: Build and push
74+
uses: docker/build-push-action@v5
75+
with:
76+
context: .
77+
file: ./Dockerfile
78+
build-args: |
79+
ENERGY_TRACKER_VERSION=${{ steps.image_tag.outputs.version }}
80+
push: true
81+
platforms: linux/amd64,linux/arm64
82+
tags: |
83+
ghcr.io/${{ steps.image_tag.outputs.owner }}/energy-tracker:${{ steps.image_tag.outputs.version }}
84+
ghcr.io/${{ steps.image_tag.outputs.owner }}/energy-tracker:latest
85+
cache-from: type=gha,scope=energy-tracker
86+
cache-to: type=gha,mode=max,scope=energy-tracker

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# syntax=docker/dockerfile:1.7
22
FROM python:3.13-slim
33

4+
ARG ENERGY_TRACKER_VERSION="unknown"
45
ENV PYTHONUNBUFFERED=1
6+
ENV ENERGY_TRACKER_VERSION=${ENERGY_TRACKER_VERSION}
57
WORKDIR /app
68

79
COPY octopus_agile_tracker /app/octopus_agile_tracker
810

911
USER nobody
1012
ENTRYPOINT ["python", "-m", "octopus_agile_tracker.main"]
11-

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ docker run --rm \
6666
energy-tracker:dev
6767
```
6868

69+
Version tags in the form `energy-tracker-<version>` are built by GitHub Actions
70+
and pushed to:
71+
72+
```text
73+
ghcr.io/clythershackers/energy-tracker
74+
```

0 commit comments

Comments
 (0)