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

Make Python3.10 upgrade branch master #195

Merged
merged 199 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
d93e4bb
Workflows to build and push to ECR and then deploy
floptical Oct 15, 2021
8346488
messing around with gunicorn
Nov 19, 2021
2c66198
try out nginx/gunicorn mods
Nov 24, 2021
6b6e982
rebalancing nginx and gunicorn
Nov 29, 2021
2b91359
rebalancing nginx and gunicorn again
floptical Nov 30, 2021
22c424c
Adjust nginx.conf
floptical Dec 1, 2021
e87a82a
Properly install ais in venv
floptical Dec 1, 2021
c16a33f
Correct nginx
floptical Dec 1, 2021
b1a4cb6
Change venv to python3.6
floptical Dec 1, 2021
83f4178
function to scale up staging and disable then reenable scale in alarm
floptical Dec 5, 2021
0c61d95
Docker uses the 172 private subs, add it to be allowed in nginx.conf
floptical Dec 6, 2021
b18b0b0
Actually make scale_up_staging function in build_go.sh work
floptical Dec 6, 2021
1b9dc37
Blocke more than one action from running on our runner at atime
floptical Dec 6, 2021
33fde76
test concurrent runs
floptical Dec 6, 2021
6c5d4ca
Make warmup_lb command work
floptical Dec 7, 2021
4c54f15
workflow to test docker on pull requests
floptical Dec 7, 2021
f8e730d
correct syntax error
floptical Dec 7, 2021
8165c11
try out concurrency
floptical Dec 7, 2021
f2d8030
try out concurrency v2
floptical Dec 7, 2021
0999f4e
test
floptical Dec 7, 2021
6f46022
Testing workflow actions
floptical Dec 7, 2021
be28a96
Make workflow pull PR changes
floptical Dec 7, 2021
e3bc41e
correct error in requirements.app.txt
floptical Dec 7, 2021
10a6259
debug working dir in runner
floptical Dec 7, 2021
ca14606
have everything run on test runner
floptical Dec 7, 2021
1d6ccab
actually debug working dir in runner
floptical Dec 7, 2021
a3c7e83
fix requirements.app.txt
floptical Dec 7, 2021
b6557c7
Fix horrible dockerfile bug
floptical Dec 7, 2021
883c5f5
Changes for newer shapely version
floptical Dec 10, 2021
ed52dc7
Basket o changes
floptical May 10, 2022
039173c
Add address to ignore list for OPA child unit API test
floptical May 10, 2022
e384af2
Workflows to build and push to ECR and then deploy
floptical Oct 15, 2021
db49246
messing around with gunicorn
Nov 19, 2021
d410bbb
try out nginx/gunicorn mods
Nov 24, 2021
ad79e97
rebalancing nginx and gunicorn
Nov 29, 2021
f2fed07
rebalancing nginx and gunicorn again
floptical Nov 30, 2021
0610ec7
Adjust nginx.conf
floptical Dec 1, 2021
3db70d4
Properly install ais in venv
floptical Dec 1, 2021
2ea4ed5
Correct nginx
floptical Dec 1, 2021
6b33c3f
Change venv to python3.6
floptical Dec 1, 2021
efdb28f
function to scale up staging and disable then reenable scale in alarm
floptical Dec 5, 2021
8980ff4
Docker uses the 172 private subs, add it to be allowed in nginx.conf
floptical Dec 6, 2021
efb180f
Actually make scale_up_staging function in build_go.sh work
floptical Dec 6, 2021
388f1a3
Blocke more than one action from running on our runner at atime
floptical Dec 6, 2021
016391a
test concurrent runs
floptical Dec 6, 2021
606c90d
Make warmup_lb command work
floptical Dec 7, 2021
449c8c0
workflow to test docker on pull requests
floptical Dec 7, 2021
0bfb065
correct syntax error
floptical Dec 7, 2021
4f58c82
try out concurrency
floptical Dec 7, 2021
cc42943
try out concurrency v2
floptical Dec 7, 2021
11b3673
test
floptical Dec 7, 2021
6c61e37
Testing workflow actions
floptical Dec 7, 2021
02ecbd2
Make workflow pull PR changes
floptical Dec 7, 2021
5af49ee
correct error in requirements.app.txt
floptical Dec 7, 2021
49762e3
debug working dir in runner
floptical Dec 7, 2021
1e34330
have everything run on test runner
floptical Dec 7, 2021
2a0b64b
actually debug working dir in runner
floptical Dec 7, 2021
11151b6
fix requirements.app.txt
floptical Dec 7, 2021
37eb249
Fix horrible dockerfile bug
floptical Dec 7, 2021
a44810d
Basket o changes
floptical May 10, 2022
d2bc842
Add address to ignore list for OPA child unit API test
floptical May 10, 2022
c1b92a8
Switch running machine
floptical May 25, 2022
c092ddf
Forgot to replace runs-on in second task
floptical May 26, 2022
55d1361
Switch running machine
floptical May 25, 2022
3239cbb
script changes for warmup_lb.py
floptical May 26, 2022
e783cdf
Cleanup
floptical Jun 29, 2022
ab60fd9
csv files in wrong directory in Dockerfile
floptical Jun 29, 2022
63479e4
Fix bad paths in workflow
floptical Jun 29, 2022
b704986
better pytest flags
floptical Jun 29, 2022
6ee64f9
Properly pass engine host in pr workflow
floptical Jun 29, 2022
96ad026
Properly run workflows
floptical Jun 29, 2022
2434ed5
Debugging load_service_areas.py
floptical Jul 5, 2022
5a84d42
Switch 1 process to write to using geopetl
floptical Jul 14, 2022
485f105
Bring inline with master
floptical Jul 14, 2022
7e01d61
Small bugs, changes to get warmup_lb working.
floptical Jul 22, 2022
93ffaa1
Export secrets within function to make warmup
floptical Jul 25, 2022
ebcf088
Warning on non-200 codes and add timeout.
floptical Jul 25, 2022
bf80dfd
Move identify_prod up before engine build
floptical Jul 26, 2022
9fe52b5
URL encoding and gatekeeper key for warmup_lb
floptical Aug 3, 2022
9822250
revamp github workflows
floptical Aug 29, 2022
2c0b2fd
correct build branch
floptical Sep 1, 2022
867669e
Better comments for config-secrets
floptical Sep 1, 2022
a86fd64
Spruce up ecr push workflow
floptical Sep 1, 2022
ad11bd4
teasm message for pr tests
floptical Sep 1, 2022
ed36a2e
Add back in deploy step
floptical Sep 2, 2022
8686bdd
spruce up names
floptical Sep 2, 2022
17db445
Make reports function, currently pointed against test database
floptical Sep 20, 2022
7324161
geom rename check in make_street_intersections
floptical Sep 21, 2022
04405b7
Comment out many print lines
floptical Sep 22, 2022
4d09a82
Make reports works and is pythonic
floptical Sep 22, 2022
07ec6ec
initial python3.10 upgrade commit
floptical Nov 10, 2022
2e56a02
working 3.10 app, now just to get commands working
floptical Nov 18, 2022
61978b0
make repeated builds faster
floptical Nov 21, 2022
139d069
lots o changes
floptical Nov 29, 2022
2a85d2d
getting engine build to work
floptical Nov 30, 2022
c3085d0
export oracle envs cause they didnt appear to be getting here
floptical Feb 28, 2023
4b6887c
wrap in main function
floptical Feb 28, 2023
01cde57
update gitignore
floptical Feb 28, 2023
bcbef8c
Committing progress, fixed several things
floptical Mar 8, 2023
506edc9
Fixing bugs and removing dead code
floptical Mar 13, 2023
8c2d8db
No db access to load_addresses, get_pwd_matches taking too long
floptical Mar 14, 2023
55ea475
Ready to test build
floptical Mar 20, 2023
e1726b8
Added git branch
floptical Mar 20, 2023
8dec763
Correctly set cd
floptical Mar 20, 2023
ba4bbb9
Add unbuffered statements to print
floptical Mar 21, 2023
2a88df0
Load Addresses working
floptical Mar 27, 2023
1a34cfa
Now copying, but still having OOM - need to cut columns
jrmidkiff Mar 29, 2023
41e2f04
Now able to read all tables in
jrmidkiff Mar 30, 2023
37d8b65
Fully working
floptical Apr 3, 2023
e7a4c3f
Made bash array and function
floptical Apr 3, 2023
ca23e96
rename deplyo script something better
floptical Apr 19, 2023
ae64d63
attempt to get in good working condition
floptical May 5, 2023
e2bc596
pin requirements to current env [skip ci]
floptical May 8, 2023
7f48f60
testing out github workflows
floptical May 8, 2023
dedce7f
more small bugs
floptical May 8, 2023
92c0ade
dont print sensitive vars
floptical May 8, 2023
160ea67
revamp bash cli args logic
floptical May 9, 2023
a4f585f
selectively pull files from master
floptical May 10, 2023
7c55266
ignore log directory
floptical May 10, 2023
c36d7c0
make work
floptical May 10, 2023
3769391
cleanup reqs
floptical May 10, 2023
371a753
re-wrap in main function so runnable under new flask implementation
floptical May 11, 2023
e075a56
fixes
floptical May 11, 2023
b0db94e
Try to fix tests, load_addresses broke due to if name == __main__
jrmidkiff Jun 13, 2023
2505842
Change tests path
floptical Jun 13, 2023
de48aa4
Now correctly using test database for testing
floptical Jun 26, 2023
74f00ef
Pulled in master changes and cleared up requirements.txt
floptical Jun 26, 2023
4c74b11
Cleared up Dockerfile
floptical Jun 26, 2023
ec0b925
Reverted to ValueError in Load_Streets
jrmidkiff Jun 27, 2023
76bf662
Added detail to api tests and README
jrmidkiff Jun 27, 2023
a98d1ce
Changed Dockerfile test path, deleted dead code
floptical Jun 28, 2023
a9deaf3
make docker_tests in build_and_deploy.sh work
floptical Jul 3, 2023
c29e7b4
blurb about how this repo works
floptical Jul 3, 2023
2049987
copy instance config.py into docker container
floptical Jul 6, 2023
63163a7
make gh actions work on 3.10 branch
floptical Jul 6, 2023
0ba8662
better trap function + skip_api_tests for docker_tests()
floptical Jul 6, 2023
a1bdf2d
Make gh actions work with latest codebase
floptical Jul 6, 2023
1fed56d
cant do dockerlines like this because gh actions doesnt support buildkit
floptical Jul 6, 2023
e303da7
make run on our ais build server
floptical Jul 6, 2023
b717593
typo in pytest command
floptical Jul 6, 2023
1a8a294
experiment with gunicorn/nginx configuration again
floptical Jul 7, 2023
5f290bc
no discernible performance difference
floptical Jul 10, 2023
53759bb
make reports work
floptical Jul 27, 2023
c398c8e
Function to kill prior runs
floptical Jul 27, 2023
d140114
make check_for_prior_runs work
floptical Jul 28, 2023
7bb4e32
make ais engine build work
floptical Aug 1, 2023
50edd95
logging alert for empty geometries
floptical Aug 2, 2023
e902d76
additional ignore address in test_opa test
floptical Aug 22, 2023
5a71968
make reports work
floptical Aug 22, 2023
04e4a8a
Merge new changes from master into python3.10-upgrade branch
Alexander-M-Waldman Aug 22, 2023
a4bf3a0
make tests actually run against local db
floptical Aug 29, 2023
868e9bd
README blurb about running local queries + small bug
floptical Aug 29, 2023
b1fe763
Add if-else block to load_addresses from on-prem
jrmidkiff Aug 31, 2023
c4feb18
Convert etl.readcsv from text to int
jrmidkiff Sep 5, 2023
ca35797
Add 2nd rejected link printing to make_linked_tags
jrmidkiff Sep 6, 2023
625f4e9
deploy key config for the build script to use
floptical Sep 7, 2023
d583e1b
Update DEV
jrmidkiff Sep 7, 2023
30f9f8a
Sort address_links when read
jrmidkiff Sep 12, 2023
e05b058
Write remaining geocode_rows to geocode table
jrmidkiff Sep 13, 2023
69820fa
Remove dev where clauses
jrmidkiff Sep 13, 2023
0e704d0
Sort zoning_rcos in make_service_area_summary
jrmidkiff Sep 21, 2023
b295656
Add order by to make_street_intersections for separated intersections
jrmidkiff Sep 22, 2023
b627425
Join layers with '|' in service_area_summary
jrmidkiff Sep 22, 2023
d982998
Add back if clause to make_service_area_summary layers
jrmidkiff Sep 22, 2023
31f4b42
Update passyunk public repo in build_and_deploy script
jrmidkiff Sep 26, 2023
89ea28f
Freshen up - incorporate updates to prod
Alexander-M-Waldman Dec 4, 2023
6e58a99
Add main fct
floptical Dec 7, 2023
95b6dee
Add config changes to complete refresh
Alexander-M-Waldman Dec 11, 2023
b3d028a
Test github action
floptical Dec 13, 2023
d2b2cfb
Update entrypoint.sh
Alexander-M-Waldman Dec 14, 2023
03de739
failsafe git fetch & pull for the direct /home/ubuntu/ais folder
floptical Dec 14, 2023
5c105a6
cleanup [skip cli]
floptical Dec 14, 2023
9334d4d
remove [skip ci]
floptical Dec 14, 2023
0c7be25
Add council_district_2024 service areas
floptical Dec 14, 2023
1627dc0
modify pg_dump and pg_restore process [skip ci]
floptical Jan 5, 2024
be19a09
Create extensions if not exist
floptical Jan 8, 2024
6d72637
have engine_tests check for DB host var
floptical Jan 11, 2024
864bd1b
feeling confident this make ais build tonight [skip ci]
floptical Jan 18, 2024
e4d1bee
move parameter modification around to try to avoid restart issue [ski…
floptical Jan 19, 2024
d7ed0ce
Cleanup restore function + small changes [skip ci]
floptical Jan 24, 2024
b537b3a
verbose for pg_restore again and also less noise from rds reboot func…
floptical Jan 25, 2024
b2062ed
completely stop staging ECS containers before pg_restore
floptical Feb 12, 2024
95405cf
fix hardcoded color, whoops [skip ci]
floptical Feb 13, 2024
909ca4d
Add coalesce in opa_only query to accomondate unit parcel addresses
Alexander-M-Waldman Apr 2, 2024
7102741
Add report for source_address
Alexander-M-Waldman Apr 2, 2024
10dae0d
python script to automatically update .env secrets
floptical Apr 5, 2024
f351c29
put write secrets python file into build script
floptical Apr 5, 2024
0bf80e7
update ~/.aws/credentials too
floptical Apr 8, 2024
f1e043c
Add sorting to read from street_segment table
floptical Apr 18, 2024
93c24f9
somewhat de-obfuscate which databases are used where
floptical May 10, 2024
dbca04b
fix gh actions
floptical May 10, 2024
55dd685
make gh actions work for real
floptical May 10, 2024
ca21134
upgrade ghactions modules [skip ci]
floptical May 10, 2024
32b9f02
Update reports to match prod
floptical May 15, 2024
671d537
modify route 53 dns for mulesoft account too [skip ci]
floptical Jun 28, 2024
4abcc25
make build more resilient, modify warmup gatekeeper endpoint [skip ci]
floptical Jul 5, 2024
625e35c
fail warmup_lb if no successes seen [skip ci]
floptical Jul 5, 2024
7402c7e
properly write mulesoft creds [skip ci]
floptical Jul 5, 2024
ca7dc75
Merge branch 'master' into python3.10-upgrade
floptical Jul 5, 2024
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
197 changes: 197 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
name: Build and Deploy to ECR and ECS
# We want this to build our docker container, push to ECR ("build" job)
# and then perform a rolling update to ECS with the new image ( "deploy" job)

# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#on
on:
push:
branches:
- master
- python3.10-upgrade

concurrency:
group: testing_environment
cancel-in-progress: false


jobs:

build:
name: Build and Push to ECR
if: "!contains(github.event.head_commit.message, 'skip ci')"
#needs: pre-build
runs-on: ais-runner
#runs-on: ubuntu-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# This is a github function? Ref doc: https://github.com/actions/checkout#checkout-a-different-branch
- name: Checkout commit
uses: actions/checkout@v4

- name: Get github commit sha ID
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV

# https://github.com/marketplace/actions/microsoft-teams-notification
- name: Notify build start
uses: jdcargile/[email protected]
with:
GITHUB-TOKEN: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: Building and testing of new AIS docker image started for commit id ${{ env.GITHUB_SHA_SHORT }}
notification-color: 17a2b8
timezone: America/New_York


# https://github.com/aws-actions/amazon-ecr-login
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Identify production cluster, either blue or green
id: prod-cluster-color
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PROD_ENDPOINT: ${{ secrets.PROD_ENDPOINT }}
run: |
# Note: a simple dig doesn't work from in office.
# Run the command manually first so we're sure it works, otherwise the var assignment hides errors.
aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green"
echo "PROD_COLOR=$(aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green")" >> $GITHUB_ENV

