Skip to content

Update ci #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 55 additions & 23 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,88 @@ name: CI Pipeline
on:
push:
branches: [ "main" ]
####### Uncomment this to test the CI pipeline in a PR
####### You'll also need to comment the rules containing {{branch}}
####### in the `Extract Docker metadata` step
# pull_request:
# branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
REGISTRY_PATH: ${{ github.repository }}
TEST_TAG: user/app:test

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

# This might be unnecessary as tests are not
# multiplatform
- name: Setup Docker buildx
uses: docker/[email protected]

# Build but don't push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build test image
id: build-test
uses: docker/[email protected]
with:
context: .
load: true
target: dev
tags: ${{ env.TEST_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

# This is a barrier check to make sure we push a functional
# docker image, we can avoid linting
- name: Run tests in the test image
run: |
docker run --rm ${{ env.TEST_TAG }} make ci-test

build:
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

strategy:
matrix:
docker_target:
- http
- socketio
- dramatiq
steps:
# GitHub gives only repository complete in <owner>/<repo> format.
# Need some manual sheanigans
# Set IMAGE_NAME so we can push to <owner>/<repo>/<image>
- name: Set ENV variables
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV

- name: Checkout repository
uses: actions/checkout@v4

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

# Install the cosign tool except on PR
# Install the cosign tool
# https://github.com/sigstore/cosign-installer
- name: Install cosign
uses: sigstore/[email protected]

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

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

# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build test image
id: build-test
uses: docker/[email protected]
with:
context: .
load: true
target: dev
tags: ${{ env.TEST_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test
run: |
docker run --rm ${{ env.TEST_TAG }} make ci-test

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
# list of Docker images to use as base name for tags
# <registry/<owner>/<repo_name>/<repo_name>-<target>
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}/${{ env.IMAGE_NAME }}-${{ matrix.docker_target }}
# generate Docker tags based on the following events/attributes
tags: |
type=sha
Expand All @@ -89,7 +121,7 @@ jobs:
uses: docker/[email protected]
with:
context: .
target: http_app
target: ${{ matrix.docker_target }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
4 changes: 2 additions & 2 deletions .gitlab_ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build-http-app-amd64:
variables:
DOCKER_IMAGE_NAME: $CI_PROJECT_NAME-http
DOCKER_PLATFORM: "linux/amd64"
DOCKER_TARGET: http_app
DOCKER_TARGET: http
tags:
- saas-linux-small-amd64
rules:
Expand All @@ -32,7 +32,7 @@ build-http-app-arm64:
variables:
DOCKER_IMAGE_NAME: $CI_PROJECT_NAME-http
DOCKER_PLATFORM: "linux/arm64"
DOCKER_TARGET: http_app
DOCKER_TARGET: http
tags:
- saas-linux-small-arm64
rules:
Expand Down
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,30 @@ RUN --mount=type=cache,target=~/.cache/uv \
# Create the base app with the common python packages
FROM base AS base_app
USER nonroot
COPY --chown=nonroot:nonroot src/migrations ./migrations
COPY --chown=nonroot:nonroot src/common ./common
COPY --chown=nonroot:nonroot src/domains ./domains
COPY --chown=nonroot:nonroot src/gateways ./gateways
COPY --chown=nonroot:nonroot src/common ./common
COPY --chown=nonroot:nonroot src/migrations ./migrations
COPY --chown=nonroot:nonroot src/alembic.ini .

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

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

# Copy the dramatiq python package and requirements from relevant builder
FROM base_app AS dramatiq_app
FROM base_app AS dramatiq
COPY --from=dramatiq_builder /venv /venv
COPY --chown=nonroot:nonroot src/dramatiq_worker ./dramatiq_worker
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
# Run CMD using array syntax, so it uses `exec` and runs as PID1
# TODO: Review processes/threads
CMD ["opentelemetry-instrument", "dramatiq", "-p", "1", "-t", "1", "dramatiq_worker"]
3 changes: 0 additions & 3 deletions tests/socketio_app/namespaces/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def chat_namespace():
return ChatNamespace("/chat")


@pytest.mark.asyncio
async def test_on_connect(chat_namespace):
sid = "test_session_id"
environ = {}
Expand All @@ -19,7 +18,6 @@ async def test_on_connect(chat_namespace):
chat_namespace.on_connect(sid, environ)


@pytest.mark.asyncio
async def test_on_disconnect(chat_namespace):
sid = "test_session_id"
reason = "test_reason"
Expand All @@ -28,7 +26,6 @@ async def test_on_disconnect(chat_namespace):
chat_namespace.on_disconnect(sid, reason)


@pytest.mark.asyncio
async def test_on_echo_message(chat_namespace):
sid = "test_session_id"
test_data = {"message": "Hello, World!"}
Expand Down