fix: respect pre-existing .env files when preparing the herokuish buildenv

Closes #4894
This commit is contained in:
Jose Diaz-Gonzalez
2022-01-18 02:20:57 -05:00
parent 3c68114ad3
commit 07f2ef1411
4 changed files with 32 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
trigger-builder-herokuish-pre-build-buildpack() {
declare desc="builder-herokuish pre-build-buildpack plugin trigger"
declare trigger="pre-build-buildpack"
declare APP="$1"
declare APP="$1" SOURCECODE_WORK_DIR="$2"
local IMAGE TMP_WORK_DIR
local DOCKER_BUILD_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP"
@@ -27,7 +27,13 @@ trigger-builder-herokuish-pre-build-buildpack() {
config_bundle --merged "$APP" | tar -x -C "$TMP_WORK_DIR/.env.d"
# create build env for 'old style' buildpacks and dokku plugins
config_export app "$APP" --format envfile --merged >"$TMP_WORK_DIR/.env"
touch "$TMP_WORK_DIR/.env"
if [[ -f "$SOURCECODE_WORK_DIR/.env" ]]; then
cp -f "$SOURCECODE_WORK_DIR/.env" "$TMP_WORK_DIR/.env"
fi
local dotenv_contents="$(sed -Ez '$ s/\n+$//' "$TMP_WORK_DIR/.env")"
echo "$dotenv_contents" >"$TMP_WORK_DIR/.env"
config_export app "$APP" --format envfile --merged >>"$TMP_WORK_DIR/.env"
if ! suppress_output "$DOCKER_BIN" image build "${DOCKER_BUILD_LABEL_ARGS[@]}" $DOKKU_GLOBAL_BUILD_ARGS -f "$PLUGIN_AVAILABLE_PATH/builder-herokuish/dockerfiles/pre-build.Dockerfile" --build-arg APP_IMAGE="$IMAGE" -t $IMAGE "$TMP_WORK_DIR"; then
dokku_log_warn "Failure injecting BUILD_ENV into build environment"

1
tests/apps/python/.env Normal file
View File

@@ -0,0 +1 @@
DOTENV_KEY=some_value

View File

@@ -5,7 +5,10 @@ import os
def main():
print("GLOBAL_SECRET: {0}".format(os.getenv('GLOBAL_SECRET')))
print("SECRET_KEY: {0}".format(os.getenv('SECRET_KEY')))
with open("/app/.env", "r") as f:
for line in f.readlines():
if "DOTENV_KEY" in line:
print(line)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bats
load test_helper
setup() {
create_app
}
teardown() {
destroy_app
}
@test "(builder-herouish:build .env)" {
run deploy_app python dokku@dokku.me:$TEST_APP
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains 'DOTENV_KEY=some_value'
}