- name: Set engine hostname based on prod color
env:
PROD_ENDPOINT: ${{ secrets.PROD_ENDPOINT }}
run: |
if [[ "$PROD_COLOR" -eq "blue" ]]; then
echo "ENGINE_HOST=${{ secrets.BLUE_ENGINE_CNAME }}" >> $GITHUB_ENV
elif [[ "$PROD_COLOR" -eq "green" ]]; then
echo "ENGINE_HOST=${{ secrets.GREEN_ENGINE_CNAME }}" >> $GITHUB_ENV
fi

- name: git fetch and pull failsafe
working-directory: /home/ubuntu/ais
run: git fetch && git pull

- name: Build the Docker image using docker-compose
# Run directly in our ais folder, necessary to get some secrets in the container
working-directory: /home/ubuntu/ais
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: |
docker-compose -f build-test-compose.yml build --no-cache

- name: Start the Docker image using docker-compose
# Run directly in our ais folder, necessary to get some secrets in the container
working-directory: /home/ubuntu/ais
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: docker-compose -f build-test-compose.yml up -d

- name: Run API pytests to ensure image build is good
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: |
docker exec ais bash -c 'cd /ais && pytest /ais/ais/tests/api/ -vvv -ra --showlocals --tb=native'

- name: Confirm nginx configuration is good
run: docker exec ais bash -c 'nginx -t'

