Skip to content

Commit c5336d2

Browse files
authored
Merge pull request #239 from ral-facilities/release/v2.0.0
Release v2.0.0
2 parents a6ae88d + 58798f1 commit c5336d2

File tree

16 files changed

+225
-215
lines changed

16 files changed

+225
-215
lines changed
File renamed without changes.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
## Description
2+
23
Enter a description of the changes here
34

45
## Testing instructions
6+
57
Add a set of instructions describing how the reviewer should test the code
8+
69
- [ ] Review code
710
- [ ] Check Actions build
11+
- [ ] Review changes to test coverage
812
- [ ] {more steps here}
913

1014
## Agile board tracking
15+
1116
closes #{issue_number}

.github/workflows/.ci.yml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: CI
22
on:
33
workflow_dispatch:
4+
inputs:
5+
push-docker-image-to-harbor:
6+
description: "Push Docker Image to Harbor"
7+
type: boolean
8+
default: false
49
pull_request:
510
push:
611
branches:
@@ -35,6 +40,9 @@ jobs:
3540
python -m pip install .[code-analysis]
3641
python -m pip install -r requirements.txt
3742
43+
- name: Run black
44+
run: black --check --line-length 120 ldap_jwt_auth test
45+
3846
- name: Run pylint
3947
run: pylint ldap_jwt_auth
4048

@@ -45,57 +53,56 @@ jobs:
4553
- name: Checkout repository
4654
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4755

48-
- name: Install python-ldap system dependencies
49-
run: |
50-
sudo apt-get update
51-
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev
52-
53-
- name: Set up Python
54-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
55-
with:
56-
python-version: "3.12"
57-
cache: "pip"
58-
59-
- name: Install dependencies
60-
run: |
61-
python -m pip install --upgrade pip
62-
python -m pip install .[test]
63-
python -m pip install -r requirements.txt
64-
6556
- name: Create logging configuration file
66-
run: cp ldap_jwt_auth/logging.example.ini ldap_jwt_auth/logging.ini
57+
run: cp logging.example.ini logging.ini
6758

6859
- name: Run unit tests
69-
run: pytest -c test/pytest.ini test/unit/ --cov
60+
run: |
61+
docker build --file Dockerfile --target test --tag ldap-jwt-auth:test .
62+
docker run \
63+
--name ldap-jwt-auth \
64+
--volume ./logging.ini:/app/logging.ini \
65+
ldap-jwt-auth:test \
66+
pytest --config-file test/pytest.ini --cov ldap_jwt_auth --cov-report xml test/unit -v
67+
docker cp ldap-jwt-auth:/app/coverage.xml coverage.xml
68+
69+
- name: Upload coverage reports to Codecov
70+
if: success()
71+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
72+
with:
73+
token: ${{ secrets.CODECOV_TOKEN }}
7074

7175
docker:
72-
# This job triggers only if all the other jobs succeed. It builds the Docker image and if successful,
73-
# it pushes it to Harbor.
76+
# This job triggers only if all the other jobs succeed. It builds the Docker image
77+
# and if run manually from Github Actions, it pushes to Harbor.
7478
needs: [linting, unit-tests]
7579
name: Docker
7680
runs-on: ubuntu-latest
81+
env:
82+
PUSH_DOCKER_IMAGE_TO_HARBOR: ${{ inputs.push-docker-image-to-harbor != null && inputs.push-docker-image-to-harbor || 'false' }}
7783
steps:
7884
- name: Check out repo
7985
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8086

87+
- name: Extract metadata (tags, labels) for Docker
88+
id: meta
89+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
90+
with:
91+
images: ${{ vars.HARBOR_URL }}/auth-api
92+
8193
- name: Login to Harbor
94+
if: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
8295
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
8396
with:
84-
registry: ${{ secrets.HARBOR_URL }}
97+
registry: ${{ vars.HARBOR_URL }}
8598
username: ${{ secrets.HARBOR_USERNAME }}
8699
password: ${{ secrets.HARBOR_TOKEN }}
87100

