Skip to content

Commit a2cca07

Browse files
authored
Merge pull request #920 from sanders41/docker-maturin
Add maturin fastapi dockerfiles
2 parents f25845a + 11ada00 commit a2cca07

9 files changed

+444
-20
lines changed

.github/workflows/testing_fastapi.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,169 @@ jobs:
275275
working-directory: ${{ env.WORKING_DIR }}
276276
if: matrix.project_type == 'application'
277277
run: python -m pytest
278+
test-pyo3-uv-fastapi-project:
279+
name: test-fastapi-pyo3-uv-setup-fastapi
280+
strategy:
281+
fail-fast: false
282+
runs-on: ubuntu-latest
283+
steps:
284+
- uses: actions/checkout@v5
285+
- name: install Rust
286+
uses: dtolnay/rust-toolchain@stable
287+
- name: Cache Rust dependencies
288+
uses: Swatinem/[email protected]
289+
- name: Install sqlx-cli
290+
run: cargo install sqlx-cli --no-default-features -F native-tls -F postgres
291+
- name: Install uv
292+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
293+
- name: Set up Python
294+
uses: actions/setup-python@v6
295+
with:
296+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
297+
- name: Build package
298+
run: cargo build --release -F fastapi
299+
- name: Run creation
300+
run: ./scripts/ci_run_fastapi.sh "fastapi" 3
301+
shell: bash
302+
- name: Install Dependencies
303+
working-directory: ${{ env.WORKING_DIR }}
304+
run: |
305+
uv lock
306+
uv sync --frozen
307+
uv run maturin build
308+
- name: Pre-commit check
309+
working-directory: ${{ env.WORKING_DIR }}
310+
run: |
311+
uv run pre-commit install
312+
git add .
313+
uv run pre-commit run --all-files
314+
- name: make .env
315+
working-directory: ${{ env.WORKING_DIR }}
316+
run: touch .env
317+
- name: Build and start Docker containers
318+
working-directory: ${{ env.WORKING_DIR }}
319+
run: docker compose up -d
320+
- name: Test with pytest
321+
working-directory: ${{ env.WORKING_DIR }}
322+
run: uv run pytest -n auto
323+
test-pyo3-uv-non-fastapi-project:
324+
name: test-fastapi-uv-pyo3-setup-non-fastapi
325+
strategy:
326+
fail-fast: false
327+
matrix:
328+
project_type: ["application", "lib"]
329+
runs-on: ubuntu-latest
330+
steps:
331+
- uses: actions/checkout@v5
332+
- name: install Rust
333+
uses: dtolnay/rust-toolchain@stable
334+
- name: Cache Rust dependencies
335+
uses: Swatinem/[email protected]
336+
- name: Install uv
337+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
338+
- name: Set up Python
339+
uses: actions/setup-python@v6
340+
with:
341+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
342+
- name: Build package
343+
run: cargo build --release -F fastapi
344+
- name: Run creation
345+
run: ./scripts/ci_run_fastapi.sh ${{ matrix.project_type }} 3
346+
shell: bash
347+
- name: Install Dependencies
348+
working-directory: ${{ env.WORKING_DIR }}
349+
run: |
350+
uv lock
351+
uv sync --frozen
352+
uv run maturin build
353+
- name: Pre-commit check
354+
working-directory: ${{ env.WORKING_DIR }}
355+
run: |
356+
uv run pre-commit install
357+
git add .
358+
uv run pre-commit run --all-files
359+
- name: Test with pytest
360+
working-directory: ${{ env.WORKING_DIR }}
361+
if: matrix.project_type == 'application'
362+
run: uv run pytest
363+
test-pyo3-setuptools-fastapi-project:
364+
name: test-fastapi-pyo3-setuptools-setup-fastapi
365+
strategy:
366+
fail-fast: false
367+
runs-on: ubuntu-latest
368+
steps:
369+
- uses: actions/checkout@v5
370+
- name: install Rust
371+
uses: dtolnay/rust-toolchain@stable
372+
- name: Cache Rust dependencies
373+
uses: Swatinem/[email protected]
374+
- name: Install sqlx-cli
375+
run: cargo install sqlx-cli --no-default-features -F native-tls -F postgres
376+
- name: Set up Python
377+
uses: actions/setup-python@v6
378+
with:
379+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
380+
- name: Build package
381+
run: cargo build --release -F fastapi
382+
- name: Run creation
383+
run: ./scripts/ci_run_fastapi.sh "fastapi" 3 2
384+
shell: bash
385+
- name: Install Dependencies
386+
working-directory: ${{ env.WORKING_DIR }}
387+
run: |
388+
python -m pip install -U pip
389+
python -m pip install -r requirements.txt -r requirements-dev.txt
390+
python -m maturin build
391+
- name: Pre-commit check
392+
working-directory: ${{ env.WORKING_DIR }}
393+
run: |
394+
pre-commit install
395+
git add .
396+
pre-commit run --all-files
397+
- name: make .env
398+
working-directory: ${{ env.WORKING_DIR }}
399+
run: touch .env
400+
- name: Build and start Docker containers
401+
working-directory: ${{ env.WORKING_DIR }}
402+
run: docker compose up -d
403+
- name: Test with pytest
404+
working-directory: ${{ env.WORKING_DIR }}
405+
run: python -m pytest -n auto
406+
test-pyo3-setuptools-non-fastapi-project:
407+
name: test-fastapi-setuptools-pyo3-setup-non-fastapi
408+
strategy:
409+
fail-fast: false
410+
matrix:
411+
project_type: ["application", "lib"]
412+
runs-on: ubuntu-latest
413+
steps:
414+
- uses: actions/checkout@v5
415+
- name: install Rust
416+
uses: dtolnay/rust-toolchain@stable
417+
- name: Cache Rust dependencies
418+
uses: Swatinem/[email protected]
419+
- name: Set up Python
420+
uses: actions/setup-python@v6
421+
with:
422+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
423+
- name: Build package
424+
run: cargo build --release -F fastapi
425+
- name: Run creation
426+
run: ./scripts/ci_run_fastapi.sh ${{ matrix.project_type }} 3 2
427+
shell: bash
428+
- name: Install Dependencies
429+
working-directory: ${{ env.WORKING_DIR }}
430+
run: |
431+
python -m pip install -U pip
432+
python -m pip install -r requirements-dev.txt
433+
python -m maturin build
434+
- name: Pre-commit check
435+
working-directory: ${{ env.WORKING_DIR }}
436+
run: |
437+
pre-commit install
438+
git add .
439+
pre-commit run --all-files
440+
- name: Test with pytest
441+
working-directory: ${{ env.WORKING_DIR }}
442+
if: matrix.project_type == 'application'
443+
run: python -m pytest

