diff --git a/integration/ci.sh b/integration/ci.sh index c1f8fef..4db2126 100755 --- a/integration/ci.sh +++ b/integration/ci.sh @@ -4,28 +4,28 @@ set -Exeuo pipefail source integration/lib.sh - -main() { - # CI runes these dependencies as part of its config, so skipping - # spinning up deps if running from within CI, - - if [ -z ${CI+x} ]; +init() { + if is_ci then + cp dashboard/local_settings.ci.py dashboard/local_settings.py + else docker_compose_down || true docker_compose_up setup_env - wait_for_env - else - cp dashboard/local_settings.ci.py dashboard/local_settings.py + sleep 5 +# wait_for_env fi gitea_root support_repo_init fleet_repo_init - if [ -z ${CI+x} ]; +} + +teardown() { + if ! is_ci then - teardown_env docker_compose_down + teardown_env fi } -main +$1 diff --git a/integration/lib.sh b/integration/lib.sh index 30f7e61..c821996 100755 --- a/integration/lib.sh +++ b/integration/lib.sh @@ -1,7 +1,25 @@ readonly SERVER_PID_FILE=./tmp/server.pid +is_ci(){ + if [ -z ${CI+x} ]; + then + return 1 + else + return 0 + fi +} + +if is_ci +then + MAILDEV_URL="http://smtp:1080" + GITEA_URL="http://gitea:3000" + GITEA_SSH_URL="ssh://git@gitea:2221" +else + MAILDEV_URL="http://localhost:1080" + GITEA_URL="http://localhost:3000" + GITEA_SSH_URL="ssh://git@localhost:22" +fi readonly DASHBOARD_URL="http://localhost:8000" -readonly GITEA_URL="http://localhost:3000" readonly DASHBOARD_OIDC_DISCOVERY_URL="$DASHBOARD_URL/o/.well-known/openid-configuration/" @@ -16,25 +34,20 @@ readonly GITEA_ROOT_EMAIL="$GITEA_ROOT_USERNAME@example.org" readonly GITEA_ROOT_PASSOWRD=supercomplicatedpassword readonly GITEA_HOSTEA_SSO_NAME=hostea-sso readonly GITEA_OIDC_CALLBACK="$GITEA_URL/user/oauth2/$GITEA_HOSTEA_SSO_NAME/callback" -readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY="tests/fleet-deploy-key.pub" +readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY="$(realpath tests/fleet-deploy-key.pub)" +readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE="$(realpath tests/fleet-deploy-key)" readonly GITEA_HOSTEA_USERNAME=hostea readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword readonly GITEA_HOSTEA_EMAIL="$GITEA_HOSTEA_USERNAME@example.org" readonly GITEA_HOSTEA_SUPPORT_REPO="support" readonly GITEA_HOSTEA_FLEET_REPO="fleet" +readonly GITEA_HOSTEA_FLEET_REPO_REMOTE="$GITEA_SSH_URL/$GITEA_HOSTEA_USERNAME/$GITEA_HOSTEA_FLEET_REPO.git" readonly HOSTEA_CUSTOMER_USERNAME=batman readonly HOSTEA_CUSTOMER_PASSWORD=supercomplicatedpassword readonly HOSTEA_CUSTOMER_EMAIL="$HOSTEA_CUSTOMER_USERNAME@example.org" -if [ -z ${CI+x} ]; -then - MAILDEV_URL="http://localhost:1080" -else - MAILDEV_URL="http://smtp:1080" -fi - OIDC_CLIENT_ID="" OIDC_CLIENT_SECRET="" @@ -133,6 +146,24 @@ fleet_repo_init() { $GITEA_URL \ $GITEA_HOSTEA_FLEET_REPO \ $GITEA_HOSTEA_FLEET_DEPLOY_KEY + + tmp_dir=$(mktemp -d) + pushd $tmp_dir + echo "init" >> README + if is_ci + then + git config --global user.email "${CI_COMMIT_AUTHOR_EMAIL}" + git config --global user.name "${CI_COMMIT_AUTHOR}" + fi + git init + git add README + git commit -m "init" + git remote add origin $GITEA_HOSTEA_FLEET_REPO_REMOTE + GIT_SSH_COMMAND="/usr/bin/ssh -oStrictHostKeyChecking=no -i $GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE" \ + git push --set-upstream origin master + popd + rm -rf $tmp_dir + } # Create user on Hostea to simulate a Hostea customer