Skip to content

Commit

Permalink
update qa deploy to enable static routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Apr 6, 2022
1 parent 5994d1b commit 699f969
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 34 deletions.
20 changes: 0 additions & 20 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!--
Expand All @@ -34,13 +24,3 @@ Note: Please uncheck any relevent tasks if you make further changes to the code.
- Mac guide: https://support.apple.com/en-gb/HT208721
- Windows guide: https://support.microsoft.com/en-us/windows/5328cd25-9046-4472-8a14-c485f138802c
-->

### Before

### After

## Next steps

<!--
Document this change in [Confluence](https://dfedigital.atlassian.net/wiki/spaces/GHBFS)
-->
18 changes: 16 additions & 2 deletions .github/workflows/qa-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -72,19 +71,34 @@ 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 }}

- name: Run seeding
if: ${{ github.event.action != 'synchronize' }}
run: |
script/install-cf
script/qa/cf-login
script/qa/seed
6 changes: 6 additions & 0 deletions script/install-cf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions script/qa/cf-login
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions script/qa/get-free-dsi-redirect-route
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions script/qa/map-static-route
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions script/qa/seed
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 699f969

Please sign in to comment.