Skip to content

Commit 98abfe4

Browse files
Merge branch 'qa' into production
2 parents 8a283af + 330b1a0 commit 98abfe4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1043
-1761
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to production if tagged as production release
2+
3+
on:
4+
release:
5+
types: [ released ]
6+
7+
permissions:
8+
id-token: write
9+
contents: read
10+
11+
jobs:
12+
check_production_tag:
13+
name: Check if the release is tagged as production
14+
runs-on: ubuntu-latest
15+
outputs:
16+
has_production_tag: ${{ steps.check-production-tag.outputs.run_jobs }}
17+
steps:
18+
- name: check production tag ${{ github.ref }}
19+
id: check-production-tag
20+
run: |
21+
if [[ ${{ github.ref }} =~ refs\/tags\/production ]]; then
22+
echo "run_jobs=true" >> $GITHUB_OUTPUT
23+
else
24+
echo "run_jobs=false" >> $GITHUB_OUTPUT
25+
fi
26+
publish_production:
27+
needs: [ check_production_tag ]
28+
if: needs.check_production_tag.outputs.has_production_tag == 'true'
29+
name: Publish image to ECR and update ECS stack
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout repo
33+
uses: actions/checkout@v3
34+
35+
- name: Configure AWS credentials
36+
uses: aws-actions/configure-aws-credentials@v2
37+
with:
38+
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
39+
aws-region: us-east-1
40+
41+
- name: Login to Amazon ECR
42+
id: login-ecr
43+
uses: aws-actions/amazon-ecr-login@v1
44+
45+
- name: Build, tag, and push image to Amazon ECR
46+
env:
47+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
48+
ECR_REPOSITORY: pc-reserve-poller
49+
IMAGE_TAG: ${{ github.sha }}
50+
run: |
51+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
52+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
53+
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
54+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
55+
56+
- name: Force ECS Update
57+
run: |
58+
aws ecs update-service --cluster pc-reserve-poller-production --service pc-reserve-poller-app-production --force-new-deployment

.github/workflows/deploy-qa.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to QA if tagged as QA release
2+
3+
on:
4+
release:
5+
types: [ released ]
6+
7+
permissions:
8+
id-token: write
9+
contents: read
10+
11+
jobs:
12+
check_qa_tag:
13+
name: Check if the release is tagged as QA
14+
runs-on: ubuntu-latest
15+
outputs:
16+
has_qa_tag: ${{ steps.check-qa-tag.outputs.run_jobs }}
17+
steps:
18+
- name: check qa tag ${{ github.ref }}
19+
id: check-qa-tag
20+
run: |
21+
if [[ ${{ github.ref }} =~ refs\/tags\/qa ]]; then
22+
echo "run_jobs=true" >> $GITHUB_OUTPUT
23+
else
24+
echo "run_jobs=false" >> $GITHUB_OUTPUT
25+
fi
26+
publish_qa:
27+
needs: [ check_qa_tag ]
28+
if: needs.check_qa_tag.outputs.has_qa_tag == 'true'
29+
name: Publish image to ECR and update ECS stack
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout repo
33+
uses: actions/checkout@v3
34+
35+
- name: Configure AWS credentials
36+
uses: aws-actions/configure-aws-credentials@v2
37+
with:
38+
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
39+
aws-region: us-east-1
40+
41+
- name: Login to Amazon ECR
42+
id: login-ecr
43+
uses: aws-actions/amazon-ecr-login@v1
44+
45+
- name: Build, tag, and push image to Amazon ECR
46+
env:
47+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
48+
ECR_REPOSITORY: pc-reserve-poller
49+
IMAGE_TAG: ${{ github.sha }}
50+
run: |
51+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
52+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
53+
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest
54+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest
55+
56+
- name: Force ECS Update
57+
run: |
58+
aws ecs update-service --cluster pc-reserve-poller-qa --service pc-reserve-poller-app-qa --force-new-deployment

.github/workflows/run-tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Python unit tests
2+
3+
on:
4+
pull_request:
5+
actions: [ opened ]
6+
7+
jobs:
8+
changelog:
9+
name: Updates changelog
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: dangoslen/changelog-enforcer@v3
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Python 3.9
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.9'
24+
cache: 'pip'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements.txt
30+
31+
- name: Run linter and test suite
32+
run: |
33+
make lint
34+
make test

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
2-
.env
3-
Gemfile.lock
4-
vendor/
5-
local_logs/
2+
__pycache__/
3+
.vscode/
4+
*env/
5+
*.py[cod]
6+
*$py.class

.rspec

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## 2023-07-12 -- v1.0.1
2+
### Fixed
3+
- Increase max Sierra query attempts to 10
4+
5+
## 2023-07-07 -- v1.0.0
6+
### Fixed
7+
- Manually set Sierra query timeout to 5 minutes in order to prevent a bug in ECS where a query will time out after 10 minutes (the PostgreSQL default) but the error will not be propagated and the connection will hang for the next 2 hours. Through trial and error, 5 minutes was found to be the maximum timeout before this bug occurs. The root cause of the bug is still unknown.
8+
9+
## 2023-06-29 -- v0.0.4
10+
### Added
11+
- Updated `configure-aws-credentials` GitHub action version
12+
- Updated `nypl-py-utils` version
13+
- Only convert datatypes where necessary -- ensures patron ids are obfuscated as integer strings
14+
15+
## 2023-05-25 -- v0.0.3
16+
### Fixed
17+
- If a barcode corresponds to multiple Sierra patron records, do not use any of the patron info
18+
- Handle second Sierra query timeout
19+
20+
## 2023-05-24 -- v0.0.2
21+
### Fixed
22+
- Added retry if Sierra query times out
23+
24+
## 2023-04-14 -- v0.0.1
25+
### Added
26+
- Initial python commit

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
FROM ruby:2.7
2-
1+
FROM python:3.9
32
ADD . /src
4-
53
WORKDIR /src
64

7-
RUN bundle lock
8-
RUN bundle config set deployment 'true'
9-
RUN bundle install
5+
COPY requirements.txt ./
6+
RUN pip install --upgrade pip && \
7+
pip install -r requirements.txt
108

11-
CMD ["bundle", "exec", "./index.rb"]
9+
COPY . .
10+
CMD [ "python3", "./main.py"]

Gemfile

Lines changed: 0 additions & 14 deletions
This file was deleted.

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DEFAULT: help
2+
3+
help:
4+
@echo "make help"
5+
@echo " display this help statement"
6+
@echo "make run"
7+
@echo " run the application in development mode"
8+
@echo "make test"
9+
@echo " run associated test suite with pytest"
10+
@echo "make lint"
11+
@echo " lint project files using the flake8 linter"
12+
13+
run:
14+
export ENVIRONMENT=devel; \
15+
python main.py
16+
17+
test:
18+
pytest
19+
20+
lint:
21+
flake8 --exclude *env

0 commit comments

Comments
 (0)