- name: Simple curl query check
run: curl http://localhost:8080/search/1234%20Market%20Street

# https://github.com/aws-actions/amazon-ecr-login
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Docker Push to ECR
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ECR_REPOSITORY_URL: ${{ secrets.ECR_REPOSITORY_url }}
run: |
docker tag ais:latest $ECR_REPOSITORY_URL:latest
docker push $ECR_REPOSITORY_URL:latest

# https://github.com/marketplace/actions/microsoft-teams-notification
- name: Notify build status
if: always()
uses: jdcargile/[email protected]
with:
GITHUB-TOKEN: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: Build and push to ECR; ${{ job.status }} for commit ID ${{ env.GITHUB_SHA_SHORT }}!
notification-color: ${{ job.status == 'success' && '28a745' || 'dc3545' }}
timezone: America/New_York

deploy:

name: Deploy to prod ECS cluster
# needs prior job of 'build' to not fail.
needs: build
runs-on: ubuntu-latest


steps:

# https://github.com/aws-actions/amazon-ecr-login
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

# Set $PROD_COLOR env var through the complicated method github actions requires
# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Identify production cluster, either blue or green
id: prod-cluster-color
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PROD_ENDPOINT: ${{ secrets.PROD_ENDPOINT }}
run: |
# Note: a simple dig doesn't work from in office.
# Run the command manually first so we're sure it works, otherwise the var assignment hides errors.
aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green"
echo "PROD_COLOR=$(aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green")" >> $GITHUB_ENV

