-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add test of dev container #13
Changes from all commits
7f0df2a
7af340c
4e47a26
e82d27f
cb4f241
45f8788
11be6ca
7b45371
339bca7
313353c
3cc0dc0
d884920
de2d467
9557043
275e04b
596189f
b692acf
9fd4e1e
8280ee1
8a93100
fe2b23e
b217131
35b169d
3d95ba6
1b64daa
69e9483
07dd6f6
0b37773
07f66f8
f7426e2
4153dce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test research template dev container | ||
|
||
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: Test dev container | ||
uses: devcontainers/ci@a56d055efecd725e8cfe370543b6071b79989cc8 # v0.3.1900000349 | ||
with: | ||
runCmd: ./research-template/research-template-docker/tests/dev_container.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,15 @@ default: | |
build: | ||
docker build . -t research-template | ||
|
||
smoke-test: | ||
docker run --rm research-template ls /opt/venv/bin/python3.10 | ||
check-image-exists: | ||
# Extra brackets are for Just escaping. | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the image didn't exist, then wouldn't Docker tell us? What's the benefit of this check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do However, Docker will then immediately try and pull an arbitrary I dislike this behaviour a lot. So this is a preventative measure to ensure that we only run a local image. The alternative would be to refer to a local image with a name that we do control like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As elsewhere, I'm not too tied to this specifically, but I'm inclined to merge this now as it's been open a while, and get the benefit of having the tests running. If we decide this could work better, this is OK, and would be a reasonable follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying. That is, indeed, very dislikable behaviour. |
||
docker image inspect --format='{{{{.Id}}}}' research-template | ||
|
||
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-install: check-image-exists | ||
docker run -i --entrypoint /bin/bash research-template < ./tests/r_studio.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
# Check the OpenSAFELY research-template example runs. | ||
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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/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. | ||
|
||
# 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=$(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")) | ||
|
||
[ "$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' | ||
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=$(docker run "$research_template_image" /opt/venv/bin/python3.10 -m pip freeze) | ||
diff <(echo "$python_docker_packages") <(echo "$python_installed_packages") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
/opt/venv/bin/python3.10 --version |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking out and running opensafely/research-template seems like unnecessarily tight coupling to me. What are the advantages over, say, checking in a simple
dataset_definition.py
to this repo and callingopensafely exec
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this test is to check end-to-end that the dev container setup in
research-template
runs (which is a little indirect, I agree).However, it was suggested originally to keep this tests here rather than in the
research-template
repository.The reason to checkout the repository is so that we build a dev container from the
.devcontainer
configuration there.That said, I'm not sure if it's necessary to run the full research-template project (which is also tested when on PRs to that repository).
The only real extra pieces of installation that happen in the research-template
.devcontainer
configuration are:So maybe it's sufficient to check those are installed correctly (by running and importing respectively).
(It's also possible that those could move in future to here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to this being moved or restructured, but maybe that's the subject of a subsequent PR.