Repository navigation
Expand file tree
/
Copy pathconfig.yml
More file actions
184 lines (178 loc) · 7.51 KB
/
Copy pathconfig.yml
File metadata and controls
184 lines (178 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
version: 2.1
parameters:
python-version:
type: string
default: "3.14"
publish-branch:
type: string
default: "main"
docker-registry-host:
type: string
default: "registry.gitlab.com"
docker-repo-tabular:
type: string
default: "registry.gitlab.com/etalab/data.gouv.fr/infra/tabular-api"
docker-repo-metrics:
type: string
default: "registry.gitlab.com/etalab/data.gouv.fr/infra/metrics-api"
jobs:
lint:
docker:
- image: ghcr.io/astral-sh/uv:python<< pipeline.parameters.python-version >>-trixie
steps:
- checkout
- run:
name: Install Python dependencies
command: uv sync --frozen
- run:
name: Lint and format code and sort imports
# ruff check --extend-select I . : check linting and imports sorting without fixing (to fix, use --fix)
# ruff format --check . : check code formatting without fixing (to fix, remove --check)
command: |
uv run ruff check --extend-select I .
uv run ruff format --check .
- run:
name: Type check
command: uv run ty check
tests:
machine:
image: ubuntu-2404:current # Machine executor needed to run Docker containers (PostgreSQL + PostgREST)
steps:
- checkout
- run:
name: Start test containers
command: |
docker compose --profile test up -d
- run:
name: Wait for PostgreSQL to be ready
command: |
# Wait for PostgreSQL to be ready to accept connections
timeout 60 bash -c 'until docker compose exec -T postgres-test pg_isready -U csvapi; do sleep 2; done'
- run:
name: Wait for PostgREST to be ready
command: |
# Wait for PostgREST to be ready
timeout 30 bash -c 'until curl -f http://localhost:8080/ > /dev/null 2>&1; do sleep 2; done'
- run:
name: Install uv and dependencies and dev dependencies
command: |
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
uv python install << pipeline.parameters.python-version >>
uv sync --frozen
- run:
name: Run tests
command: |
export PATH="$HOME/.local/bin:$PATH"
uv run pytest --junitxml=reports/python/tests.xml -p no:sugar --color=yes
- store_test_results:
path: reports/python
build:
machine:
image: ubuntu-2404:current
steps:
- checkout
- run:
name: Install uv and Python << pipeline.parameters.python-version >>
command: |
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
uv python install << pipeline.parameters.python-version >>
uv sync --frozen
- run:
name: Compute RELEASE_VERSION via setuptools_scm, and build wheel
command: |
export PATH="$HOME/.local/bin:$PATH"
uv pip install --system setuptools-scm
# derive from setuptools_scm or base version + build number
RELEASE_VERSION=$(python -m setuptools_scm)
echo "Building a wheel release with version $RELEASE_VERSION"
echo "Build number: $CIRCLE_BUILD_NUM"
echo "Commit hash: ${CIRCLE_SHA1:0:7}"
echo "Git tag: $CIRCLE_TAG"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$BASH_ENV"
uv build --wheel
- store_artifacts:
path: dist
- persist_to_workspace:
root: .
paths:
- dist
- pyproject.toml
- run:
name: Log in to Docker registry
command: |
echo "${DOCKER_REGISTRY_PASSWORD}" | docker login -u "oauth2" --password-stdin << pipeline.parameters.docker-registry-host >>
- run:
name: Build and push Docker images (Tabular API and Metrics API)
command: |
source "$BASH_ENV"
export PATH="$HOME/.local/bin:$PATH"
# Five distinct tags per image (SCM version, SHA short/long, branch, optional git tag).
# Docker tags allow only [a-zA-Z0-9_.-]; setuptools_scm can output e.g. 0.4.0.dev5+gabc1234
DOCKER_TAG_SCM=$(echo "$RELEASE_VERSION" | tr '+' '-')
DOCKER_TAG_SHA_SHORT="${CIRCLE_SHA1:0:7}"
DOCKER_TAG_SHA_LONG="$CIRCLE_SHA1"
DOCKER_TAG_BRANCH=$(printf '%s' "$CIRCLE_BRANCH" | tr '/' '-' | sed 's/[^a-zA-Z0-9_.-]/-/g')
DOCKER_TAG_GIT="${CIRCLE_TAG:-}"
# Tabular API: tabular endpoints only
docker build --build-arg APP_MODULE=api_tabular.tabular.app:app_factory \
-t "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SCM}" \
-t "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SHA_SHORT}" \
-t "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SHA_LONG}" \
-t "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_BRANCH}" \
${DOCKER_TAG_GIT:+-t "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_GIT}"} \
.
docker push "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SCM}"
docker push "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SHA_SHORT}"
docker push "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_SHA_LONG}"
docker push "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_BRANCH}"
if [ -n "$DOCKER_TAG_GIT" ]; then
docker push "<< pipeline.parameters.docker-repo-tabular >>:${DOCKER_TAG_GIT}"
fi
# Metrics API: metrics endpoints only
docker build --build-arg APP_MODULE=api_tabular.metrics.app:app_factory \
-t "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SCM}" \
-t "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SHA_SHORT}" \
-t "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SHA_LONG}" \
-t "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_BRANCH}" \
${DOCKER_TAG_GIT:+-t "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_GIT}"} \
.
docker push "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SCM}"
docker push "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SHA_SHORT}"
docker push "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_SHA_LONG}"
docker push "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_BRANCH}"
if [ -n "$DOCKER_TAG_GIT" ]; then
docker push "<< pipeline.parameters.docker-repo-metrics >>:${DOCKER_TAG_GIT}"
fi
publish-pypi:
docker:
- image: ghcr.io/astral-sh/uv:python<< pipeline.parameters.python-version >>-trixie-slim
steps:
- attach_workspace:
at: .
- run:
name: Publish on PyPI
command: |
uv publish --username "${PYPI_USERNAME}" --password "${PYPI_PASSWORD}"
workflows:
build-test-deploy:
jobs:
- lint
- tests
- build:
requires:
- lint
- tests
filters:
branches:
only: << pipeline.parameters.publish-branch >>
context: org-global
- publish-pypi:
requires:
- build
filters:
branches:
only: << pipeline.parameters.publish-branch >>
context: org-global