- name: Force deploy to ECS cluster
run: |
echo "Deploying to $PROD_COLOR"
aws ecs update-service --cluster ais-$PROD_COLOR-cluster \
--service ais-$PROD_COLOR-api-service --force-new-deployment --region us-east-1
aws ecs wait services-stable --cluster ais-$PROD_COLOR-cluster \
--service ais-$PROD_COLOR-api-service --region us-east-1
- name: Confirm LB target group health
run: |
blue_tg_arn=$(aws elbv2 describe-target-groups | grep "blue-tg" | grep TargetGroupArn| cut -d"\"" -f4)
green_tg_arn=$(aws elbv2 describe-target-groups | grep "green-tg" | grep TargetGroupArn| cut -d"\"" -f4)
if [[ "$PROD_COLOR" -eq "blue" ]]; then
echo "blue"
aws elbv2 describe-target-health --target-group-arn $blue_tg_arn | grep "\"healthy\""
echo $?
elif [[ "$PROD_COLOR" -eq "green" ]]; then
echo "green"
aws elbv2 describe-target-health --target-group-arn $green_tg_arn | grep "\"healthy\""
echo $?
fi

# https://github.com/marketplace/actions/microsoft-teams-notification
- name: Notify build status
if: always()
uses: jdcargile/[email protected]
with:
GITHUB-TOKEN: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: Deployed to ${{ env.PROD_COLOR }} ECS cluster.
notification-color: ${{ job.status == 'success' && '28a745' || 'dc3545' }}
timezone: America/New_York
109 changes: 109 additions & 0 deletions .github/workflows/pull_request_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Build and Test Docker Image for PRs

