Skip to content

Commit d3ae258

Browse files
committed
Specify secret file path as env var
1 parent 0570888 commit d3ae258

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

.github/workflows/unit_test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
runs-on: ubuntu-latest
1313
env:
14-
DJANGO_SECRET_KEY: for-testing-only
14+
DJANGO_SECRET_KEY_FILE: ${{ runner.temp }}/django_secret_key
1515
strategy:
1616
matrix:
1717
python-version: ['3.10']
@@ -32,8 +32,7 @@ jobs:
3232
steps:
3333
- name: Write Docker-secrets-like file for CI
3434
run: |
35-
mkdir -p /run/secrets && touch /run/secrets/django_secret_key
36-
echo "for-testing-only" > /run/secrets/django_secret_key
35+
echo "for-testing-only" > $DJANGO_SECRET_KEY_FILE
3736
3837
- uses: actions/checkout@v5
3938

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ WORKDIR /usr/src/app
2020
RUN uv sync --locked
2121

2222
# Collect static files
23-
RUN --mount=type=secret,id=django_secret_key,required=true uv run python manage.py collectstatic --no-input
23+
RUN --mount=type=secret,id=django_secret_key,required=true \
24+
DJANGO_SECRET_KEY_FILE=/run/secrets/django_secret_key uv run python manage.py collectstatic --no-input

_app/webauthnio/settings.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
# Build paths inside the project like this: BASE_DIR / 'subdir'.
55
BASE_DIR = Path(__file__).resolve().parent.parent
66

7-
# Read the secret from the file that Docker injects
8-
# (see https://docs.docker.com/reference/compose-file/build/#secrets)
9-
_secret_key_file = open("/run/secrets/django_secret_key", "r")
7+
# Get path to the file containing the secret (this is a Docker-specific method)
8+
_secret_key_file_path = os.getenv("DJANGO_SECRET_KEY_FILE")
9+
if not _secret_key_file_path:
10+
raise Exception("DJANGO_SECRET_KEY_FILE must be a file path string")
11+
12+
# Read the secret from the file
13+
_secret_key_file = open(_secret_key_file_path, "r")
1014
SECRET_KEY = _secret_key_file.read()
1115
_secret_key_file.close()
1216

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ services:
4646
- django_secret_key
4747
environment:
4848
- PYTHONUNBUFFERED=0
49+
- DJANGO_SECRET_KEY_FILE=/run/secrets/django_secret_key
4950
- PROD_HOST_NAME
5051
- PROD_CSRF_ORIGIN
5152
- RP_ID

0 commit comments

Comments
 (0)