feat: properly export env vars for cnb apps
They are not baked into the image like they are for herokuish, so we need to manually set them via --env. Additionally, due to newline constraints in docker, we need to use `--env=key` format to correctly pull the values into place.
This commit is contained in:
@@ -14,8 +14,8 @@ trigger-config-docker-args() {
|
||||
STDIN=$(cat)
|
||||
trigger="$0 config_docker_args"
|
||||
|
||||
if ! is_image_herokuish_based "$IMAGE" "$APP"; then
|
||||
ENV_ARGS="$(config_export app "$APP" --format docker-args --merged)"
|
||||
if ! is_image_herokuish_based "$IMAGE" "$APP" || is_image_cnb_based "$IMAGE"; then
|
||||
ENV_ARGS="$(config_export app "$APP" --format docker-args-keys --merged)"
|
||||
echo -n "$STDIN $ENV_ARGS"
|
||||
else
|
||||
echo -n "$STDIN"
|
||||
|
||||
@@ -222,6 +222,7 @@ fn-start-app-container() {
|
||||
|
||||
declare -a __DOKKU_DOCKER_ARG_ARRAY
|
||||
eval "__DOKKU_DOCKER_ARG_ARRAY=($DOCKER_ARGS)"
|
||||
eval "$(config_export app "$APP")"
|
||||
"$DOCKER_BIN" container create "${__DOKKU_DOCKER_ARG_ARRAY[@]}"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
@@ -7,7 +8,12 @@ class GetHandler(http.server.BaseHTTPRequestHandler):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain; charset=utf-8")
|
||||
self.end_headers()
|
||||
self.wfile.write("python/http.server".encode("utf-8"))
|
||||
|
||||
if self.path == '/':
|
||||
self.wfile.write("python/http.server".encode("utf-8"))
|
||||
else:
|
||||
data = json.dumps(dict(os.environ), sort_keys=True, indent=4)
|
||||
self.wfile.write(data.encode("utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
31
tests/unit/ps-cnb.bats
Normal file
31
tests/unit/ps-cnb.bats
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
global_setup
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
global_teardown
|
||||
}
|
||||
|
||||
@test "(ps) cnb env vars" {
|
||||
run /bin/bash -c "dokku config:set $TEST_APP DOKKU_CNB_EXPERIMENTAL=1"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@dokku.me:$TEST_APP add_requirements_txt
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "curl $(dokku url $TEST_APP)/env"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains '"DOKKU_CNB_EXPERIMENTAL": "1"'
|
||||
}
|
||||
@@ -513,6 +513,13 @@ add_release_command() {
|
||||
echo "release: touch /app/release.test" >> "$APP_REPO_DIR/Procfile"
|
||||
}
|
||||
|
||||
add_requirements_txt() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
echo "flask" >> "$APP_REPO_DIR/requirements.txt"
|
||||
}
|
||||
|
||||
build_nginx_config() {
|
||||
# simulate nginx post-deploy
|
||||
dokku domains:setup "$TEST_APP"
|
||||
|
||||
Reference in New Issue
Block a user