Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from communitiesuk/fs-4462-base-image-build
Browse files Browse the repository at this point in the history
Fs 4462 base image build
  • Loading branch information
srh-sloan authored Jun 18, 2024
2 parents 0ecbde6 + 994c801 commit 9f74c08
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 18 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Publish Base Image

on:
workflow_dispatch:
on: [push, workflow_dispatch]

env:
DOCKER_REGISTRY: ghcr.io
Expand All @@ -11,8 +10,11 @@ jobs:
docker-build:
strategy:
matrix:
flavour: ["vanilla", "frontend"]
flavour: ["flask", "frontend"]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./python-flask-dev
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -21,8 +23,9 @@ jobs:
id: set-tags
run: |
source tags
echo "PYTHON_FLASK_DEV_VANILLA=$PYTHON_FLASK_DEV" >> $GITHUB_ENV
echo "PYTHON_FLASK_DEV_FRONTEND=$PYTHON_FLASK_DEV_FRONTEND" >> $GITHUB_ENV
echo "PYTHON_FLASK_DEV_PYTHON=$PYTHON_FLASK_DEV_PY" >> $GITHUB_ENV
echo "PYTHON_FLASK_DEV_FLASK=$PYTHON_FLASK_DEV_FLASK" >> $GITHUB_ENV
echo "PYTHON_FLASK_DEV_FRONTEND=$PYTHON_FLASK_DEV_JINJA" >> $GITHUB_ENV
- name: Docker metadata
id: metadata
Expand All @@ -32,8 +35,9 @@ jobs:
tags: |
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{env.PYTHON_FLASK_DEV_VANILLA}},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{env.PYTHON_FLASK_DEV_FRONTEND}},enable=(${{ (github.ref == format('refs/heads/{0}', 'main')) && (matrix.flavour == 'frontend') }})
type=raw,value=${{env.PYTHON_FLASK_DEV_PYTHON}},enable=${{ github.ref == format('refs/heads/{0}', 'main')}}
type=raw,value=${{env.PYTHON_FLASK_DEV_FLASK}},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{env.PYTHON_FLASK_DEV_FRONTEND}},enable=${{ (github.ref == format('refs/heads/{0}', 'main')) && (matrix.flavour == 'frontend') }}
type=ref,event=branch
- name: Log in to the Container registry
Expand All @@ -46,8 +50,9 @@ jobs:
- name: Build and push docker image
uses: docker/build-push-action@v4
with:
context: .
context: ./python-flask-dev/
tags: ${{ steps.metadata.outputs.tags}}
labels: ${{ steps.metadata.outputs.labels }}
push: true
file: ./python-flask-dev/Dockerfile
file: ./python-flask-dev/Dockerfile
target: ${{matrix.flavour}}
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

sqlite.db

.idea
.DS_Store
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# funding-service-design-base
Base images and requirements definitions for funding service design apps
Base images and requirements definitions for development of funding service design apps. These images are not used in production as those ones are build using Paketo.

## Python Flask Dev
Contains requirements files for different versions of a python flask app. The [Dockerfile](./python-flask-dev/Dockerfile) contains the following build targets:
- `flask`: Developer image based on python 3.10 bullseye, with Flask 3.0.3 installed on top, plus everything in [requirements-dev.txt](./python-flask-dev/requirements-dev.txt)
- `frontend`: Base on `flask` above, with everything from [requirements-frontend.txt](./python-flask-dev/requirements-frontend.txt) installed

## Workflows
- [Publish](/.github/workflows/publish.yml): Uses a matrix strategy to build each target in the Dockerfile and publish these to GHCR. If on `main`, will tag them as specified in [tags](./python-flask-dev/tags). (At present if you add something to tags you also need to add to [publish.yml](./.github/workflows/publish.yml)).

# Future Improvements
- Make the workflow just use all tags in the tags file, not hard code them?
- If we add other base images besides [python-flask-dev](./python-flask-dev/), make the workflow use a matrix approach so it builds all of these?
- Are we using the right tag names?
- Stop using pip-compile and use rye?
27 changes: 21 additions & 6 deletions python-flask-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
FROM python:3.10-bullseye as fsd-base-dev-python-flask

# --------------------------------------------------
# Basic python flask image that the other FSD images can build upon
# --------------------------------------------------

FROM python:3.10-bullseye as flask
WORKDIR /app
COPY requirements.txt requirements.txt
COPY requirements-dev.txt requirements-dev.txt
RUN pip install --upgrade pip && pip install -r requirements.txt
RUN pip install -r requirements-dev.txt
RUN pip install pip-tools

FROM fsd-base-dev-python-flask as frontend
# --------------------------------------------------
# Base image to build frontend applications on - includes flask and other frontend frameworks such as govuk-frontend-jinja
# --------------------------------------------------

FROM flask as frontend
WORKDIR /app
COPY requirements-frontend.txt requirements-frontend.txt
RUN pip install --upgrade pip && pip install -r requirements-frontend.txt

FROM fsd-base-dev-python-flask as db
WORKDIR /app
COPY requirements-frontend.txt requirements-db.txt
RUN pip install --upgrade pip && pip install -r requirements-db.txt


# --------------------------------------------------
# Will hold config for building DB base image
# --------------------------------------------------

# FROM flask as db
# WORKDIR /app
# COPY requirements-db.txt requirements-db.txt
# RUN pip install --upgrade pip && pip install -r requirements-db.txt
24 changes: 24 additions & 0 deletions python-flask-dev/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#-----------------------------------
# Pytest
#-----------------------------------

pytest==8.2.2
pytest-mock==3.12.0
pytest-env==1.1.3

#-----------------------------------
# Dev Utils
#-----------------------------------
invoke==2.2.0

#-----------------------------------
# Code Quality
#-----------------------------------
flake8==7.0.0
flake8-pyproject==1.2.3
black==24.3.0

#-----------------------------------
# Other Dev Dependencies
#-----------------------------------
beautifulsoup4==4.12.2
61 changes: 61 additions & 0 deletions python-flask-dev/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements-dev.in
#
beautifulsoup4==4.12.2
# via -r requirements-dev.in
black==24.3.0
# via -r requirements-dev.in
click==8.1.7
# via black
exceptiongroup==1.2.1
# via pytest
flake8==7.0.0
# via
# -r requirements-dev.in
# flake8-pyproject
flake8-pyproject==1.2.3
# via -r requirements-dev.in
iniconfig==2.0.0
# via pytest
invoke==2.2.0
# via -r requirements-dev.in
mccabe==0.7.0
# via flake8
mypy-extensions==1.0.0
# via black
packaging==24.1
# via
# black
# pytest
pathspec==0.12.1
# via black
platformdirs==4.2.2
# via black
pluggy==1.5.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.2.2
# via
# -r requirements-dev.in
# pytest-env
# pytest-mock
pytest-env==1.1.3
# via -r requirements-dev.in
pytest-mock==3.12.0
# via -r requirements-dev.in
soupsieve==2.5
# via beautifulsoup4
tomli==2.0.1
# via
# black
# flake8-pyproject
# pytest
# pytest-env
typing-extensions==4.12.2
# via black
Loading

0 comments on commit 9f74c08

Please sign in to comment.