Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly use cache volume for herokuish builds #6631

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions plugins/app-json/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
}...)
}

Expand All @@ -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, " ")}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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[:])))
Expand Down Expand Up @@ -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"))
}
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/app-json.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" {
Expand Down
28 changes: 0 additions & 28 deletions tests/unit/build-env.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 0 additions & 10 deletions tests/unit/repo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Loading