From 91ea8051b26911f4c6ee261d31b2fc1261a3cfb0 Mon Sep 17 00:00:00 2001 From: Dan Stefaniuk Date: Tue, 3 Oct 2023 14:31:22 +0100 Subject: [PATCH] Make the test and example working --- scripts/docker/docker.lib.sh | 11 ++++++----- scripts/docker/docker.mk | 1 + scripts/docker/examples/python/.tool-versions | 2 ++ .../python/assets/hello_world/requirements.txt | 14 ++++++++++++-- scripts/docker/tests/.tool-versions | 2 ++ scripts/docker/tests/docker.test.sh | 1 + 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 scripts/docker/examples/python/.tool-versions create mode 100644 scripts/docker/tests/.tool-versions diff --git a/scripts/docker/docker.lib.sh b/scripts/docker/docker.lib.sh index aecc15b1..193983ee 100644 --- a/scripts/docker/docker.lib.sh +++ b/scripts/docker/docker.lib.sh @@ -11,8 +11,9 @@ set -euo pipefail # $ source ./docker.lib.sh # # Arguments (provided as environment variables): -# DOCKER_IMAGE=ghcr.io/org/repo # Docker image name -# DOCKER_TITLE="My Docker image" # Docker image title +# DOCKER_IMAGE=ghcr.io/org/repo # Docker image name +# DOCKER_TITLE="My Docker image" # Docker image title +# TOOL_VERSIONS=$project_dir/.tool-versions # Path to the tool versions file # ============================================================================== # Functions to be used with custom images. @@ -164,7 +165,7 @@ function docker-get-image-version-and-pull() { # Get the image full version from the '.tool-versions' file, # match it by name and version regex, if given. - local versions_file="$(git rev-parse --show-toplevel)/.tool-versions" + local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}" local version="latest" if [ -f "$versions_file" ]; then line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-'.*'}") @@ -217,13 +218,13 @@ function _create-effective-dockerfile() { function _replace-image-latest-by-specific-version() { local dir=${dir:-$PWD} - local versions_file=$(git rev-parse --show-toplevel)/.tool-versions + local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}" local dockerfile="${dir}/Dockerfile.effective" local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} if [ -f "$versions_file" ]; then # First, list the entries specific for Docker to take precedence, then the rest but exclude comments - content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" | grep -v "^#") + content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" ||: | grep -v "^#") echo "$content" | while IFS= read -r line; do [ -z "$line" ] && continue line=$(echo "$line" | sed "s/^#\s*//; s/\s*#.*$//" | sed "s;docker/;;") diff --git a/scripts/docker/docker.mk b/scripts/docker/docker.mk index 83e26b4d..2ad92b4d 100644 --- a/scripts/docker/docker.mk +++ b/scripts/docker/docker.mk @@ -45,6 +45,7 @@ docker-example-build: # Build Docker example @ExamplesAndTests cd scripts/docker/examples/python DOCKER_IMAGE=repository-template/docker-example-python DOCKER_TITLE="Repository Template Docker Python Example" + TOOL_VERSIONS="$(shell git rev-parse --show-toplevel)/scripts/docker/examples/python/.tool-versions" docker-build docker-example-lint: # Lint Docker example @ExamplesAndTests diff --git a/scripts/docker/examples/python/.tool-versions b/scripts/docker/examples/python/.tool-versions new file mode 100644 index 00000000..92093116 --- /dev/null +++ b/scripts/docker/examples/python/.tool-versions @@ -0,0 +1,2 @@ +# python, SEE: https://hub.docker.com/_/python/tags +# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86 diff --git a/scripts/docker/examples/python/assets/hello_world/requirements.txt b/scripts/docker/examples/python/assets/hello_world/requirements.txt index 09909f8d..ae33eb71 100644 --- a/scripts/docker/examples/python/assets/hello_world/requirements.txt +++ b/scripts/docker/examples/python/assets/hello_world/requirements.txt @@ -1,2 +1,12 @@ -flask==2.3.2 -Flask-WTF==1.1.1 +blinker==1.6.2 +click==8.1.7 +Flask-WTF==1.2.0 +Flask==2.3.3 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +pip==23.1.2 +setuptools==65.5.1 +Werkzeug==3.0.0 +wheel==0.41.1 +WTForms==3.0.1 diff --git a/scripts/docker/tests/.tool-versions b/scripts/docker/tests/.tool-versions new file mode 100644 index 00000000..92093116 --- /dev/null +++ b/scripts/docker/tests/.tool-versions @@ -0,0 +1,2 @@ +# python, SEE: https://hub.docker.com/_/python/tags +# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86 diff --git a/scripts/docker/tests/docker.test.sh b/scripts/docker/tests/docker.test.sh index 4f66887f..6ab8378e 100755 --- a/scripts/docker/tests/docker.test.sh +++ b/scripts/docker/tests/docker.test.sh @@ -74,6 +74,7 @@ function test-docker-build() { function test-docker-image-from-signature() { # Arrange + TOOL_VERSIONS="$(git rev-parse --show-toplevel)/scripts/docker/tests/.tool-versions" cp Dockerfile Dockerfile.effective # Act _replace-image-latest-by-specific-version