Skip to content

Commit ca82300

Browse files
committed
nix/build-ami: Change how packer build handles errors
In CI it will abort so that the workflow can grab ec2 console output, hopefully catching any kernel messages there. Otherwise set to ask if stdout is a tty so that the caller can poke around if they want to debug. If stdout is not a tty then we will go with the default.
1 parent 888c845 commit ca82300

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎nix/packages/build-ami.nix‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ writeShellApplication {
7070
INPUT_HASH=''${INPUT_HASH%%-*}
7171
shift 2
7272
73+
export PACKER_LOG=''${PACKER_LOG:-''${RUNNER_DEBUG:-0}}
74+
on_error=ask
75+
if ''${CI:-false}; then
76+
echo "::notice::Setting packer build -on-error=abort since this is CI, this is different than non-CI runs!"
77+
on_error=abort
78+
elif ! [[ -t 1 ]]; then
79+
echo "stdout is not a tty, so running packer build -on-error=cleanup (default) since there's no one to ask!" >&2
80+
on_error=cleanup
81+
fi
82+
7383
REGION="''${AWS_REGION:-ap-southeast-1}"
7484
7585
find_stage1_ami() {
@@ -109,8 +119,6 @@ writeShellApplication {
109119
fi
110120
}
111121
112-
export PACKER_LOG=''${RUNNER_DEBUG:-0}
113-
114122
if [ "$STAGE" = "stage1" ]; then
115123
echo "Building stage 1..."
116124
echo "Checking for existing AMI..."
@@ -150,7 +158,7 @@ writeShellApplication {
150158
151159
cd ${packerSources}
152160
PACKER_LOG=0 packer init "$@"
153-
packer build \
161+
packer build -on-error=$on_error \
154162
-var-file="development-$ARCH.vars.pkr.hcl" \
155163
-var "input-hash=$INPUT_HASH" \
156164
-var "postgres-version=$POSTGRES_VERSION" \
@@ -183,7 +191,7 @@ writeShellApplication {
183191
echo "Found stage 1 AMI: $STAGE1_AMI_ID"
184192
185193
PACKER_LOG=0 packer init stage2-nix-psql.pkr.hcl
186-
packer build \
194+
packer build -on-error=$on_error \
187195
-var-file="development-$ARCH.vars.pkr.hcl" \
188196
-var-file="common-nix.vars.pkr.hcl" \
189197
-var "region=$REGION" \

0 commit comments

Comments
 (0)