scripts/ci_run_fastapi.sh

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,19 @@ use_continuous_deployment=""
5050
use_release_drafter=""
5151
pyo3_python_manager=""
5252

53-
if [[ project_manager -eq 3 ]]; then
54-
./target/release/python-project create -s << EOF
53+
# Check for user provided pyo3_python_manager input
54+
if [ $# -gt 2 ]; then
55+
if [ $3 -lt 1 ] || [ $3 -gt 2 ]; then
56+
echo "Invalid pyo3_python_manager value"
57+
exit 1
58+
else
59+
pyo3_python_manager=$3
60+
fi
61+
fi
62+
63+
if [[ $project_manager -eq 3 ]]; then
64+
if [ "$fastapi_project" = "1" ]; then
65+
./target/release/python-project create -s << EOF
5566
$project_name
5667
$project_slug
5768
$source_dir
@@ -61,17 +72,42 @@ $creator_email
6172
$license
6273
$copyright_year
6374
$version
75+
$fastapi_project
76+
$python_version
77+
$min_python_version
78+
$gha_versions
79+
$project_manager
80+
$pyo3_python_manager
81+
$max_line_length
82+
$use_dependabot
83+
$use_continuous_deployment
84+
$use_release_drafter
85+
EOF
86+
else
87+
./target/release/python-project create -s << EOF
88+
$project_name
89+
$project_slug
90+
$source_dir
91+
$project_description
92+
$creator
93+
$creator_email
94+
$license
95+
$copyright_year
96+
$version
97+
$fastapi_project
6498
$python_version
6599
$min_python_version
66100
$gha_versions
67101
$project_manager
68102
$pyo3_python_manager
69103
$application
104+
$is_async_project
70105
$max_line_length
71106
$use_dependabot
72107
$use_continuous_deployment
73108
$use_release_drafter
74109
EOF
110+
fi
75111
else
76112
if [ "$fastapi_project" = "1" ]; then
77113
./target/release/python-project create -s << EOF

0 commit comments

Comments
 (0)