Skip to content

Commit

Permalink
Merge pull request #2 from UKGovernmentBEIS/craig/migrate-tooling
Browse files Browse the repository at this point in the history
Initial repo tooling migration
  • Loading branch information
craigwalton-dsit authored Dec 17, 2024
2 parents 224498d + a0cfd6d commit 2821a9b
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.148.1/containers/python-3/.devcontainer/base.Dockerfile
ARG VARIANT="3.11"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# https://github.com/UKGovernmentBEIS/inspect_ai/issues/51
ENV XDG_RUNTIME_DIR=/tmp
USER vscode
RUN pip3 --disable-pip-version-check --no-cache-dir install -U \
'poetry==1.8.3' \
'pip==22.1.2'
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
4 changes: 4 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This devcontainer include tools such as minikube and Helm which are required for
Kubernetes Sandbox Environment development and testing.

It is used by the CI pipeline. Its use is optional for local development.
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Devcontainer",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "3.11",
"INSTALL_NODE": "true",
"NODE_VERSION": "18.7"
}
},
"runArgs": [
"--network=host" // Allows accessing K8s API from within container using docker outside of docker
],
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"dockerDashComposeVersion": "2.30.3"
},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"version": "1.31.0",
"helm": "3.16.1",
"minikube": "1.34.0"
}
},
"postCreateCommand": "bash .devcontainer/post-create.sh",
"remoteUser": "vscode"
}
46 changes: 46 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Exit immediately if a command exits with a non-zero status, and print each command.
set -e -x

echo "Setting up Minikube..."
minikube delete
# github actions runner has 2 cpus, 8G memory
minikube start --addons=gvisor --cni bridge --container-runtime=containerd --memory=4g

# Add the containerd RuntimeClass to the cluster.
kubectl apply -f - <<EOF
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: runc
handler: runc
EOF

# Add a mocked nfs-csi StorageClass which uses the hostpath provisioner.
kubectl apply -f - <<EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-csi
provisioner: k8s.io/minikube-hostpath
reclaimPolicy: Delete
volumeBindingMode: Immediate
EOF

# Install Cilium CLI. Previously, the ghcr.io/audacioustux/devcontainers/cilium:1
# devcontainer feature was used, but it doesn't allow a specific version of the CLI to
# be installed and the latest version failed at `cilium install`.
CILIUM_CLI_VERSION=v0.16.15
CILIUM_CLI_ARCH=amd64
echo "Installing Cilium CLI $CILIUM_CLI_VERSION $CILIUM_CLI_ARCH..."
curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CILIUM_CLI_ARCH}.tar.gz{,.sha256sum}
sha256sum --check cilium-linux-${CILIUM_CLI_ARCH}.tar.gz.sha256sum
sudo tar xzvfC cilium-linux-${CILIUM_CLI_ARCH}.tar.gz /usr/local/bin
rm cilium-linux-${CILIUM_CLI_ARCH}.tar.gz{,.sha256sum}

echo "Installing Cilium..."
cilium install
cilium status --wait
cilium hubble enable --ui

echo "Installing poetry environment..."
poetry install
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
uses: ./.github/workflows/lint.yml
format:
uses: ./.github/workflows/format.yml
type-check:
uses: ./.github/workflows/type-check.yml
test:
uses: ./.github/workflows/test.yml
pre-commit:
uses: ./.github/workflows/pre-commit.yml
28 changes: 28 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: docs
on:
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Set up Python
uses: actions/setup-python@v5.1.0
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
working-directory: ./docs
- run: poetry run mkdocs gh-deploy --force
working-directory: ./docs
15 changes: 15 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Check format using Ruff

on:
workflow_call:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check format with Ruff
uses: chartboost/ruff-action@v1
with:
args: 'format --check'
version: 0.6.0
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint using Ruff

on:
workflow_call:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint with Ruff
uses: chartboost/ruff-action@v1
with:
version: 0.6.0
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run pre-commit checks

on:
workflow_call:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.0
with:
python-version: 3.11
- name: Set skips
# There are separate CI checks for Ruff; avoid checking twice.
run: echo "SKIP=ruff,ruff-format" >> $GITHUB_ENV
- uses: pre-commit/action@v3.0.1
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Test using Pytest

on:
workflow_call:

jobs:
pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install -g @devcontainers/cli@v0.30.0
- run: devcontainer up --workspace-folder=.
- run: devcontainer exec --workspace-folder=. poetry run pytest -rA -x --color=yes
21 changes: 21 additions & 0 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Type check using Mypy

on:
workflow_call:

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5.1.0
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Type check with mypy
run: poetry run mypy .
170 changes: 170 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# 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/
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/
cover/

# 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
.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

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__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/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Inspect logs
logs/

# Ruff
.ruff_cache

scratch/
Loading

0 comments on commit 2821a9b

Please sign in to comment.