88-
- name: Extract metadata (tags, labels) for Docker
89-
id: meta
90-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
91-
with:
92-
images: ${{ secrets.HARBOR_URL }}/auth-api
93-
94-
- name: Build and push Docker image to Harbor
95-
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
101+
- name: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) && 'Build and push Docker image to Harbor' || 'Build Docker image' }}
102+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
96103
with:
97104
context: .
98-
file: ./Dockerfile.prod
99-
push: true
105+
push: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
100106
tags: ${{ steps.meta.outputs.tags }}
101107
labels: ${{ steps.meta.outputs.labels }}
108+
target: prod

.github/workflows/release-build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Release Build
22
on:
33
push:
4-
tags: 'v*'
4+
tags: "v*"
55

66
permissions:
77
contents: read
@@ -18,23 +18,23 @@ jobs:
1818
- name: Login to Harbor
1919
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
2020
with:
21-
registry: ${{ secrets.HARBOR_URL }}
21+
registry: ${{ vars.HARBOR_URL }}
2222
username: ${{ secrets.HARBOR_USERNAME }}
2323
password: ${{ secrets.HARBOR_TOKEN }}
2424

2525
- name: Extract metadata (tags, labels) for Docker
2626
id: meta
2727
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
2828
with:
29-
images: ${{ secrets.HARBOR_URL }}/auth-api
29+
images: ${{ vars.HARBOR_URL }}/auth-api
3030
tags: |
3131
type=semver,pattern={{version}}
3232
type=semver,pattern={{major}}.{{minor}}
3333
flavor: |
3434
latest=false
3535
3636
- name: Build and push Docker image to Harbor
37-
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
37+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
3838
with:
3939
context: .
4040
file: ./Dockerfile.prod

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ldap_jwt_auth/logging.ini
1+
logging.ini
22
/active_usernames.txt
33
keys/*
44
!keys/.keep

Dockerfile

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
1-
FROM python:3.12.10-alpine3.21@sha256:e5956ba054e89858c706f038a980241ea38565176619f1a2695cb9b039ea1265
1+
FROM python:3.12.11-alpine3.22@sha256:c610e4a94a0e8b888b4b225bfc0e6b59dee607b1e61fb63ff3926083ff617216 AS base
22

3-
WORKDIR /ldap-jwt-auth-run
3+
# Install python-ldap system dependencies
4+
RUN apk add --no-cache build-base openldap-dev
5+
6+
WORKDIR /app
47

58
COPY pyproject.toml requirements.txt ./
69
COPY ldap_jwt_auth/ ldap_jwt_auth/
710

11+
12+
FROM base AS dev
13+
14+
WORKDIR /app
15+
816
RUN --mount=type=cache,target=/root/.cache \
917
set -eux; \
1018
\
11-
# Install python-ldap system dependencies \
12-
apk add --no-cache build-base openldap-dev; \
19+
pip install --no-cache-dir .[dev]; \
20+
# Ensure the pinned versions of the production dependencies and subdependencies are installed \
21+
pip install --no-cache-dir --requirement requirements.txt;
22+
23+
CMD ["fastapi", "dev", "ldap_jwt_auth/main.py", "--host", "0.0.0.0", "--port", "8000"]
24+
25+
EXPOSE 8000
26+
27+
28+
FROM dev AS test
29+
30+
WORKDIR /app
31+
32+
COPY test/ test/
33+
34+
CMD ["pytest", "--config-file", "test/pytest.ini", "-v"]
35+
36+
37+
FROM base AS prod
38+
39+
WORKDIR /app
40+
41+
RUN --mount=type=cache,target=/root/.cache \
42+
set -eux; \
1343
\
14-
python -m pip install .[dev]; \
44+
# Ensure the package gets installed properly using the pyproject.toml file \
45+
pip install --no-cache-dir .; \
1546
# Ensure the pinned versions of the production dependencies and subdependencies are installed \
16-
python -m pip install --no-cache-dir --requirement requirements.txt;
47+
pip install --no-cache-dir --requirement requirements.txt; \
48+
\
49+
# Create a non-root user to run as \
50+
addgroup -g 500 -S ldap-jwt-auth; \
51+
adduser -S -D -G ldap-jwt-auth -H -u 500 -h /app ldap-jwt-auth;
52+
53+
USER ldap-jwt-auth
54+
55+
CMD ["fastapi", "run", "ldap_jwt_auth/main.py", "--host", "0.0.0.0", "--port", "8000"]
1756

18-
CMD ["uvicorn", "ldap_jwt_auth.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
1957
EXPOSE 8000

Dockerfile.prod

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)