Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve process management in e2e test #4840

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,67 @@

set -euo pipefail
IFS=$'\n\t'
ATLANTIS_PID=""
NGROK_PID=""

function cleanup() {
cleanupPid "$ATLANTIS_PID"
cleanupPid "$NGROK_PID"
}

function cleanupPid() {
local pid="$1"
# Never set, no need to clean up
if [[ "$pid" == "" ]]
then
return
fi
# Somehow pid was not number, just being careful
if ! [[ "$pid" =~ ^[0-9]+$ ]]
then
return
fi
# Not currently running, no need to kill
if ! ps -p "$pid" &>/dev/null
then
return
fi
kill $pid
}


# start atlantis server in the background and wait for it to start
# It's the responsibility of the caller of this script to set the github, gitlab, etc.
# permissions via environment variable
./atlantis server \
--data-dir="/tmp" \
--log-level="debug" \
--repo-allowlist="github.com/runatlantis/atlantis-tests" \
--repo-config-json='{"repos":[{"id":"/.*/", "allowed_overrides":["apply_requirements","workflow"], "allow_custom_workflows":true}]}' \
&> /tmp/atlantis-server.log &
ATLANTIS_PID=$!
sleep 2
if ! ps -p "$ATLANTIS_PID" &>/dev/null
then
echo "Atlantis failed to start"
cat /tmp/atlantis-server.log
exit 1
fi
echo "Atlantis is running..."

# start ngrok in the background and wait for it to start
./ngrok config add-authtoken $NGROK_AUTH_TOKEN > /dev/null 2>&1
./ngrok http 4141 > /tmp/ngrok.log 2>&1 &
NGROK_PID=$!
sleep 2
if ! ps -p "$NGROK_PID" &>/dev/null
then
cleanup
echo "Ngrok failed to start"
cat /tmp/ngrok.log
exit 1
fi
echo "Ngrok is running..."

# find out what URL ngrok has given us
export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[] | select(.proto=="https") | .public_url')
Expand All @@ -27,6 +74,7 @@ make build

echo "Running e2e test: 'make run'"
set +e
estatus=0
make run
if [[ $? -eq 0 ]]
then
Expand All @@ -35,5 +83,7 @@ else
echo "e2e tests failed"
echo "atlantis logs:"
cat /tmp/atlantis-server.log
exit 1
estatus=1
fi
cleanup
exit $estatus