Skip to content

Commit

Permalink
Merge pull request #122 from alan-turing-institute/r-docker-refactor
Browse files Browse the repository at this point in the history
R docker refactor for lab sessions
  • Loading branch information
griff-rees authored Feb 5, 2024
2 parents 271b50d + c47f4f9 commit 822adc5
Show file tree
Hide file tree
Showing 64 changed files with 18,020 additions and 3,071 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
README_files
_reference
_sidebar*
_site*
_extensions
*.bak
80 changes: 18 additions & 62 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
CONDA_ENV_NAME: clim-recal
CONDA_ENV_PATH: environment.yml
MIN_PYTHON_VERSION: 3.9
PYTHON_MODULE_FOLDER: /home/jovyan/python/
PYTHON_MODULE_FOLDER: python/
COVERAGE_SVG_FOLDER: docs/assets/
COVERAGE_SVG_FILE_NAME: coverage.svg
# replace below with references to previous config lines
Expand All @@ -15,12 +16,11 @@ env:

on:
pull_request:
branches: ['main', 'doc-deploy']
branches: ['main', 'r-docker-refactor']
paths-ignore: ['docs/**']

push:
branches: ['main', 'doc-deploy']
paths-ignore: ['docs/**']
branches: ['main', 'r-docker-refactor']

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand All @@ -45,91 +45,47 @@ jobs:
uses: pre-commit/action@main

- name: Update pre-commit
uses: pre-commit-ci/lite-action@v1.0.1
uses: pre-commit-ci/lite-action@main
if: always()

# With no caching at all the entire ci process takes 4m 30s to complete!
pytest:
runs-on: ubuntu-latest

steps:
- name: Checkout Code Repository
uses: actions/checkout@main

- name: Build, Test and Save Test Coverage
run: |
docker compose build
docker compose up --detach
docker compose exec jupyter bash -c "conda run -n $CONDA_ENV_NAME --cwd python pytest -p no:sugar"
export JUPYTER_ID=$(docker compose ps -q jupyter)
echo "jupyter_id=$JUPYTER_ID" >> $GITHUB_ENV
echo "jupyter_id=$JUPYTER_ID"
- name: Check accessing saved jupyter_id
- name: Build Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: ${{ env.CONDA_ENV_PATH }}
auto-activate-base: false
miniforge-version: latest

- name: Test and Save Test Coverage
shell: bash -el {0}
run: |
echo ${{ env.jupyter_id }}
mamba run -n ${{ env.CONDA_ENV_NAME }} --cwd python pytest
- name: Copy test coverage results
run: |
docker cp ${{ env.jupyter_id }}:${{ env.PYTHON_MODULE_FOLDER }}${{ env.COVERAGE_SVG_PATH }} ${{ env.COVERAGE_SVG_FOLDER }}
cp ${{ env.PYTHON_MODULE_FOLDER }}${{ env.COVERAGE_SVG_PATH }} ${{ env.COVERAGE_SVG_FOLDER }}
- name: Archive coverage svg
uses: actions/upload-artifact@v3
with:
name: coverage-badge
path: ${{ env.COVERAGE_SVG_PATH }}

- name: Tear down the Stack
run: docker compose down

docs:
needs: [linter, pytest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download coverage svg
uses: actions/download-artifact@v3
with:
name: coverage-badge
path: ${{ env.GH_PAGE_PATH }}${{ env.COVERAGE_SVG_PATH }}

# Other options for documentation build for future testing outside docker
# - name: Set up conda environment
# uses: conda-incubator/setup-miniconda@v2
# with:
# activate-environment: environment.yml
#
# From https://github.com/r-lib/actions/tree/v2-branch/setup-r
# - name: Setup R
# uses: r-lib/actions/setup-r@v2

# Potentially necessary for future interactive documentation builds following uatk-spc
# - name: Install node
# uses: actions/setup-node@v2
# with:
# node-version: 18.x
# cache: 'npm'
# cache-dependency-path: web/package-lock.json
#
# - name: Build web app
# run: |
# cd web
# npm ci
# npm run build --if-present
# mv dist ../docs/_book/app

- name: Build docker quarto
run: |
# A potentially quicker build option to try in future, requires running in detatched mode
# DOCKER_BUILDKIT=1 docker build --no-cache -f compose/docs/Dockerfile --target builder --tag 'clim-recal-docs' .
docker compose build
docker compose up --detach
docker cp $(docker compose ps -q docs):/usr/local/apache2/htdocs/ ${{ env.GH_PAGE_PATH }}
- name: Publish
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ env.GH_PAGE_PATH }}
keep_files: false
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: "R|data"
exclude: "data"
repos:
- repo: https://github.com/psf/black
rev: "23.9.1"
rev: "23.12.1"
hooks:
- id: black-jupyter

Expand All @@ -27,13 +27,13 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/hadialqattan/pycln
rev: v2.2.2
rev: v2.4.0
hooks:
- id: pycln
args: ["python/"]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
Expand Down
Loading

0 comments on commit 822adc5

Please sign in to comment.