Skip to content

Commit 31a4249

Browse files
31chtumaisch
authored andcommitted
Add initial devcontainer
1 parent 974be22 commit 31a4249

26 files changed

+1802
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://github.com/devcontainers/images/tree/main/src/python
2+
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm
3+
4+
# Install additional packages.
5+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
# && apt-get -y install --no-install-recommends \
7+
# <your-package-list-here> \
8+
# && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
9+
10+
# Install UV / UVX
11+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
12+
ENV UV_COMPILE_BYTECODE=1
13+
ENV UV_LINK_MODE=copy
14+
15+
# Install project dependencies
16+
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
--mount=type=bind,source=uv.lock,target=uv.lock \
18+
uv sync --frozen --no-install-project --all-extras

.devcontainer/devcontainer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Python 3",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"build": {
7+
// Path is relative to the devcontainer.json file.
8+
"dockerfile": "Dockerfile",
9+
"context": ".."
10+
},
11+
// Features to add to the dev container. More info: https://containers.dev/features.
12+
// "features": {},
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
// Use 'postCreateCommand' to run commands after the container is created.
16+
"postCreateCommand": "uv pip install -e ."
17+
// Configure tool-specific properties.
18+
// "customizations": {},
19+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
20+
// "remoteUser": "root"
21+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- Pipfile
9+
- Pipfile.lock
10+
- .devcontainer/Dockerfile
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- Pipfile
16+
- Pipfile.lock
17+
- .devcontainer/Dockerfile
18+
workflow_dispatch:
19+
20+
jobs:
21+
build-and-publish:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
file: .devcontainer/Dockerfile
46+
push: true
47+
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build and test the project
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- ".devcontainer/Dockerfile"
9+
pull_request:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- ".devcontainer/Dockerfile"
14+
workflow_dispatch:
15+
16+
# IMPORTANT: make sure to use the 'runner user'when running jobs in a container!
17+
# Otherwise there will be 'dubious ownership' issues reported by Git.
18+
# Therefore, make sure to use the '--user 1001' option for the container.
19+
jobs:
20+
build-doc:
21+
runs-on: ubuntu-latest
22+
container:
23+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
24+
options: --user 1001
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
- name: Build documentation
29+
run: ./tools/build-docs.sh
30+
- name: Upload documentation
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: documentation
34+
path: "build/html"
35+
retention-days: 1
36+
37+
build-package:
38+
runs-on: ubuntu-latest
39+
container:
40+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
41+
options: --user 1001
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
- name: Build Python package
46+
run: ./tools/build-package.sh
47+
- name: Upload Python package
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: python-package
51+
path: "dist/*.whl"
52+
retention-days: 1
53+
54+
lint-package:
55+
runs-on: ubuntu-latest
56+
container:
57+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
58+
options: --user 1001
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
- name: Run linters
63+
run: tools/lint-package.sh
64+
continue-on-error: true
65+
- name: Upload lint results
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: lint-results
69+
path: "build/*.txt"
70+
retention-days: 1
71+
72+
test-package:
73+
runs-on: ubuntu-latest
74+
container:
75+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
76+
options: --user 1001
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
- name: Run tests
81+
run: ./tools/test-package.sh
82+
- name: Upload test results
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: test-results
86+
path: "build/*.xml"
87+
retention-days: 1

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
__pycache__
2+
.coverage
3+
.mypy_cache
4+
.pytest_cache
5+
.venv
6+
*.egg-info
7+
_build
8+
build
9+
dist
10+
coverage.xml
11+
report.xml
12+
version.py

.gitlab-ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
default:
3+
image: mcr.microsoft.com/devcontainers/python:1-3.12-bookworm
4+
5+
workflow:
6+
name: '$CI_COMMIT_AUTHOR: $CI_COMMIT_TITLE'
7+
auto_cancel:
8+
on_new_commit: interruptible
9+
on_job_failure: all
10+
rules:
11+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
12+
variables:
13+
DEPLOY_ENV: "development"
14+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
15+
variables:
16+
DEPLOY_ENV: "staging"
17+
- if: $CI_COMMIT_BRANCH == $CI_COMMIT_TAG
18+
variables:
19+
DEPLOY_ENV: "production"
20+
- when: never
21+
22+
stages:
23+
- build
24+
- test
25+
- deploy
26+
27+
build-python-package:
28+
stage: build
29+
before_script:
30+
- pipx install uv
31+
script:
32+
- tools/build-package.sh
33+
artifacts:
34+
paths:
35+
- 'dist/*.whl'
36+
expire_in: 1 week
37+
38+
build-documentation:
39+
stage: build
40+
before_script:
41+
- pipx install uv
42+
script:
43+
- tools/build-docs.sh
44+
artifacts:
45+
paths:
46+
- build/html/
47+
48+
test-python-package:
49+
stage: test
50+
before_script:
51+
- pipx install uv
52+
script:
53+
- tools/test-package.sh
54+
coverage: '/TOTAL.*\s+(\d+%)$/'
55+
artifacts:
56+
reports:
57+
junit: report.xml
58+
coverage_report:
59+
coverage_format: cobertura
60+
path: coverage.xml
61+
62+
lint-python-package:
63+
stage: test
64+
before_script:
65+
- pipx install uv
66+
script:
67+
- uv run --all-extras flake8 src/python_training_project --format gl-codeclimate --output-file gl-code-quality-report.json
68+
artifacts:
69+
reports:
70+
codequality: gl-code-quality-report.json
71+
72+
additional-mr-checks:
73+
stage: test
74+
script:
75+
- echo "Additional checks for merge requests"
76+
rules:
77+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
78+
79+
deploy-python-package:
80+
stage: deploy
81+
before_script:
82+
- pipx install uv
83+
variables:
84+
UV_PUBLISH_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi
85+
UV_PUBLISH_USERNAME: gitlab-ci-token
86+
UV_PUBLISH_PASSWORD: ${CI_JOB_TOKEN}
87+
88+
script:
89+
- tools/deploy-package.sh
90+
91+
pages:
92+
stage: deploy
93+
script:
94+
- mv build/html/ public/
95+
artifacts:
96+
paths:
97+
- public/
98+
99+
job-for-tags:
100+
stage: deploy
101+
script:
102+
- echo "Tag pipeline"
103+
rules:
104+
- if: $CI_COMMIT_TAG
105+

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

0 commit comments

Comments
 (0)