Skip to content

Commit b3aa9d8

Browse files
ci: add container build workflow for main and development
- Trigger on main and development so Docker builds pick up fixes before merge - development pushes ghcr tags :development and :vVERSION-development (not :latest) - Replace poetry lock with poetry check --lock for reproducible CI Co-authored-by: Christian <ChrisCoder9000@users.noreply.github.com>
1 parent 6608555 commit b3aa9d8

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and Push Container
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- development
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
packages: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.11"
24+
25+
- name: Install Poetry
26+
run: pip install poetry==2.1.3
27+
28+
- name: Verify lockfile matches pyproject.toml
29+
run: poetry check --lock
30+
31+
- name: Get version
32+
id: version
33+
run: echo "VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')" >> $GITHUB_OUTPUT
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Log in to GitHub Container Registry
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GHCR_TOKEN }}
44+
45+
- name: Build and push Docker image (main)
46+
if: github.ref == 'refs/heads/main'
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
platforms: linux/amd64
51+
push: true
52+
tags: |
53+
ghcr.io/lumen-labs/brainapi:v${{ steps.version.outputs.VERSION }}
54+
ghcr.io/lumen-labs/brainapi:latest
55+
build-args: |
56+
BUILD_DATE=${{ github.event.head_commit.timestamp }}
57+
BUILD_SHA=${{ github.sha }}
58+
CACHE_BUST=${{ github.run_number }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
61+
62+
- name: Build and push Docker image (development)
63+
if: github.ref == 'refs/heads/development'
64+
uses: docker/build-push-action@v5
65+
with:
66+
context: .
67+
platforms: linux/amd64
68+
push: true
69+
tags: |
70+
ghcr.io/lumen-labs/brainapi:development
71+
ghcr.io/lumen-labs/brainapi:v${{ steps.version.outputs.VERSION }}-development
72+
build-args: |
73+
BUILD_DATE=${{ github.event.head_commit.timestamp }}
74+
BUILD_SHA=${{ github.sha }}
75+
CACHE_BUST=${{ github.run_number }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max
78+
79+
- name: Create Git tag (only on main branch)
80+
if: github.ref == 'refs/heads/main'
81+
run: |
82+
git config --local user.email "action@github.com"
83+
git config --local user.name "GitHub Action"
84+
git tag -a v${{ steps.version.outputs.VERSION }} -m "Release v${{ steps.version.outputs.VERSION }}"
85+
git push origin v${{ steps.version.outputs.VERSION }}

0 commit comments

Comments
 (0)