Skip to content

Commit

Permalink
Merge pull request #1235 from docToolchain/1231-docker-port-mapping-o…
Browse files Browse the repository at this point in the history
…nly-needed-for-previewsite

fix #1231: docker: port mapping only needed for previewSite
  • Loading branch information
rdmueller committed Nov 25, 2023
2 parents cfaf161 + c84bb5c commit b5727bb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project tries to adhere to https://semver.org/spec/v2.0.0.html[Semantic

=== changed

* https://github.com/docToolchain/docToolchain/issues/1231[#1231: docker: port mapping only needed for previewSite]

== 3.1.2 - 2023-11-16

=== fixes
Expand Down
12 changes: 11 additions & 1 deletion dtcw
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,18 @@ build_command() {
local container_name=doctoolchain-${version}
container_name+="-$(date '+%Y%m%d_%H%M%S')"
pwd=$(has cygpath && cygpath -w "${PWD}" || echo "${PWD}")

PORTMAPPING=""
# Loop through the arguments
for arg in "$@"; do
if [ "$arg" == "previewSite" ]; then
PORTMAPPING="-p 8042:8042"
break
fi
done

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 \
-e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} ${PORTMAPPING} \
--entrypoint /bin/bash -v '${pwd}:/project' doctoolchain/doctoolchain:v${version}"

cmd="docker ${docker_args} -c \"doctoolchain . ${*} ${DTC_OPTS} && exit\""
Expand Down
12 changes: 11 additions & 1 deletion dtcw.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,19 @@ function build_command($environment, $version, $_args) {
}
$container_name="doctoolchain-${version}-$(date -uFormat '+%Y%m%d_%H%M%S')"
$docker_cmd = Get-Command docker

$PORTMAPPING = ""
# Loop through the arguments
foreach ($arg in $args) {
if ($arg -eq "previewSite") {
$PORTMAPPING = "-p 8042:8042"
break
}
}

# TODO: DTC_PROJECT_BRANCH is not passed into the docker environment
# See https://github.com/docToolchain/docToolchain/issues/1087
$docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}"
$docker_args = "run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} ${PORTMAPPING} --entrypoint /bin/bash -v '${PWD}:/project' doctoolchain/doctoolchain:v${version}"
$cmd = "$docker_cmd ${docker_args} -c ""doctoolchain . $_args ${DTC_OPTS} && exit "" "

} else {
Expand Down
4 changes: 2 additions & 2 deletions test/docker_environment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ teardown() {

expected_cmd="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) \
--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 -Dfile.encoding=UTF-8 && exit"
--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}"
# TODO: the mock doesn't handles quotes correctly
# assert_line "$expected_cmd"
Expand Down

0 comments on commit b5727bb

Please sign in to comment.