Skip to content

Commit da5fd4a

Browse files
authored
Update ci (#251)
* Split test and build steps (preparation for matrix build) * Temporary run ci pipeline in PR * Temporary disable branch in tags * Matrix build all targets * Fix typo * Comments * Remove pytest marks * Try manual image name * Rename dockerfile targets * Rearrange COPY in alphabetical order * Run back CI only on main
1 parent 674cde5 commit da5fd4a

File tree

4 files changed

+66
-37
lines changed

4 files changed

+66
-37
lines changed

.github/workflows/ci-pipeline.yml

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,88 @@ name: CI Pipeline
88
on:
99
push:
1010
branches: [ "main" ]
11+
####### Uncomment this to test the CI pipeline in a PR
12+
####### You'll also need to comment the rules containing {{branch}}
13+
####### in the `Extract Docker metadata` step
14+
# pull_request:
15+
# branches: [ "main" ]
1116

1217
env:
1318
# Use docker.io for Docker Hub if empty
1419
REGISTRY: ghcr.io
1520
# github.repository as <account>/<repo>
16-
IMAGE_NAME: ${{ github.repository }}
21+
REGISTRY_PATH: ${{ github.repository }}
1722
TEST_TAG: user/app:test
1823

1924
jobs:
25+
test:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
# This might be unnecessary as tests are not
32+
# multiplatform
33+
- name: Setup Docker buildx
34+
uses: docker/[email protected]
35+
36+
# Build but don't push Docker image with Buildx
37+
# https://github.com/docker/build-push-action
38+
- name: Build test image
39+
id: build-test
40+
uses: docker/[email protected]
41+
with:
42+
context: .
43+
load: true
44+
target: dev
45+
tags: ${{ env.TEST_TAG }}
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max
48+
49+
# This is a barrier check to make sure we push a functional
50+
# docker image, we can avoid linting
51+
- name: Run tests in the test image
52+
run: |
53+
docker run --rm ${{ env.TEST_TAG }} make ci-test
54+
2055
build:
2156
runs-on: ubuntu-latest
57+
needs: test
2258
permissions:
2359
contents: read
2460
packages: write
2561
# This is used to complete the identity challenge
2662
# with sigstore/fulcio when running outside of PRs.
2763
id-token: write
28-
64+
strategy:
65+
matrix:
66+
docker_target:
67+
- http
68+
- socketio
69+
- dramatiq
2970
steps:
71+
# GitHub gives only repository complete in <owner>/<repo> format.
72+
# Need some manual sheanigans
73+
# Set IMAGE_NAME so we can push to <owner>/<repo>/<image>
74+
- name: Set ENV variables
75+
run: |
76+
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
77+
3078
- name: Checkout repository
3179
uses: actions/checkout@v4
3280

3381
- name: Set up QEMU
3482
uses: docker/setup-qemu-action@v3
3583

36-
# Install the cosign tool except on PR
84+
# Install the cosign tool
3785
# https://github.com/sigstore/cosign-installer
3886
- name: Install cosign
3987
uses: sigstore/[email protected]
4088

4189
- name: Setup Docker buildx
4290
uses: docker/[email protected]
4391

44-
# Login against a Docker registry except on PR
92+
# Login against a Docker registry
4593
# https://github.com/docker/login-action
4694
- name: Log into registry ${{ env.REGISTRY }}
4795
uses: docker/[email protected]
@@ -50,32 +98,16 @@ jobs:
5098
username: ${{ github.actor }}
5199
password: ${{ secrets.GITHUB_TOKEN }}
52100

53-
# Build and push Docker image with Buildx
54-
# https://github.com/docker/build-push-action
55-
- name: Build test image
56-
id: build-test
57-
uses: docker/[email protected]
58-
with:
59-
context: .
60-
load: true
61-
target: dev
62-
tags: ${{ env.TEST_TAG }}
63-
cache-from: type=gha
64-
cache-to: type=gha,mode=max
65-
66-
- name: Test
67-
run: |
68-
docker run --rm ${{ env.TEST_TAG }} make ci-test
69-
70101
# Extract metadata (tags, labels) for Docker
71102
# https://github.com/docker/metadata-action
72103
- name: Extract Docker metadata
73104
id: meta
74105
uses: docker/[email protected]
75106
with:
76107
# list of Docker images to use as base name for tags
108+
# <registry/<owner>/<repo_name>/<repo_name>-<target>
77109
images: |
78-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
110+
${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}/${{ env.IMAGE_NAME }}-${{ matrix.docker_target }}
79111
# generate Docker tags based on the following events/attributes
80112
tags: |
81113
type=sha
@@ -89,7 +121,7 @@ jobs:
89121
uses: docker/[email protected]
90122
with:
91123
context: .
92-
target: http_app
124+
target: ${{ matrix.docker_target }}
93125
platforms: linux/amd64,linux/arm64
94126
push: true
95127
tags: ${{ steps.meta.outputs.tags }}

.gitlab_ci/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build-http-app-amd64:
1717
variables:
1818
DOCKER_IMAGE_NAME: $CI_PROJECT_NAME-http
1919
DOCKER_PLATFORM: "linux/amd64"
20-
DOCKER_TARGET: http_app
20+
DOCKER_TARGET: http
2121
tags:
2222
- saas-linux-small-amd64
2323
rules:
@@ -32,7 +32,7 @@ build-http-app-arm64:
3232
variables:
3333
DOCKER_IMAGE_NAME: $CI_PROJECT_NAME-http
3434
DOCKER_PLATFORM: "linux/arm64"
35-
DOCKER_TARGET: http_app
35+
DOCKER_TARGET: http
3636
tags:
3737
- saas-linux-small-arm64
3838
rules:

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,30 @@ RUN --mount=type=cache,target=~/.cache/uv \
6969
# Create the base app with the common python packages
7070
FROM base AS base_app
7171
USER nonroot
72-
COPY --chown=nonroot:nonroot src/migrations ./migrations
72+
COPY --chown=nonroot:nonroot src/common ./common
7373
COPY --chown=nonroot:nonroot src/domains ./domains
7474
COPY --chown=nonroot:nonroot src/gateways ./gateways
75-
COPY --chown=nonroot:nonroot src/common ./common
75+
COPY --chown=nonroot:nonroot src/migrations ./migrations
7676
COPY --chown=nonroot:nonroot src/alembic.ini .
7777

7878
# Copy the http python package and requirements from relevant builder
79-
FROM base_app AS http_app
79+
FROM base_app AS http
8080
COPY --from=http_builder /venv /venv
8181
COPY --chown=nonroot:nonroot src/http_app ./http_app
82-
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
82+
# Run CMD using array syntax, so it uses `exec` and runs as PID1
8383
CMD ["opentelemetry-instrument", "python", "-m", "http_app"]
8484

8585
# Copy the socketio python package and requirements from relevant builder
86-
FROM base_app AS socketio_app
87-
COPY --from=socketio_builder_builder /venv /venv
86+
FROM base_app AS socketio
87+
COPY --from=socketio_builder /venv /venv
8888
COPY --chown=nonroot:nonroot src/socketio_app ./socketio_app
89-
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
89+
# Run CMD using array syntax, so it uses `exec` and runs as PID1
9090
CMD ["opentelemetry-instrument", "python", "-m", "socketio_app"]
9191

9292
# Copy the dramatiq python package and requirements from relevant builder
93-
FROM base_app AS dramatiq_app
93+
FROM base_app AS dramatiq
9494
COPY --from=dramatiq_builder /venv /venv
9595
COPY --chown=nonroot:nonroot src/dramatiq_worker ./dramatiq_worker
96-
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
96+
# Run CMD using array syntax, so it uses `exec` and runs as PID1
9797
# TODO: Review processes/threads
9898
CMD ["opentelemetry-instrument", "dramatiq", "-p", "1", "-t", "1", "dramatiq_worker"]

tests/socketio_app/namespaces/test_chat.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def chat_namespace():
1010
return ChatNamespace("/chat")
1111

1212

13-
@pytest.mark.asyncio
1413
async def test_on_connect(chat_namespace):
1514
sid = "test_session_id"
1615
environ = {}
@@ -19,7 +18,6 @@ async def test_on_connect(chat_namespace):
1918
chat_namespace.on_connect(sid, environ)
2019

2120

22-
@pytest.mark.asyncio
2321
async def test_on_disconnect(chat_namespace):
2422
sid = "test_session_id"
2523
reason = "test_reason"
@@ -28,7 +26,6 @@ async def test_on_disconnect(chat_namespace):
2826
chat_namespace.on_disconnect(sid, reason)
2927

3028

31-
@pytest.mark.asyncio
3229
async def test_on_echo_message(chat_namespace):
3330
sid = "test_session_id"
3431
test_data = {"message": "Hello, World!"}

0 commit comments

Comments
 (0)