From 7f0df2aab8d80b586b4f5a01bcef53281877359c Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 3 May 2024 18:05:21 +0100 Subject: [PATCH 01/31] Use same operating system consistently In GitHub Actions workflow. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40c6bd1..9c03488 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,7 +46,7 @@ jobs: publish: needs: [build-and-test] - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest permissions: contents: read From 7af340c5316a2d16d4e141209c9fffdf10fb7be5 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 3 May 2024 18:06:04 +0100 Subject: [PATCH 02/31] Load the Docker image by file instead of stdin It's a simpler command. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9c03488..9dda7ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,7 +67,7 @@ jobs: path: /tmp/image - name: Import docker image - run: gunzip -c /tmp/image/research-template.tar.gz | docker load + run: docker load --input /tmp/image/research-template.tar.gz - name: Publish image run: | From 4e47a26bf8e63fc9c21078527e3cbc8db642f871 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 3 May 2024 17:28:38 +0100 Subject: [PATCH 03/31] Speed up saving image Using `pigz` cuts the compression time from about 4 minutes to 2 minutes in the default 4 core GitHub Actions runner. The `upload-artifact` action also compresses with `zlib` which is redundant, so let's disable this to speed up the upload step. --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9dda7ab..11a3f7d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,13 +35,15 @@ jobs: - name: Save docker image run: | - docker save research-template | gzip > /tmp/research-template.tar.gz + docker save research-template | pigz > /tmp/research-template.tar.gz - name: Upload docker image uses: actions/upload-artifact@v4 with: name: research-template-image path: /tmp/research-template.tar.gz + # Disable compression; the file is already compressed + compression-level: 0 publish: needs: [build-and-test] From e82d27f5c741a6308ef49a927c0413be4d9382c7 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 3 May 2024 18:07:19 +0100 Subject: [PATCH 04/31] Use faster compression option One-off comparison in GitHub Actions with the default 4 core runner: * default `pigz`: 1.7G file size, 1m 49s * `--fast`: 1.9G file size, 1m 16s The upload and download time for the file compressed with default settings is about 10 seconds (turning compression off for the upload). --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11a3f7d..d166139 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Save docker image run: | - docker save research-template | pigz > /tmp/research-template.tar.gz + docker save research-template | pigz --fast > /tmp/research-template.tar.gz - name: Upload docker image uses: actions/upload-artifact@v4 From cb4f2412ba8fcc657a1669d8c6bb21174f21c54d Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Fri, 3 May 2024 17:04:56 +0100 Subject: [PATCH 05/31] Add minimal test for dev container This is a separate job so that we can easily and cleanly have the research-template repository checked out. We could consider moving the smoke test here, although it's maybe advantageous to have that fail early, before the Docker image is compressed (because that's a slow step). --- .github/workflows/main.yml | 34 +++++++++++++++++++++++++++++++++- tests/dev_container.sh | 15 +++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 tests/dev_container.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d166139..ed044e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,8 +45,40 @@ jobs: # Disable compression; the file is already compressed compression-level: 0 - publish: + test-devcontainer: needs: [build-and-test] + runs-on: ubuntu-latest + + steps: + - name: Download Docker image + uses: actions/download-artifact@v4 + with: + name: research-template-image + path: /tmp/image + + - name: Import Docker image + run: docker load --input /tmp/image/research-template.tar.gz + + - name: Tag Docker image for use with dev container + run: docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:v0 + + - name: Checkout research template temporary devcontainer dev branch + uses: actions/checkout@v4 + with: + repository: opensafely/research-template + + - name: Checkout research-template-docker repository in subdirectory + uses: actions/checkout@v4 + with: + path: 'research-template/research-template-docker' + + - name: Build and run dev container task + uses: devcontainers/ci@v0.3 + with: + runCmd: ./research-template/research-template-docker/tests/dev_container.sh + + publish: + needs: [build-and-test, test-devcontainer] runs-on: ubuntu-latest diff --git a/tests/dev_container.sh b/tests/dev_container.sh new file mode 100755 index 0000000..e395ef4 --- /dev/null +++ b/tests/dev_container.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euxo pipefail + +# Check that we are the rstudio user. +[ "$(whoami)" == 'rstudio' ] + +# Check the OpenSAFELY research-template example runs. +opensafely run run_all + +# Check the RStudio server is running. +curl -L 'http://localhost:8787' | grep 'RStudio' + +# Check the RStudio server installation. +sudo rstudio-server stop +sudo rstudio-server verify-installation From 45f8788c7da1e8ab8115ed28b81ed6f1741250e7 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 16 May 2024 13:33:43 +0100 Subject: [PATCH 06/31] Check Python packages in dev container Check these are the same as the OpenSAFELY Python Docker image. --- tests/dev_container.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/dev_container.sh b/tests/dev_container.sh index e395ef4..cc48063 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -7,6 +7,15 @@ set -euxo pipefail # Check the OpenSAFELY research-template example runs. opensafely run run_all +# Check that the Python packages in the OpenSAFELY Python image are available in the dev container. +# This checks package names and versions. +python_image_version='v2' +opensafely pull "python:$python_image_version" + +docker_python_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) +local_python_packages=$(/opt/venv/bin/python3.10 -m pip freeze) +diff <(echo "$local_python_packages") <(echo "$docker_python_packages") + # Check the RStudio server is running. curl -L 'http://localhost:8787' | grep 'RStudio' From 11be6ca1c0024a50c17ea672a5ee79234eb99625 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 9 May 2024 19:15:34 +0100 Subject: [PATCH 07/31] Check Docker image version in `devcontainer.json` It needs to match that which we tag locally, otherwise we'll end up pulling the image instead of using the locally built image. --- .github/workflows/main.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed044e1..4d65ecc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,7 @@ name: CI env: IMAGE_NAME: research-template + IMAGE_VERSION: v0 PUBLIC_IMAGE_NAME: ghcr.io/opensafely-core/research-template REGISTRY: ghcr.io @@ -60,7 +61,7 @@ jobs: run: docker load --input /tmp/image/research-template.tar.gz - name: Tag Docker image for use with dev container - run: docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:v0 + run: docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:$IMAGE_VERSION - name: Checkout research template temporary devcontainer dev branch uses: actions/checkout@v4 @@ -72,6 +73,13 @@ jobs: with: path: 'research-template/research-template-docker' + - name: Check that we have correct version of image in devcontainer.json + # Slightly brittle because jq doesn't strip comments + # See https://github.com/jqlang/jq/issues/1571 + run: | + devcontainer_image=$(grep -v "//" .devcontainer/devcontainer.json | jq --raw-output .image) + test "$devcontainer_image" = "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + - name: Build and run dev container task uses: devcontainers/ci@v0.3 with: @@ -106,7 +114,7 @@ jobs: - name: Publish image run: | echo ${{ secrets.GITHUB_TOKEN }} | docker login $REGISTRY -u ${{ github.actor }} --password-stdin - docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:v0 + docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:$IMAGE_VERSION docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:latest - docker push $PUBLIC_IMAGE_NAME:v0 + docker push $PUBLIC_IMAGE_NAME:$IMAGE_VERSION docker push $PUBLIC_IMAGE_NAME:latest From 7b45371a3901ad5f1911aca190d932f03d5bef05 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 15 May 2024 15:54:53 +0100 Subject: [PATCH 08/31] Strip `devcontainer.json` comments more robustly There may be better software out there to do this, but this is available in Ubuntu's repositories, without having to manually download a software release. Hopefully, `jq` eventually gets functionality to handle this without needing another package. --- .github/workflows/main.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d65ecc..72bc133 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -61,7 +61,7 @@ jobs: run: docker load --input /tmp/image/research-template.tar.gz - name: Tag Docker image for use with dev container - run: docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:$IMAGE_VERSION + run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" - name: Checkout research template temporary devcontainer dev branch uses: actions/checkout@v4 @@ -73,11 +73,16 @@ jobs: with: path: 'research-template/research-template-docker' - - name: Check that we have correct version of image in devcontainer.json - # Slightly brittle because jq doesn't strip comments + - name: Install demjson package for jsonlint + # Necessary because jq doesn't yet have an option to strip comments. # See https://github.com/jqlang/jq/issues/1571 run: | - devcontainer_image=$(grep -v "//" .devcontainer/devcontainer.json | jq --raw-output .image) + sudo apt-get update + sudo apt-get install python3-demjson + + - name: Check that we have correct version of image in devcontainer.json + run: | + devcontainer_image=$(jsonlint --allow comments --format-compactly ".devcontainer/devcontainer.json" | jq --raw-output .image) test "$devcontainer_image" = "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" - name: Build and run dev container task From 339bca7654880bb109ba7f10debe03a3698b514f Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 16 May 2024 08:41:47 +0100 Subject: [PATCH 09/31] Consistently double quote shell variables The lack of double quotes for these variables results in a `shellcheck` warning: https://www.shellcheck.net/wiki/SC2086 Since double quotes are now used elsewhere, it seems reasonable to add them throughout for consistency in the edited file. Quotes are not absolutely necessary given the specific values that are being used here; there are no spaces or filename expansions there. However, it's more difficult to reason that through for each variable, than simply making them safe by quoting. --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 72bc133..1c5011d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -118,8 +118,8 @@ jobs: - name: Publish image run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login $REGISTRY -u ${{ github.actor }} --password-stdin - docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:$IMAGE_VERSION - docker tag $IMAGE_NAME $PUBLIC_IMAGE_NAME:latest - docker push $PUBLIC_IMAGE_NAME:$IMAGE_VERSION - docker push $PUBLIC_IMAGE_NAME:latest + echo ${{ secrets.GITHUB_TOKEN }} | docker login "$REGISTRY" -u ${{ github.actor }} --password-stdin + docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:latest" + docker push "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + docker push "$PUBLIC_IMAGE_NAME:latest" From 313353cc9ed4f6a948f72c7937b2fb32c8533d39 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 15 May 2024 15:50:13 +0100 Subject: [PATCH 10/31] Check R packages in dev container As the comments explain, the R packaging situation is slightly complicated. We have additional packages due to the Rocker image. Some of these are duplicates of those in the OpenSAFELY R image; some with the same version and some with a different version. An alternative approach might have been to: * copy the OpenSAFELY R packages to a path that is unique * add that library tree to the front of `.libPaths`, so these packages always take precedence over other installed versions * when comparing, compare the `installed_packages` in the specific OpenSAFELY library tree of interest: ```r installed.packages(lib.loc="/usr/local/lib/R/opensafely-site-library") ``` taken from the OpenSAFELY image. That would remove the need for the exemptions when checking. Fow now, it's possibly more useful still being aware of these additional packages and checking for them explicitly. --- tests/dev_container.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/dev_container.sh b/tests/dev_container.sh index cc48063..282c8f6 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -7,6 +7,37 @@ set -euxo pipefail # Check the OpenSAFELY research-template example runs. opensafely run run_all +# Check that the R packages in the OpenSAFELY R image are available in the dev container. +# The R setup we have leads to two sources of packages. +# As a result, this only compares package names; +# some packages are installed multiple times with different version numbers. +# See https://github.com/opensafely-core/research-template-docker/issues/22 + +# These packages are known to be extra to the local installation. +r_installed_known_extra_packages=$(cat <<-END +"docopt" +"littler" +"spatial" +END +) + +# This function expects a CSV format with header line: +# "Package","Version" +# "SomeRPackage","1.0" +extract_quoted_package_names_from_csv() { + tail -n +2 | \ + cut -d ',' -f1 | \ + sort -u +} + +r_docker_packages=$(curl 'https://raw.githubusercontent.com/opensafely-core/r-docker/main/packages.csv' | + extract_quoted_package_names_from_csv) +r_installed_packages=$(Rscript -e 'write.csv(installed.packages()[, c("Package", "Version")], row.names = FALSE)' | + extract_quoted_package_names_from_csv) +r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo "$r_installed_packages")) + +[ "$r_packages_extra_to_local_install" == "$r_installed_known_extra_packages" ] + # Check that the Python packages in the OpenSAFELY Python image are available in the dev container. # This checks package names and versions. python_image_version='v2' From 3cc0dc09555075a2143fefdcfa07381ebb0e3a8d Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 16 May 2024 13:47:10 +0100 Subject: [PATCH 11/31] Remove unused `__init__.py` --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 From d884920510994a4d79f907617de39d1d292f6359 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 16 May 2024 13:49:41 +0100 Subject: [PATCH 12/31] Rename variables for consistency With the R checks. --- tests/dev_container.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/dev_container.sh b/tests/dev_container.sh index 282c8f6..f6a9425 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -43,9 +43,9 @@ r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo python_image_version='v2' opensafely pull "python:$python_image_version" -docker_python_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) -local_python_packages=$(/opt/venv/bin/python3.10 -m pip freeze) -diff <(echo "$local_python_packages") <(echo "$docker_python_packages") +python_docker_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) +python_installed_packages=$(/opt/venv/bin/python3.10 -m pip freeze) +diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") # Check the RStudio server is running. curl -L 'http://localhost:8787' | grep 'RStudio' From de2d4677234aedf9aab878330880943cbbe80227 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Tue, 21 May 2024 15:23:18 +0100 Subject: [PATCH 13/31] Rename workflow step for clarity This is a remnant from when the improved dev container configuration was being worked on in a separate branch in the `research-template` repository. It no longer applies; we're checking out the `main` branch. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c5011d..e5978ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: - name: Tag Docker image for use with dev container run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" - - name: Checkout research template temporary devcontainer dev branch + - name: Checkout research template repository uses: actions/checkout@v4 with: repository: opensafely/research-template From 955704344ce6f48ebab9129d99bad777c2b957ff Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 12:53:40 +0100 Subject: [PATCH 14/31] Pin `devcontainers/ci` action to a commit Wasn't sure if Dependabot would upgrade this, because, for whatever reason, the commits associated with releases in `devcontainers/ci` are not associated with branches. Tested it, and Dependabot can still upgrade the action version. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5978ab..86f0dab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -86,7 +86,7 @@ jobs: test "$devcontainer_image" = "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" - name: Build and run dev container task - uses: devcontainers/ci@v0.3 + uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 with: runCmd: ./research-template/research-template-docker/tests/dev_container.sh From 275e04b887b2f5185ce7ba2f8f1be493195976ac Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 17:25:13 +0100 Subject: [PATCH 15/31] Split package checks out from dev container checks --- .github/workflows/main.yml | 6 +++--- tests/dev_container.sh | 40 ------------------------------------ tests/packages.sh | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 43 deletions(-) create mode 100755 tests/packages.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86f0dab..1723fa9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,7 +46,7 @@ jobs: # Disable compression; the file is already compressed compression-level: 0 - test-devcontainer: + test-packages: needs: [build-and-test] runs-on: ubuntu-latest @@ -88,10 +88,10 @@ jobs: - name: Build and run dev container task uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 with: - runCmd: ./research-template/research-template-docker/tests/dev_container.sh + runCmd: ./research-template/research-template-docker/tests/packages.sh publish: - needs: [build-and-test, test-devcontainer] + needs: [build-and-test, test-packages] runs-on: ubuntu-latest diff --git a/tests/dev_container.sh b/tests/dev_container.sh index f6a9425..e395ef4 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -7,46 +7,6 @@ set -euxo pipefail # Check the OpenSAFELY research-template example runs. opensafely run run_all -# Check that the R packages in the OpenSAFELY R image are available in the dev container. -# The R setup we have leads to two sources of packages. -# As a result, this only compares package names; -# some packages are installed multiple times with different version numbers. -# See https://github.com/opensafely-core/research-template-docker/issues/22 - -# These packages are known to be extra to the local installation. -r_installed_known_extra_packages=$(cat <<-END -"docopt" -"littler" -"spatial" -END -) - -# This function expects a CSV format with header line: -# "Package","Version" -# "SomeRPackage","1.0" -extract_quoted_package_names_from_csv() { - tail -n +2 | \ - cut -d ',' -f1 | \ - sort -u -} - -r_docker_packages=$(curl 'https://raw.githubusercontent.com/opensafely-core/r-docker/main/packages.csv' | - extract_quoted_package_names_from_csv) -r_installed_packages=$(Rscript -e 'write.csv(installed.packages()[, c("Package", "Version")], row.names = FALSE)' | - extract_quoted_package_names_from_csv) -r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo "$r_installed_packages")) - -[ "$r_packages_extra_to_local_install" == "$r_installed_known_extra_packages" ] - -# Check that the Python packages in the OpenSAFELY Python image are available in the dev container. -# This checks package names and versions. -python_image_version='v2' -opensafely pull "python:$python_image_version" - -python_docker_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) -python_installed_packages=$(/opt/venv/bin/python3.10 -m pip freeze) -diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") - # Check the RStudio server is running. curl -L 'http://localhost:8787' | grep 'RStudio' diff --git a/tests/packages.sh b/tests/packages.sh new file mode 100755 index 0000000..c246040 --- /dev/null +++ b/tests/packages.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -euxo pipefail + +# Check that the R packages in the OpenSAFELY R image are available in the dev container. +# The R setup we have leads to two sources of packages. +# As a result, this only compares package names; +# some packages are installed multiple times with different version numbers. +# See https://github.com/opensafely-core/research-template-docker/issues/22 + +# These packages are known to be extra to the local installation. +r_installed_known_extra_packages=$(cat <<-END +"docopt" +"littler" +"spatial" +END +) + +# This function expects a CSV format with header line: +# "Package","Version" +# "SomeRPackage","1.0" +extract_quoted_package_names_from_csv() { + tail -n +2 | \ + cut -d ',' -f1 | \ + sort -u +} + +r_docker_packages=$(curl 'https://raw.githubusercontent.com/opensafely-core/r-docker/main/packages.csv' | + extract_quoted_package_names_from_csv) +r_installed_packages=$(Rscript -e 'write.csv(installed.packages()[, c("Package", "Version")], row.names = FALSE)' | + extract_quoted_package_names_from_csv) +r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo "$r_installed_packages")) + +[ "$r_packages_extra_to_local_install" == "$r_installed_known_extra_packages" ] + +# Check that the Python packages in the OpenSAFELY Python image are available in the dev container. +# This checks package names and versions. +python_image_version='v2' +opensafely pull "python:$python_image_version" + +python_docker_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) +python_installed_packages=$(/opt/venv/bin/python3.10 -m pip freeze) +diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") From 596189f9af09ee64e0a84a7403b2080bedd64a77 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 17:37:39 +0100 Subject: [PATCH 16/31] Remove explicit use of `opensafely` from test We don't strictly need `opensafely` here to run the test, so we can remove this dependency. However, we still need to run this in a dev container as things stand, because: 1. There's no easy way to get a canonical list of Python packages after installation, that we can compare to the known `requirements.txt` for the Python v2 image. The `requirements.txt` in the OpenSAFELY Python Docker image repository there will not match the frozen virtual environment; for example, some packages have extras listed in the `requirements.txt` that then show as individually installed packages in the virtual environment. 2. The `research-template-docker` image does not install Docker, so we can't directly run Docker. For the dev container, the `docker-in-docker` feature is installed. --- tests/packages.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/packages.sh b/tests/packages.sh index c246040..54a1ff6 100755 --- a/tests/packages.sh +++ b/tests/packages.sh @@ -35,8 +35,10 @@ r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo # Check that the Python packages in the OpenSAFELY Python image are available in the dev container. # This checks package names and versions. python_image_version='v2' -opensafely pull "python:$python_image_version" +python_image="ghcr.io/opensafely-core/python:$python_image_version" -python_docker_packages=$(docker run "ghcr.io/opensafely-core/python:$python_image_version" python -m pip freeze) +docker pull "$python_image" + +python_docker_packages=$(docker run "$python_image" python -m pip freeze) python_installed_packages=$(/opt/venv/bin/python3.10 -m pip freeze) diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") From b692acf8d24a61a2032cd3fa24ebbf9009e8278e Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 18:00:50 +0100 Subject: [PATCH 17/31] Add scheduled check of research-template container This is a minimal workflow that tests the `research-template` dev container daily, using whichever Docker image is specified in the `devcontainer.json` in the `main` branch there. It could be extended to run on every build with the image to be tested. This workflow should also report to Slack on failure, instead of whoever last edited the cron line. --- .github/workflows/dev_container.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/dev_container.yml diff --git a/.github/workflows/dev_container.yml b/.github/workflows/dev_container.yml new file mode 100644 index 0000000..4bbf8b5 --- /dev/null +++ b/.github/workflows/dev_container.yml @@ -0,0 +1,25 @@ +name: Check research template dev container functions + +on: + schedule: + - cron: "18 8 * * *" + workflow_dispatch: + +jobs: + dev-container: + runs-on: ubuntu-latest + steps: + - name: Checkout research-template repository + uses: actions/checkout@v4 + with: + repository: 'opensafely/research-template' + + - name: Checkout research-template-docker repository in subdirectory + uses: actions/checkout@v4 + with: + path: 'research-template/research-template-docker' + + - name: Build and run dev container task + uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 + with: + runCmd: ./research-template/research-template-docker/tests/dev_container.sh From 9fd4e1e02a7d5209442ebf54262e178075264fc6 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 18:12:06 +0100 Subject: [PATCH 18/31] Add comment to workflow explaining test setup --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1723fa9..c84356b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,6 +85,9 @@ jobs: devcontainer_image=$(jsonlint --allow comments --format-compactly ".devcontainer/devcontainer.json" | jq --raw-output .image) test "$devcontainer_image" = "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + # It is necessary to run these tests in the dev container, + # because they currently require Docker to correctly discover + # the state of the Python packages in the Python action image. - name: Build and run dev container task uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 with: From 8280ee146c4d2516d947e62b67e5dcdbe0f5f9e8 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 18:16:49 +0100 Subject: [PATCH 19/31] Add comment to test script --- tests/packages.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/packages.sh b/tests/packages.sh index 54a1ff6..f13d245 100755 --- a/tests/packages.sh +++ b/tests/packages.sh @@ -1,6 +1,10 @@ #!/bin/bash set -euxo pipefail +# These checks assume that the packages do not change +# between building the Docker image in this repository, +# and checking the packages against the OpenSAFELY R and Python images. + # Check that the R packages in the OpenSAFELY R image are available in the dev container. # The R setup we have leads to two sources of packages. # As a result, this only compares package names; From 8a931009a9c4792a2de0990eef0014dd22781f16 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 18:49:00 +0100 Subject: [PATCH 20/31] Amend comment --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c84356b..5e550a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -88,7 +88,7 @@ jobs: # It is necessary to run these tests in the dev container, # because they currently require Docker to correctly discover # the state of the Python packages in the Python action image. - - name: Build and run dev container task + - name: Build and run dev container test task uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 with: runCmd: ./research-template/research-template-docker/tests/packages.sh From fe2b23e9ade1a56f1467d7ee53b4651f1d0258a1 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 18:35:39 +0100 Subject: [PATCH 21/31] Tag Docker image for testing with `dev` This means that: * it's clearer what's going on * we can't accidentally pull a `dev` image as we don't have one --- .github/workflows/main.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e550a9..f1c3342 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,8 +60,8 @@ jobs: - name: Import Docker image run: docker load --input /tmp/image/research-template.tar.gz - - name: Tag Docker image for use with dev container - run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + - name: Tag Docker image for testing + run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:dev" - name: Checkout research template repository uses: actions/checkout@v4 @@ -80,10 +80,13 @@ jobs: sudo apt-get update sudo apt-get install python3-demjson - - name: Check that we have correct version of image in devcontainer.json + - name: Amend research-template devcontainer.json to use dev image run: | - devcontainer_image=$(jsonlint --allow comments --format-compactly ".devcontainer/devcontainer.json" | jq --raw-output .image) - test "$devcontainer_image" = "$PUBLIC_IMAGE_NAME:$IMAGE_VERSION" + # Necessary because jq doesn't give the option to write to a file. + # See https://github.com/jqlang/jq/issues/2418 + cleaned_json=$(jsonlint --allow comments --format-compactly ".devcontainer/devcontainer.json" | + jq --arg variable "$PUBLIC_IMAGE_NAME:dev" '.image |= $variable') + echo "$cleaned_json" > ".devcontainer/devcontainer.json" # It is necessary to run these tests in the dev container, # because they currently require Docker to correctly discover From b217131958291936e88af40e27a23d0dc0a784c7 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 21:40:46 +0100 Subject: [PATCH 22/31] Rework package test to work without dev container This removes the dependency of this test on the `research-template` repository. --- .github/workflows/main.yml | 42 +++++++++----------------------------- justfile | 5 ++++- tests/packages.sh | 10 +++++++-- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f1c3342..43171ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,14 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install just + uses: "opensafely-core/setup-action@v1" + with: + install-just: true + - name: Download Docker image uses: actions/download-artifact@v4 with: @@ -63,38 +71,8 @@ jobs: - name: Tag Docker image for testing run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:dev" - - name: Checkout research template repository - uses: actions/checkout@v4 - with: - repository: opensafely/research-template - - - name: Checkout research-template-docker repository in subdirectory - uses: actions/checkout@v4 - with: - path: 'research-template/research-template-docker' - - - name: Install demjson package for jsonlint - # Necessary because jq doesn't yet have an option to strip comments. - # See https://github.com/jqlang/jq/issues/1571 - run: | - sudo apt-get update - sudo apt-get install python3-demjson - - - name: Amend research-template devcontainer.json to use dev image - run: | - # Necessary because jq doesn't give the option to write to a file. - # See https://github.com/jqlang/jq/issues/2418 - cleaned_json=$(jsonlint --allow comments --format-compactly ".devcontainer/devcontainer.json" | - jq --arg variable "$PUBLIC_IMAGE_NAME:dev" '.image |= $variable') - echo "$cleaned_json" > ".devcontainer/devcontainer.json" - - # It is necessary to run these tests in the dev container, - # because they currently require Docker to correctly discover - # the state of the Python packages in the Python action image. - - name: Build and run dev container test task - uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 - with: - runCmd: ./research-template/research-template-docker/tests/packages.sh + - name: Check packages + run: just packages-test publish: needs: [build-and-test, test-packages] diff --git a/justfile b/justfile index afc71bc..016e9f4 100644 --- a/justfile +++ b/justfile @@ -8,4 +8,7 @@ build: docker build . -t research-template smoke-test: - docker run --rm research-template ls /opt/venv/bin/python3.10 \ No newline at end of file + docker run --rm research-template ls /opt/venv/bin/python3.10 + +packages-test: + tests/packages.sh diff --git a/tests/packages.sh b/tests/packages.sh index f13d245..ff9fcca 100755 --- a/tests/packages.sh +++ b/tests/packages.sh @@ -1,6 +1,12 @@ #!/bin/bash set -euxo pipefail +# This test requires: +# * Docker +# * the availability of the research-template Docker image +research_template_image="research-template" +docker image inspect "$research_template_image" > /dev/null + # These checks assume that the packages do not change # between building the Docker image in this repository, # and checking the packages against the OpenSAFELY R and Python images. @@ -30,7 +36,7 @@ extract_quoted_package_names_from_csv() { r_docker_packages=$(curl 'https://raw.githubusercontent.com/opensafely-core/r-docker/main/packages.csv' | extract_quoted_package_names_from_csv) -r_installed_packages=$(Rscript -e 'write.csv(installed.packages()[, c("Package", "Version")], row.names = FALSE)' | +r_installed_packages=$(docker run -i "$research_template_image" /bin/bash -c "Rscript -e 'write.csv(installed.packages()[, c(\"Package\", \"Version\")], row.names = FALSE)'" | extract_quoted_package_names_from_csv) r_packages_extra_to_local_install=$(comm -13 <(echo "$r_docker_packages") <(echo "$r_installed_packages")) @@ -44,5 +50,5 @@ python_image="ghcr.io/opensafely-core/python:$python_image_version" docker pull "$python_image" python_docker_packages=$(docker run "$python_image" python -m pip freeze) -python_installed_packages=$(/opt/venv/bin/python3.10 -m pip freeze) +python_installed_packages=$(docker run "$research_template_image" /opt/venv/bin/python3.10 -m pip freeze) diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") From 35b169db7315f00124c7f2241dc645e1c9a39267 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Thu, 23 May 2024 21:42:46 +0100 Subject: [PATCH 23/31] Rename `justfile` test recipes So they are `test` first; this is what we do in other repositories (where we have `test-dev`). --- .github/workflows/main.yml | 6 +++--- justfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 43171ca..39e2526 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,8 +31,8 @@ jobs: - name: Build docker image run: just build - - name: Test docker image - run: just smoke-test + - name: Smoke test docker image + run: just test-smoke - name: Save docker image run: | @@ -72,7 +72,7 @@ jobs: run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:dev" - name: Check packages - run: just packages-test + run: just test-packages publish: needs: [build-and-test, test-packages] diff --git a/justfile b/justfile index 016e9f4..ca13c2f 100644 --- a/justfile +++ b/justfile @@ -7,8 +7,8 @@ default: build: docker build . -t research-template -smoke-test: +test-smoke: docker run --rm research-template ls /opt/venv/bin/python3.10 -packages-test: +test-packages: tests/packages.sh From 3d95ba6502e8cebd75e597cf47569dbe4af6b156 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Tue, 28 May 2024 13:12:48 +0100 Subject: [PATCH 24/31] Move R Studio tests out of dev container checks But still retain a check that the R Studio is running in the dev container, as that's started up based on the dev container configuration. --- .github/workflows/main.yml | 7 +++++-- justfile | 3 +++ tests/dev_container.sh | 7 ------- tests/r_studio.sh | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) create mode 100755 tests/r_studio.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 39e2526..dc226c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,7 +46,7 @@ jobs: # Disable compression; the file is already compressed compression-level: 0 - test-packages: + test-docker-image: needs: [build-and-test] runs-on: ubuntu-latest @@ -74,8 +74,11 @@ jobs: - name: Check packages run: just test-packages + - name: Check R Studio installation + run: just test-rstudio + publish: - needs: [build-and-test, test-packages] + needs: [build-and-test, test-docker-image] runs-on: ubuntu-latest diff --git a/justfile b/justfile index ca13c2f..20a34a0 100644 --- a/justfile +++ b/justfile @@ -12,3 +12,6 @@ test-smoke: test-packages: tests/packages.sh + +test-rstudio: + docker run -i --entrypoint /bin/bash research-template < ./tests/r_studio.sh diff --git a/tests/dev_container.sh b/tests/dev_container.sh index e395ef4..6bc06f7 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -1,15 +1,8 @@ #!/bin/bash set -euxo pipefail -# Check that we are the rstudio user. -[ "$(whoami)" == 'rstudio' ] - # Check the OpenSAFELY research-template example runs. opensafely run run_all # Check the RStudio server is running. curl -L 'http://localhost:8787' | grep 'RStudio' - -# Check the RStudio server installation. -sudo rstudio-server stop -sudo rstudio-server verify-installation diff --git a/tests/r_studio.sh b/tests/r_studio.sh new file mode 100755 index 0000000..3eff38f --- /dev/null +++ b/tests/r_studio.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euxo pipefail + +# Check that we are the rstudio user. +[ "$(whoami)" == 'rstudio' ] + +# Check the RStudio server installation. +sudo rstudio-server verify-installation +sudo rstudio-server start + +# Check the RStudio server is running. +curl -L 'http://localhost:8787' | grep 'RStudio' + +sudo rstudio-server stop From 1b64daabd11c2a99461743b25a3950d39935300a Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Tue, 28 May 2024 13:16:06 +0100 Subject: [PATCH 25/31] Remove tagging of image This is unnecessary now. We have a local Docker image called `research-template` and we use that image name in the testing. --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc226c4..680a734 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,9 +68,6 @@ jobs: - name: Import Docker image run: docker load --input /tmp/image/research-template.tar.gz - - name: Tag Docker image for testing - run: docker tag "$IMAGE_NAME" "$PUBLIC_IMAGE_NAME:dev" - - name: Check packages run: just test-packages From 69e948309f669c330d60fa453b521f4d8b75cc9d Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Tue, 28 May 2024 13:31:41 +0100 Subject: [PATCH 26/31] Check Docker image exists before running any test From within the `justfile`. --- justfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/justfile b/justfile index 20a34a0..ad3f962 100644 --- a/justfile +++ b/justfile @@ -7,11 +7,15 @@ default: build: docker build . -t research-template -test-smoke: +check-image-exists: + # Extra brackets are for Just escaping. + docker image inspect --format='{{{{.Id}}}}' research-template + +test-smoke: check-image-exists docker run --rm research-template ls /opt/venv/bin/python3.10 -test-packages: +test-packages: check-image-exists tests/packages.sh -test-rstudio: +test-rstudio: check-image-exists docker run -i --entrypoint /bin/bash research-template < ./tests/r_studio.sh From 07dd6f6fe2ff744203d858a790e314a044300eeb Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 29 May 2024 16:22:50 +0100 Subject: [PATCH 27/31] Amend `docker load` to `docker image load` Co-authored-by: Iain Dillingham --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 680a734..c66fd96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,7 +66,7 @@ jobs: path: /tmp/image - name: Import Docker image - run: docker load --input /tmp/image/research-template.tar.gz + run: docker image load --input /tmp/image/research-template.tar.gz - name: Check packages run: just test-packages @@ -98,7 +98,7 @@ jobs: path: /tmp/image - name: Import docker image - run: docker load --input /tmp/image/research-template.tar.gz + run: docker image load --input /tmp/image/research-template.tar.gz - name: Publish image run: | From 0b37773c2ead7e3fd85dd8575bf93ee2f58bb41e Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 29 May 2024 16:42:25 +0100 Subject: [PATCH 28/31] Use consistent naming in workflows This is also consistent with the `justfile`. --- .github/workflows/dev_container.yml | 6 +++--- .github/workflows/main.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dev_container.yml b/.github/workflows/dev_container.yml index 4bbf8b5..14cb40b 100644 --- a/.github/workflows/dev_container.yml +++ b/.github/workflows/dev_container.yml @@ -1,4 +1,4 @@ -name: Check research template dev container functions +name: Test research template dev container on: schedule: @@ -18,8 +18,8 @@ jobs: uses: actions/checkout@v4 with: path: 'research-template/research-template-docker' - - - name: Build and run dev container task + + - name: Test dev container uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 with: runCmd: ./research-template/research-template-docker/tests/dev_container.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c66fd96..781a085 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,10 +68,10 @@ jobs: - name: Import Docker image run: docker image load --input /tmp/image/research-template.tar.gz - - name: Check packages + - name: Test packages run: just test-packages - - name: Check R Studio installation + - name: Test R Studio installation run: just test-rstudio publish: From 07f66f8cd2141ffc2b5a7a4e1f0e39680ce1d200 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 29 May 2024 16:49:37 +0100 Subject: [PATCH 29/31] Move smoke test to a check of Python for ehrQL This is a separate installation of Python, specifically to install ehrQL in the dev container at dev container creation time. This also means we separate out the build CI workflow from the test workflow. --- .github/workflows/main.yml | 16 ++++++++-------- justfile | 6 +++--- tests/python.sh | 4 ++++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100755 tests/python.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 781a085..ddad6ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ on: - cron: "0 12 * * SUN" jobs: - build-and-test: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -31,9 +31,6 @@ jobs: - name: Build docker image run: just build - - name: Smoke test docker image - run: just test-smoke - - name: Save docker image run: | docker save research-template | pigz --fast > /tmp/research-template.tar.gz @@ -47,7 +44,7 @@ jobs: compression-level: 0 test-docker-image: - needs: [build-and-test] + needs: build runs-on: ubuntu-latest steps: @@ -68,14 +65,17 @@ jobs: - name: Import Docker image run: docker image load --input /tmp/image/research-template.tar.gz - - name: Test packages - run: just test-packages + - name: Test Python installation + run: just test-python-install - name: Test R Studio installation run: just test-rstudio + - name: Test packages + run: just test-packages + publish: - needs: [build-and-test, test-docker-image] + needs: [build, test-docker-image] runs-on: ubuntu-latest diff --git a/justfile b/justfile index ad3f962..d2d814a 100644 --- a/justfile +++ b/justfile @@ -11,11 +11,11 @@ check-image-exists: # Extra brackets are for Just escaping. docker image inspect --format='{{{{.Id}}}}' research-template -test-smoke: check-image-exists - docker run --rm research-template ls /opt/venv/bin/python3.10 - test-packages: check-image-exists tests/packages.sh +test-python-install: check-image-exists + docker run -i --entrypoint /bin/bash research-template < ./tests/python.sh + test-rstudio: check-image-exists docker run -i --entrypoint /bin/bash research-template < ./tests/r_studio.sh diff --git a/tests/python.sh b/tests/python.sh new file mode 100755 index 0000000..e4818dc --- /dev/null +++ b/tests/python.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euxo pipefail + +/opt/venv/bin/python3.10 --version From f7426e2f06b14326205d693c4428409db0e06c79 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 29 May 2024 17:29:46 +0100 Subject: [PATCH 30/31] Rename R Studio test for consistency --- .github/workflows/main.yml | 2 +- justfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ddad6ec..6eadef0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,7 +69,7 @@ jobs: run: just test-python-install - name: Test R Studio installation - run: just test-rstudio + run: just test-rstudio-install - name: Test packages run: just test-packages diff --git a/justfile b/justfile index d2d814a..fbdbe92 100644 --- a/justfile +++ b/justfile @@ -17,5 +17,5 @@ test-packages: check-image-exists test-python-install: check-image-exists docker run -i --entrypoint /bin/bash research-template < ./tests/python.sh -test-rstudio: check-image-exists +test-rstudio-install: check-image-exists docker run -i --entrypoint /bin/bash research-template < ./tests/r_studio.sh From 4153dce65361771904c724e8c4241201406ac6e9 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 29 May 2024 17:39:25 +0100 Subject: [PATCH 31/31] Add rudimentary check for ehrQL in dev container As the comment states, we cannot check this is installed properly yet. --- tests/dev_container.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/dev_container.sh b/tests/dev_container.sh index 6bc06f7..6d88af2 100755 --- a/tests/dev_container.sh +++ b/tests/dev_container.sh @@ -6,3 +6,9 @@ opensafely run run_all # Check the RStudio server is running. curl -L 'http://localhost:8787' | grep 'RStudio' + +# This is a rudimentary placeholder test of the ehrQL installation. +# We cannot easily run ehrQL because it requires Python 3.11 to be imported, +# but the OpenSAFELY Python Docker image, and the dev container, uses Python 3.10. +# In future, we could actually try and import ehrQL through Python. +ls .devcontainer/ehrql-main/