Skip to content

Commit

Permalink
Add Flask image
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Dec 4, 2023
1 parent 11d6bf3 commit 164e13a
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/branch-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
image-name: [tna-python, tna-python-django]
image-name: [tna-python, tna-python-flask, tna-python-django]
steps:
- name: Prepare image tag
run: |
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ jobs:
publish: true
ignore-linting-rules: DL3002

python-flask:
name: Python Flask
needs: python
uses: ./.github/workflows/_docker-build-deploy.yml
with:
image-name: tna-python-flask
docker-context: docker/tna-python-flask
dockerfile: Dockerfile
publish: true

python-django:
name: Python Django
needs: python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/remove-untagged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
image-name: [tna-python, tna-python-root, tna-python-django, tna-python-django-root]
image-name: [tna-python, tna-python-root, tna-python-flask, tna-python-django, tna-python-django-root]
env:
PER_PAGE: 100
steps:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ jobs:
publish: false
ignore-linting-rules: DL3002

python-flask:
name: Python Flask
needs: python
uses: ./.github/workflows/_docker-build-deploy.yml
with:
image-name: tna-python-flask
docker-context: docker/tna-python-flask
dockerfile: Dockerfile
publish: false

python-django:
name: Python Django
needs: python
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/nationalarchives/docker/compare/v0.1.11...HEAD)

### Added

- Initial release of `tna-python-flask` Docker image

### Changed
### Deprecated
### Removed
Expand Down
24 changes: 24 additions & 0 deletions docker/tna-python-flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ARG BASE_IMAGE_TAG=latest
FROM ghcr.io/nationalarchives/tna-python:"$BASE_IMAGE_TAG"

# ==========================================
# Move the existing build and run scripts to
# a -common suffix so that we can keep using
# the base tna-build and tna-run commands
# ==========================================
RUN set -eux; \
\
mv /home/app/.local/bin/tna-run /home/app/.local/bin/tna-run-common

# ==========================================
# These new commands are just proxies to the
# renamed tna-build/tna-run scripts included
# in the parent Docker image, but with extra
# Django-specific commands
# ==========================================
COPY --chown=app bin/tna-run /home/app/.local/bin/

# ==========================================
# Allow all our scripts to be executable
# ==========================================
RUN chmod +x /home/app/.local/bin/tna-run
23 changes: 23 additions & 0 deletions docker/tna-python-flask/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# tna-python-flask

This image extends `tna-python` but adds checks for environment variables specific to Flask.

This image assumes you have a version of Flask added to you project's `pyproject.toml` file.

## Environment variables

All environment variables defined in [tna-python](../tna-python/README.md) as well as:

| Variable | Description | Default |
| ------------ | ----------------------------------------------- | ------- |
| `SECRET_KEY` | A random key used to secure client session data | [None] |

A secret key can be generated using:

```sh
python -c 'import secrets; print(secrets.token_hex())'
```

## Commands for the Dockerfile

The command `tna-run` is moved to `tna-run-common` and a new and `tna-run` command is added.
11 changes: 11 additions & 0 deletions docker/tna-python-flask/bin/tna-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

if [[ -z $SECRET_KEY ]]
then
echo -e "Error: Environment variable SECRET_KEY not set";
exit 1
fi

tna-run-common "$1"

0 comments on commit 164e13a

Please sign in to comment.