Skip to content

Commit

Permalink
Make the test and example working
Browse files Browse the repository at this point in the history
  • Loading branch information
stefaniuk committed Oct 3, 2023
1 parent a0eba14 commit 91ea805
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
11 changes: 6 additions & 5 deletions scripts/docker/docker.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:-'.*'}")
Expand Down Expand Up @@ -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/;;")
Expand Down
1 change: 1 addition & 0 deletions scripts/docker/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/docker/examples/python/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# python, SEE: https://hub.docker.com/_/python/tags
# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86
14 changes: 12 additions & 2 deletions scripts/docker/examples/python/assets/hello_world/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/docker/tests/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# python, SEE: https://hub.docker.com/_/python/tags
# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86
1 change: 1 addition & 0 deletions scripts/docker/tests/docker.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91ea805

Please sign in to comment.