Skip to content

Commit

Permalink
fix (closes docToolchain#829): make docker container name unique to a…
Browse files Browse the repository at this point in the history
…void conflicts

Add timestamp to the container name (YYYYmmdd_HHMMSS).
  • Loading branch information
mh182 committed May 1, 2023
1 parent bf7fdf1 commit 3da2cc4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project tries to adhere to https://semver.org/spec/v2.0.0.html[Semantic
* https://github.com/docToolchain/docToolchain/issues/395[#395 asciidoctor-diagram: ERROR: Failed to generate image: PlantUML image generation failed]
* https://github.com/docToolchain/docToolchain/issues/455[#455 Force execution to stop with failure on missing image reference]
* https://github.com/docToolchain/docToolchain/issues/621[#621: dtcw - sdkman installation check returns wrong result]
* https://github.com/docToolchain/docToolchain/issues/829[#829: Multiple run of dtcw with docker is failing because of a container name conflict]
* https://github.com/docToolchain/docToolchain/issues/831[#831: fix for generateSite: images-hrefs not correct]
* https://github.com/docToolchain/docToolchain/issues/973[#973: `dtcw getJava` doesn't work without `local`]
* https://github.com/docToolchain/docToolchain/issues/1109[#1109: docToolchain release notes contain releases twice]
Expand Down
4 changes: 3 additions & 1 deletion dtcw
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,10 @@ build_command() {
# TODO: DTC_PROJECT_BRANCH is not passed into the docker environment
# See https://github.com/docToolchain/docToolchain/issues/1087

local container_name=doctoolchain-${version}
container_name+="-$(date '+%Y%m%d_%H%M%S')"
pwd=$(has cygpath && cygpath -w "${PWD}" || echo "${PWD}")
docker_args="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) --name doctoolchain${version} \
docker_args="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) --name ${container_name} \
-e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 \
--entrypoint /bin/bash -v '${pwd}:/project' doctoolchain/doctoolchain:v${version}"

Expand Down
7 changes: 6 additions & 1 deletion test/docker_environment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ teardown() {
@test "forward call to docker" {
# No local install, but docker is present
mock_docker=$(mock_create docker)
# Replace 'date' provided by 'minimal_system' with a mock
rm "${minimal_system}/date" && mock_date=$(mock_create date)
# Use timestamp to avoid container name conflicts. Second should be enough to avoid collisions.
timestamp=20230501_145800
mock_set_output "${mock_date}" ${timestamp}

PATH="${minimal_system}" run -0 ./dtcw tasks --group doctoolchain

Expand All @@ -28,7 +33,7 @@ teardown() {
assert_line "Using environment: docker"

expected_cmd="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) \
--name doctoolchain${DTC_VERSION} -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=test \
--name doctoolchain-${DTC_VERSION}-${timestamp} -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=test \
-p 8042:8042 --entrypoint /bin/bash -v ${PWD}:/project doctoolchain/doctoolchain:v${DTC_VERSION} \
-c doctoolchain . tasks --group doctoolchain -PmainConfigFile=docToolchainConfig.groovy --warning-mode=none --no-daemon && exit"
assert_equal "$(mock_get_call_args "${mock_docker}")" "${expected_cmd}"
Expand Down

0 comments on commit 3da2cc4

Please sign in to comment.