Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-33570: Set up a web app for prototyping the portal #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Everything below this point is a copy of .gitignore.

# 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
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .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/

# pytype static type analyzer
.pytype/

# macOS
.DS_Store
85 changes: 81 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: CI

'on':
push: {}
push:
branches-ignore:
# These should always correspond to pull requests, so ignore them for
# the push trigger and let them be triggered by the pull_request
# trigger, avoiding running the workflow twice. This is a minor
# optimization so there's no need to ensure this is comprehensive.
- 'dependabot/**'
- 'renovate/**'
- 'tickets/**'
- 'u/**'
tags:
- '*'
pull_request: {}

jobs:
Expand All @@ -14,7 +25,73 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: 3.9

- name: Run pre-commit
uses: pre-commit/[email protected]
- name: Install tox
run: pip install tox

- name: Cache tox environments
id: cache-tox
uses: actions/cache@v2
with:
path: .tox
# requirements/*.txt and pyproject.toml have versioning info
# that would impact the tox environment.
key: tox-${{ matrix.python }}-${{ hashFiles('requirements/*.txt') }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
tox-${{ matrix.python }}-${{ hashFiles('requirements/*.txt') }}-

- name: Run tox
run: tox -e py,coverage-report,typing

build:
runs-on: ubuntu-latest
needs: [test]

# Only do Docker builds of tagged releases and pull requests from ticket
# branches. This will still trigger on pull requests from untrusted
# repositories whose branch names match our tickets/* branch convention,
# but in this case the build will fail with an error since the secret
# won't be set.
if: >
startsWith(github.ref, 'refs/tags/')
|| startsWith(github.head_ref, 'tickets/')

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Define the Docker tag
id: vars
run: echo ::set-output name=tag::$(scripts/docker-tag.sh "$GITHUB_HEAD_REF")

- name: Print the tag
id: print
run: echo ${{ steps.vars.outputs.tag }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: token
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./ # use currently-checked out files
file: ./Dockerfile
push: ${{ github.repository == 'lsst-sitcom/doc-portal-prototype' }}
tags: |
ghcr.io/lsst-sitcom/protorubinportal:${{ steps.vars.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ profile_default/
ipython_config.py

# pyenv
.python-version
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -127,3 +129,9 @@ dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# macOS
.DS_Store
68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This Dockerfile has four stages:
#
# base-image
# Updates the base Python image with security patches and common system
# packages. This image becomes the base of all other images.
# dependencies-image
# Installs third-party dependencies (requirements/main.txt) into a virtual
# environment. This virtual environment is ideal for copying across build
# stages.
# install-image
# Installs the app into the virtual environment.
# runtime-image
# - Copies the virtual environment into place.
# - Runs a non-root user.
# - Sets up the entrypoint and port.

FROM python:3.9.8-slim-bullseye as base-image

# Update system packages
COPY scripts/install-base-packages.sh .
RUN ./install-base-packages.sh && rm ./install-base-packages.sh

FROM base-image AS dependencies-image

# Install system packages only needed for building dependencies.
COPY scripts/install-dependency-packages.sh .
RUN ./install-dependency-packages.sh

# Create a Python virtual environment
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV
# Make sure we use the virtualenv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Put the latest pip and setuptools in the virtualenv
RUN pip install --upgrade --no-cache-dir pip setuptools wheel

# Install the app's Python runtime dependencies
COPY requirements/main.txt ./requirements.txt
RUN pip install --quiet --no-cache-dir -r requirements.txt

FROM dependencies-image AS install-image

# Use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"

COPY . /workdir
WORKDIR /workdir
RUN pip install --no-cache-dir .

FROM base-image AS runtime-image

# Create a non-root user
RUN useradd --create-home appuser

# Copy the virtualenv
COPY --from=install-image /opt/venv /opt/venv

# Make sure we use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"

# Switch to the non-root user.
USER appuser

# Expose the port.
EXPOSE 8080

# Run the application.
CMD ["uvicorn", "protorubinportal.main:app", "--host", "0.0.0.0", "--port", "8080"]
Empty file added MANIFEST.in
Empty file.
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
.PHONY: update-deps
update-deps:
pip install --upgrade pip-tools "pip<22" setuptools
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/dev.txt requirements/dev.in

.PHONY: init
init:
pip install -U pre-commit
pip install --editable .
pip install --upgrade -r requirements/main.txt -r requirements/dev.txt
rm -rf .tox
pip install --upgrade tox
pre-commit install

.PHONY: test
test:
pre-commit run --all-files
.PHONY: update
update: update-deps init

.PHONY: run
run:
tox -e run
13 changes: 13 additions & 0 deletions manifests/base/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: 'protorubinportal'
labels:
app.kubernetes.io/name: 'protorubinportal'
data:
# These configurations are injected as environment variables into the
# app container.
SAFIR_NAME: 'protorubinportal'
SAFIR_PROFILE: 'production'
SAFIR_LOGGER: 'protorubinportal'
SAFIR_LOG_LEVEL: 'INFO'
Loading