From b7788ab862807208482a84b3ae74cc4c673e5149 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Feb 2024 14:10:32 -0500 Subject: [PATCH 1/4] fix: correctly use cache volume for herokuish builds Rather than try to mount a directory into the container and use a symlink, directly mount the volume in. Note that this requires deleting the task container prior to continuing in order to ensure the volume isn't still mounted prior to other tasks being executed. --- plugins/app-json/functions.go | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/plugins/app-json/functions.go b/plugins/app-json/functions.go index b5cf991b3..fe24ca885 100644 --- a/plugins/app-json/functions.go +++ b/plugins/app-json/functions.go @@ -47,11 +47,6 @@ func constructScript(command string, shell string, isHerokuishImage bool, isCnbI "if [[ -d '/app/.profile.d' ]]; then", " for file in /app/.profile.d/*; do source $file; done;", "fi;", - - "if [[ -d '/cache' ]]; then", - " rm -rf /tmp/cache ;", - " ln -sf /cache /tmp/cache;", - "fi;", }...) } @@ -67,14 +62,6 @@ func constructScript(command string, shell string, isHerokuishImage bool, isCnbI script = append(script, fmt.Sprintf("%s || exit 1;", command)) - if isHerokuishImage && !isCnbImage { - script = append(script, []string{ - "if [[ -d '/cache' ]]; then", - " rm -f /tmp/cache;", - "fi;", - }...) - } - return []string{shell, "-c", strings.Join(script, " ")} } @@ -164,7 +151,12 @@ func cleanupDeploymentContainer(appName string, containerID string, phase string if phase != "predeploy" { os.Setenv("DOKKU_SKIP_IMAGE_RETIRE", "true") } - return common.PlugnTrigger("scheduler-register-retired", []string{appName, containerID}...) + + if !common.ContainerRemove(containerID) { + return fmt.Errorf("Failed to remove %s execution container", phase) + } + + return nil } func executeScript(appName string, image string, imageTag string, phase string) error { @@ -211,12 +203,6 @@ func executeScript(appName string, image string, imageTag string, phase string) imageSourceType = "pack" } - cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName)) - cacheHostDir := fmt.Sprintf("%s/cache", common.AppHostRoot(appName)) - if !common.DirectoryExists(cacheDir) { - os.MkdirAll(cacheDir, 0755) - } - var dockerArgs []string if b, err := common.PlugnTriggerSetup("docker-args-deploy", []string{appName, imageTag}...).SetInput("").Output(); err == nil { words, err := shellquote.Split(strings.TrimSpace(string(b[:]))) @@ -275,7 +261,9 @@ func executeScript(appName string, image string, imageTag string, phase string) } dockerArgs = append(dockerArgs, "--label=dokku_phase_script="+phase) - dockerArgs = append(dockerArgs, "-v", cacheHostDir+":/cache") + if isHerokuishImage && !isCnbImage { + dockerArgs = append(dockerArgs, "-v", fmt.Sprintf("cache-%s:/tmp/cache", appName)) + } if os.Getenv("DOKKU_TRACE") != "" { dockerArgs = append(dockerArgs, "--env", "DOKKU_TRACE="+os.Getenv("DOKKU_TRACE")) } From 1c917a4c4404e2a53fca27af71d38d8173ecf7a5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Feb 2024 15:54:31 -0500 Subject: [PATCH 2/4] fix: remove reference to cache dir --- tests/unit/repo.bats | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/unit/repo.bats b/tests/unit/repo.bats index 6a74c315d..02678d813 100644 --- a/tests/unit/repo.bats +++ b/tests/unit/repo.bats @@ -49,11 +49,6 @@ teardown() { echo "status: $status" assert_output 1 - run /bin/bash -c "find $DOKKU_ROOT/$TEST_APP/cache -type f | wc -l" - echo "count: '$output'" - echo "status: $status" - assert_output 0 - run /bin/bash -c "dokku repo:purge-cache $TEST_APP" echo "output: $output" echo "status: $status" @@ -63,9 +58,4 @@ teardown() { echo "count: '$output'" echo "status: $status" assert_output 0 - - run /bin/bash -c "find $DOKKU_ROOT/$TEST_APP/cache -type f | wc -l" - echo "count: '$output'" - echo "status: $status" - assert_output 0 } From 18c54d39c088fc85213e940ade006a54d38bbcc6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Feb 2024 16:06:17 -0500 Subject: [PATCH 3/4] fix: remove tests that are no longer applicable --- tests/unit/build-env.bats | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/tests/unit/build-env.bats b/tests/unit/build-env.bats index c6407a4ad..dd83f1e36 100644 --- a/tests/unit/build-env.bats +++ b/tests/unit/build-env.bats @@ -80,31 +80,3 @@ teardown() { echo "status: $status" assert_output "herokuish" } - -@test "(build-env) DOKKU_ROOT cache bind is used by default" { - run deploy_app - echo "output: $output" - echo "status: $status" - assert_success - - BUILD_CID=$(docker ps -a | grep $TEST_APP | grep /bin/bash | awk '{print $1}' | head -n1) - run /bin/bash -c "docker inspect --format '{{ .HostConfig.Binds }}' $BUILD_CID | tr -d '[]' | cut -f1 -d:" - echo "output: $output" - echo "status: $status" - assert_output "$DOKKU_ROOT/$TEST_APP/cache" -} - -@test "(build-env) DOKKU_HOST_ROOT cache bind is used if set" { - TMP_ROOT=$(mktemp -d) - mkdir -p $DOKKU_ROOT/.dokkurc - echo export DOKKU_HOST_ROOT="$TMP_ROOT" >$DOKKU_ROOT/.dokkurc/HOST_ROOT - DOKKU_HOST_ROOT="$TMP_ROOT" deploy_app - - BUILD_CID=$(docker ps -a | grep $TEST_APP | grep /bin/bash | awk '{print $1}' | head -n1) - run /bin/bash -c "docker inspect --format '{{ .HostConfig.Binds }}' $BUILD_CID | tr -d '[]' | cut -f1 -d:" - echo "output: $output" - echo "status: $status" - assert_output "$TMP_ROOT/$TEST_APP/cache" - - rm -rf $TMP_ROOT $DOKKU_ROOT/.dokkurc/HOST_ROOT -} From c7e1f2d380ab8bc6204c11967a22cbe208c2ec36 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Feb 2024 16:12:07 -0500 Subject: [PATCH 4/4] fix: update test to fix case where intermediate containers are now immediately removed --- tests/unit/app-json.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/app-json.bats b/tests/unit/app-json.bats index 009009033..4af2b2eba 100644 --- a/tests/unit/app-json.bats +++ b/tests/unit/app-json.bats @@ -20,6 +20,9 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + assert_output_contains "Executing predeploy task from app.json: touch /app/predeploy.test" + assert_output_contains "Executing postdeploy task from app.json: touch /app/postdeploy.test" + assert_output_contains "Executing prebuild task from app.json: touch /app/prebuild.test" 0 run docker inspect "${TEST_APP}.web.1" --format "{{json .Config.Cmd}}" echo "output: $output" @@ -37,13 +40,10 @@ teardown() { echo "status: $status" assert_success - CID=$(docker ps -a -q -f "ancestor=dokku/${TEST_APP}" -f "label=dokku_phase_script=postdeploy") - DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$TEST_APP") - IMAGE_ID=$(docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID dokku-test/${TEST_APP}) - run /bin/bash -c "docker run --rm $IMAGE_ID ls /app/postdeploy.test" + run /bin/bash -c "dokku run $TEST_APP ls /app/postdeploy.test" echo "output: $output" echo "status: $status" - assert_success + assert_failure } @test "(app-json) app.json scripts postdeploy" {