Skip to content

Commit

Permalink
If docker wait fails, get the exit code using docker inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jun 30, 2022
1 parent ef33162 commit 74a9dda
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/deploy-gcp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,20 +662,28 @@ jobs:

# Wait for the container to finish, then exit with the test's exit status.
#
# `docker wait` prints the container exit status as a string, but we need to exit `ssh` with that status.
# `docker wait` can also wait for multiple containers, but we only ever wait for a single container.
# If the container has already finished, `docker wait` should return its status.
# But sometimes this doesn't work, so we use `docker inspect` as a fallback.
#
# `docker wait` prints the container exit status as a string, but we need to exit the `ssh` command
# with that status.
# (`docker wait` can also wait for multiple containers, but we only ever wait for a single container.)
- name: Result of ${{ inputs.test_id }} test
run: |
EXIT_CODE=$(\
gcloud compute ssh \
${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ inputs.test_id }}" \
)
echo "$EXIT_CODE"
exit "$EXIT_CODE"
--command=' \
EXIT_STATUS=$( \
docker wait ${{ inputs.test_id }} || \
docker inspect --format "{{.State.ExitCode}}" ${{ inputs.test_id }} || \
echo "missing container, or missing exit status for container" \
); \
echo "docker exit status: $EXIT_STATUS"; \
exit "$EXIT_STATUS" \
'
# create a state image from the instance's state disk, if requested by the caller
Expand Down

0 comments on commit 74a9dda

Please sign in to comment.