# Trigger workflow on changes to these paths in stated branch
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#on
on:
pull_request:
branches:
- master
- python3.10-upgrade
#types: [opened, edited, repoened, review_requested]

concurrency:
group: testing_environment
cancel-in-progress: false


jobs:

build:
name: Build and Test docker container for PRs
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ais-runner
#runs-on: ubuntu-latest
# https://github.community/t/sharing-a-variable-between-jobs/16967/13
# save address for use in other jobs.

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# This is a github function? Ref doc: https://github.com/actions/checkout#checkout-a-different-branch
- name: Checkout PR branch
uses: actions/checkout@v4

# https://github.com/aws-actions/amazon-ecr-login
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Print current working directory
run: pwd

# Set $PROD_COLOR env var through the complicated method github actions requires
# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Identify production cluster, either blue or green
id: prod-cluster-color
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PROD_ENDPOINT: ${{ secrets.PROD_ENDPOINT }}
run: |
# Note: a simple dig doesn't work from in office.
# Run the command manually first so we're sure it works, otherwise the var assignment hides errors.
#echo "PROD_COLOR=$(dig ${{ secrets.PROD_ENDPOINT }} +short | grep -o "blue\|green")" >> $GITHUB_ENV
#dig ${{ secrets.PROD_ENDPOINT }} +short | grep -o "blue\|green"
aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green"
echo "PROD_COLOR=$(aws route53 list-resource-record-sets --hosted-zone-id ${{ secrets.PHILACITY_ZONE_ID }} --query "ResourceRecordSets[?Name == '${{ secrets.PROD_ENDPOINT }}.']" | grep -o "blue\|green")" >> $GITHUB_ENV

