Merge pull request #6631 from dokku/herokuish-cache
Correctly use cache volume for herokuish builds
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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" {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user