diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index dfff0e8d9..152c16307 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,16 +11,6 @@ Succinct list of changes explaining what has changed and why. --> -## Checklist - -Please complete the following tasks to allow merging of this feature: - -- [ ] Documented any architecture desisions in an ADR -- [ ] Get QA Approval of test coverage - -Note: Check a task if it is not relevent to this PR. -Note: Please uncheck any relevent tasks if you make further changes to the code. - ## Screen-shots or screen-capture of UI changes - -### Before - -### After - -## Next steps - - diff --git a/.github/workflows/qa-deploy.yml b/.github/workflows/qa-deploy.yml index 88b571d15..db29ca952 100644 --- a/.github/workflows/qa-deploy.yml +++ b/.github/workflows/qa-deploy.yml @@ -61,7 +61,6 @@ jobs: TF_VAR_environment: "qa-${{ github.event.number }}" TF_VAR_cloudfoundry_space: "sct-preview" TF_VAR_s3_bucket_name: "s3-bucket-qa-${{ github.event.number }}" - ENV_APPLICATION_URL: "https://buy-for-your-school-qa-${{ github.event.number }}.london.cloudapps.digital" CF_APP_NAME: "buy-for-your-school-qa-${{ github.event.number }}" steps: - name: Check out code @@ -72,14 +71,28 @@ jobs: with: terraform_version: 0.14.7 + - name: Get Static Route + run: | + script/install-cf + script/qa/cf-login + STATIC_ROUTE=$(${GITHUB_WORKSPACE}/script/qa/get-free-dsi-redirect-route $CF_APP_NAME) + echo "STATIC_ROUTE=${STATIC_ROUTE}" >> $GITHUB_ENV + echo "ENV_APPLICATION_URL=https://${STATIC_ROUTE}.london.cloudapps.digital" >> $GITHUB_ENV + - name: Deploy QA app run: script/deploy-terraform + - name: Map static route + run: | + script/install-cf + script/qa/cf-login + script/qa/map-static-route + - name: Comment QA URL to PR uses: mshick/add-pr-comment@v1 with: message: | - QA application accessible at: https://buy-for-your-school-qa-${{ github.event.number }}.london.cloudapps.digital. + QA application accessible at: ${{ env.ENV_APPLICATION_URL }}.london.cloudapps.digital. Note: Full organisation seeding may take up to 5 minutes. repo-token: ${{ secrets.GITHUB_TOKEN }} @@ -87,4 +100,5 @@ jobs: if: ${{ github.event.action != 'synchronize' }} run: | script/install-cf + script/qa/cf-login script/qa/seed diff --git a/script/install-cf b/script/install-cf index b14ef3a40..a80f94bab 100755 --- a/script/install-cf +++ b/script/install-cf @@ -1,4 +1,10 @@ #!/bin/bash + +# check cf already exists +if command -v cf &> /dev/null; then + exit +fi + wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list sudo apt-get update diff --git a/script/qa/cf-login b/script/qa/cf-login new file mode 100755 index 000000000..b5f853db5 --- /dev/null +++ b/script/qa/cf-login @@ -0,0 +1,3 @@ +#!/bin/bash + +cf login -u $CF_USER -p $CF_PASSWORD -a https://api.london.cloud.service.gov.uk -s $TF_VAR_cloudfoundry_space diff --git a/script/qa/get-free-dsi-redirect-route b/script/qa/get-free-dsi-redirect-route new file mode 100755 index 000000000..0897d6382 --- /dev/null +++ b/script/qa/get-free-dsi-redirect-route @@ -0,0 +1,48 @@ +#!/bin/bash + +static_route_base=ghbs-qa +app_name=$1 +IFS=$'\n' all_web_apps=($(cf apps | sed -e "1,/^name/d" | awk '{print $1}' | grep -v "worker")) + +# initialize list of static route usage statuses (15 routes) +static_routes=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + +function getStaticRouteForApp() +{ + route_for_current_app=$(cf app $1 | grep 'routes:' | cut -d ':' -f 2 | tr "," "\\n" | grep $static_route_base | cut -d '.' -f 1) + + if [[ $route_for_current_app != "" ]]; then + echo $route_for_current_app + fi +} + +# if app already exists +if [[ $(echo $all_web_apps | grep $app_name) != "" ]]; then + # check if this app already has a route + static_route=$(getStaticRouteForApp $app_name) + + if [[ $static_route != "" ]]; then + echo $static_route + exit 0 + fi +fi + +# detect which routes are currently being used +for current_app in "${all_web_apps[@]}"; do + static_route=$(getStaticRouteForApp $current_app) + + if [[ $static_route != "" ]]; then + enabled_route_number=$(echo $static_route | rev | cut -d '-' -f '1' | rev) + static_routes[$enabled_route_number]=1 + fi +done + +# get the first one +for i in "${!static_routes[@]}"; do + if [[ "${static_routes[i]}" == 0 ]]; then + echo "$static_route_base-$((i+1))" + exit 0 + fi +done + +exit 1 diff --git a/script/qa/map-static-route b/script/qa/map-static-route new file mode 100755 index 000000000..59c466dbe --- /dev/null +++ b/script/qa/map-static-route @@ -0,0 +1,16 @@ +#!/bin/bash + +# Map the QA static route to the instance + +# wait for app to become started +until cf app $CF_APP_NAME | grep "requested state:" | grep started +do + echo "Waiting for app to start..." + sleep 2 +done + +sleep 10 + +# Now we can safely map the routes + +cf map-route $CF_APP_NAME london.cloudapps.digital --hostname $STATIC_ROUTE diff --git a/script/qa/seed b/script/qa/seed index 21a9c3f2a..2cb5f57c3 100755 --- a/script/qa/seed +++ b/script/qa/seed @@ -2,18 +2,6 @@ # Seed the QA environment -cf login -u $CF_USER -p $CF_PASSWORD -a https://api.london.cloud.service.gov.uk -s $TF_VAR_cloudfoundry_space - -# Wait for app to become started -until cf app $CF_APP_NAME | grep "requested state:" | grep started -do - echo "Waiting for app to start..." - sleep 2 -done - -sleep 10 - -# Run seeding tasks cf ssh $CF_APP_NAME -c 'cd /srv/app; PATH=$PATH:/usr/local/bundle/bin:/usr/local/bin rails case_management:seed_shared_inbox_emails' # quicker cf ssh $CF_APP_NAME -c 'cd /srv/app; PATH=$PATH:/usr/local/bundle/bin:/usr/local/bin rails self_serve:populate_categories' cf ssh $CF_APP_NAME -c 'cd /srv/app; PATH=$PATH:/usr/local/bundle/bin:/usr/local/bin rails case_management:seed' # slower