- name: Set engine hostname to the production database for testing against.
env:
PROD_ENDPOINT: ${{ secrets.PROD_ENDPOINT }}
run: |
if [[ "$PROD_COLOR" -eq "blue" ]]; then
echo "ENGINE_HOST=${{ secrets.BLUE_ENGINE_CNAME }}" >> $GITHUB_ENV
elif [[ "$PROD_COLOR" -eq "green" ]]; then
echo "ENGINE_HOST=${{ secrets.GREEN_ENGINE_CNAME }}" >> $GITHUB_ENV
fi

- name: Build the Docker image using docker-compose
# Run directly in our ais folder, necessary to get some secrets in the container
working-directory: /home/ubuntu/ais
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f build-test-compose.yml build --no-cache

- name: Start the Docker image using docker-compose
# Run directly in our ais folder, necessary to get some secrets in the container
working-directory: /home/ubuntu/ais
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: docker-compose -f build-test-compose.yml up -d

- name: Run API pytests to ensure image build is good
env:
ENGINE_DB_HOST: ${{ env.ENGINE_HOST }}
ENGINE_DB_PASS: ${{ secrets.ENGINE_DB_PASS }}
run: |
docker exec ais bash -c 'cd /ais && pytest /ais/ais/tests/api/ -vvv -ra --showlocals --tb=native'

- name: Confirm nginx configuration is good
run: docker exec ais bash -c 'nginx -t'

- name: Simple curl query check
run: curl http://localhost:8080/search/1234%20Market%20Street


# https://github.com/marketplace/actions/microsoft-teams-notification
- name: Notify job progress
if: always()
uses: jdcargile/[email protected]
with:
GITHUB-TOKEN: ${{ github.token }}
ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: Build status; ${{ job.status }} for branch ${{ env.GITHUB_REF }}
notification-color: ${{ job.status == 'success' && '28a745' || 'dc3545' }}
timezone: America/New_York
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# ignore migrations folder
migrations/

# Intermediate files using for swapping DNS records
route53-prod-change.json
route53-stage-change.json

# ignore this config file
ais-config.sh

# Git keys
passyunk-private.key
passyunk-public.key
*.key

log/

# docker-compose build secrets
config-secrets.sh
config-secrets.py
route53-change.json
*.csv


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -56,6 +80,10 @@ local_settings.py
# Flask instance folder
instance/*

# AIS supplemental bash config
ais-config.sh
ais/engine/bin/ais-config.sh

# Sphinx documentation
docs/_build/

Expand All @@ -67,6 +95,7 @@ target/

# pyenv
.python-version
venv

# dotenv
.env
Expand All @@ -89,3 +118,8 @@ instance/config.py
ais/engine/log/
tmp/
ais/api/profiling/

.vscode/

# migrations
/migrations/
Loading
Loading