Skip to content

Commit ee19398

Browse files
authored
Merge pull request #61 from febus982/ci_pipeline
Add CI pipeline
2 parents b046d17 + cd4fc98 commit ee19398

File tree

3 files changed

+117
-8
lines changed

3 files changed

+117
-8
lines changed

.github/workflows/ci-pipeline.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: CI Pipeline
2+
3+
# This workflow build and run tests inside the dev container
4+
# only after the pull request is merged to main branch.
5+
# Once tests are successful it builds and pushes the
6+
# smaller size production image with multiarch suppport.
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
12+
env:
13+
# Use docker.io for Docker Hub if empty
14+
REGISTRY: ghcr.io
15+
# github.repository as <account>/<repo>
16+
IMAGE_NAME: ${{ github.repository }}
17+
TEST_TAG: user/app:test
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
# This is used to complete the identity challenge
26+
# with sigstore/fulcio when running outside of PRs.
27+
id-token: write
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v3
32+
33+
- name: Set up QEMU
34+
uses: docker/setup-qemu-action@v2
35+
36+
# Install the cosign tool except on PR
37+
# https://github.com/sigstore/cosign-installer
38+
- name: Install cosign
39+
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
40+
with:
41+
cosign-release: 'v2.1.1'
42+
43+
# Workaround: https://github.com/docker/build-push-action/issues/461
44+
- name: Setup Docker buildx
45+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
46+
47+
# Login against a Docker registry except on PR
48+
# https://github.com/docker/login-action
49+
- name: Log into registry ${{ env.REGISTRY }}
50+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
# Build and push Docker image with Buildx
57+
# https://github.com/docker/build-push-action
58+
- name: Build test image
59+
id: build-test
60+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
61+
with:
62+
context: .
63+
load: true
64+
target: dev
65+
tags: ${{ env.TEST_TAG }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
69+
- name: Test
70+
run: |
71+
docker run --rm ${{ env.TEST_TAG }} make ci-test
72+
73+
# Extract metadata (tags, labels) for Docker
74+
# https://github.com/docker/metadata-action
75+
- name: Extract Docker metadata
76+
id: meta
77+
uses: docker/metadata-action@v4
78+
with:
79+
# list of Docker images to use as base name for tags
80+
images: |
81+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
82+
# generate Docker tags based on the following events/attributes
83+
tags: |
84+
type=sha
85+
type=raw,value={{branch}}-latest
86+
type=raw,value={{branch}}-{{date 'YYYYMMDDHHmmss'}}
87+
88+
# Build and push Docker image with Buildx
89+
# https://github.com/docker/build-push-action
90+
- name: Build and push production image
91+
id: build-and-push
92+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
93+
with:
94+
context: .
95+
target: http_app
96+
platforms: linux/amd64,linux/arm64
97+
push: true
98+
tags: ${{ steps.meta.outputs.tags }}
99+
labels: ${{ steps.meta.outputs.labels }}
100+
cache-from: type=gha
101+
cache-to: type=gha,mode=max
102+
103+
# Sign the resulting Docker image digest except on PRs.
104+
# This will only write to the public Rekor transparency log when the Docker
105+
# repository is public to avoid leaking data. If you would like to publish
106+
# transparency data even for private images, pass --force to cosign below.
107+
# https://github.com/sigstore/cosign
108+
- name: Sign the published Docker image
109+
env:
110+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
111+
TAGS: ${{ steps.meta.outputs.tags }}
112+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
113+
# This step uses the identity token to provision an ephemeral certificate
114+
# against the sigstore community Fulcio instance.
115+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Bootstrap python service
2+
[![CI Pipeline](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/ci-pipeline.yml/badge.svg)](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/ci-pipeline.yml)
23
[![Python 3.9](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.9.yml/badge.svg?event=push)](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.9.yml)
34
[![Python 3.10](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.10.yml/badge.svg?event=push)](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.10.yml)
45
[![Python 3.11](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.11.yml/badge.svg?event=push)](https://github.com/febus982/bootstrap-python-fastapi/actions/workflows/python-3.11.yml)

tests/storage/conftest.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
from collections.abc import AsyncIterator
3-
from uuid import uuid4
42

53
import pytest
64
from sqlalchemy.orm import clear_mappers
@@ -11,11 +9,10 @@
119

1210
@pytest.fixture(scope="function")
1311
async def test_sa_manager() -> AsyncIterator[SQLAlchemyBindManager]:
14-
test_db_path = f"./{uuid4()}.db"
1512
clear_mappers()
1613

1714
db_config = SQLAlchemyAsyncConfig(
18-
engine_url=f"sqlite+aiosqlite:///{test_db_path}",
15+
engine_url="sqlite+aiosqlite://",
1916
engine_options=dict(connect_args={"check_same_thread": False}),
2017
)
2118
sa_manager = SQLAlchemyBindManager(config=db_config)
@@ -25,8 +22,4 @@ async def test_sa_manager() -> AsyncIterator[SQLAlchemyBindManager]:
2522
await conn.run_sync(v.registry_mapper.metadata.create_all)
2623

2724
yield sa_manager
28-
try:
29-
os.unlink(test_db_path)
30-
except FileNotFoundError:
31-
pass
3225
clear_mappers()

0 commit comments

Comments
 (0)