Skip to content

Commit 6ac6538

Browse files
authored
chore: tear down application services and simplify the remaining container application (#3975)
2 parents bbfa744 + 096c3ec commit 6ac6538

27 files changed

Lines changed: 122 additions & 370 deletions

.env.sample

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ DJANGO_DB_FIXTURES="benefits/core/migrations/local_fixtures.json"
99
DJANGO_DEBUG_TOOLBAR=false
1010
# DJANGO_LOCAL_PORT=
1111

12-
USE_POSTGRES=false
13-
14-
# Django Database settings (SQLite)
15-
DJANGO_DB_FILE=django.db
16-
DJANGO_DB_RESET=true
17-
18-
# Django Database settings (Postgres)
12+
# Django Database settings
1913
DJANGO_DB_NAME=django
2014
DJANGO_DB_USER=django
2115
DJANGO_DB_PASSWORD=django_password

.github/workflows/deploy.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ jobs:
149149
push: true
150150
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
151151

152-
# deploy application service
153-
- name: Deploy to Azure Web App
154-
uses: azure/webapps-deploy@v2
155-
with:
156-
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
157-
images: ghcr.io/${{ github.repository }}:${{ github.sha }}
158-
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
159-
160152
# begin setup to deploy container app
161153
- name: Log in to azure using federated identity credentials
162154
uses: azure/login@f5d393ae46f8fde4be8b75f32e3fc50e654ad0ca # v3
@@ -178,7 +170,6 @@ jobs:
178170
working-directory: terraform
179171
env:
180172
TF_VAR_CONTAINER_TAG: ${{ github.sha }}
181-
TF_VAR_DEVSECOPS_OBJECT_ID: ${{ secrets.TF_VAR_DEVSECOPS_OBJECT_ID }}
182173
TF_VAR_ENGINEERING_GROUP_OBJECT_ID: ${{ secrets.TF_VAR_ENGINEERING_GROUP_OBJECT_ID }}
183174
TF_VAR_sp_apply_object_id: ${{ secrets.AZURE_SP_OBJECT_ID }}
184175
TF_VAR_sp_plan_object_id: ${{ secrets.AZURE_SP_PLAN_OBJECT_ID }}

.github/workflows/terraform-plan.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
- name: Terraform Plan
5050
env:
5151
TF_VAR_CONTAINER_TAG: ${{ steps.get_main_sha.outputs.sha }}
52-
TF_VAR_DEVSECOPS_OBJECT_ID: ${{ secrets.TF_VAR_DEVSECOPS_OBJECT_ID }}
5352
TF_VAR_ENGINEERING_GROUP_OBJECT_ID: ${{ secrets.TF_VAR_ENGINEERING_GROUP_OBJECT_ID }}
5453
TF_VAR_sp_apply_object_id: ${{ secrets.AZURE_SP_DEV_OBJECT_ID }}
5554
TF_VAR_sp_plan_object_id: ${{ secrets.AZURE_SP_PLAN_OBJECT_ID }}

.github/workflows/tests-pytest.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ on:
1212
jobs:
1313
pytest:
1414
runs-on: ubuntu-latest
15+
1516
permissions:
1617
# Gives the action the necessary permissions for publishing new
1718
# comments in pull requests.
1819
pull-requests: write
1920
# Gives the action the necessary permissions for pushing data to the
20-
# python-coverage-comment-action branch, and for editing existing
21+
# python-coverage-comment-action-data branch, and for editing existing
2122
# comments (to avoid publishing multiple comments in the same PR)
2223
contents: write
2324
steps:
@@ -40,7 +41,7 @@ jobs:
4041

4142
- name: Run setup
4243
run: |
43-
python manage.py migrate
44+
python manage.py migrate --settings=tests.pytest.settings
4445
python manage.py compilemessages
4546
python manage.py collectstatic --no-input
4647

appcontainer/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ http {
7474

7575
# path for uploaded files
7676
location /media/ {
77-
alias /home/calitp/app/data/uploads/;
77+
alias /calitp/app/data/uploads/;
7878
expires 1y;
7979
add_header Cache-Control public;
8080
}

benefits/settings.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -195,40 +195,32 @@ def RUNTIME_ENVIRONMENT():
195195
WSGI_APPLICATION = "benefits.wsgi.application"
196196

197197
STORAGE_DIR = os.environ.get("DJANGO_STORAGE_DIR", BASE_DIR)
198-
USE_POSTGRES = os.environ.get("USE_POSTGRES", "false").lower() == "true"
199198

200199
sslmode = os.environ.get("POSTGRES_SSLMODE", "verify-full")
201200
sslrootcert = "/etc/ssl/certs/ca-certificates.crt" if sslmode == "verify-full" else None
202201

203-
if USE_POSTGRES:
204-
DATABASES = {
205-
"default": {
206-
"ENGINE": "django.db.backends.postgresql",
207-
"NAME": os.environ.get("DJANGO_DB_NAME", "django"),
208-
"USER": os.environ.get("DJANGO_DB_USER", "django"),
209-
"PASSWORD": os.environ.get("DJANGO_DB_PASSWORD"),
210-
"HOST": os.environ.get("POSTGRES_HOSTNAME", "postgres"),
211-
"PORT": os.environ.get("POSTGRES_PORT", "5432"),
212-
"OPTIONS": {
213-
"sslmode": sslmode,
214-
"sslrootcert": sslrootcert,
215-
# add these lines to enable TCP keepalives --
216-
# tiny network packets that keep the connection active and prevent
217-
# network hardware or the database server from thinking it's idle
218-
"keepalives": 1,
219-
"keepalives_idle": 60,
220-
"keepalives_interval": 10,
221-
"keepalives_count": 5,
222-
},
223-
}
224-
}
225-
else:
226-
DATABASES = {
227-
"default": {
228-
"ENGINE": "django.db.backends.sqlite3",
229-
"NAME": os.path.join(STORAGE_DIR, os.environ.get("DJANGO_DB_FILE", "django.db")),
230-
}
202+
DATABASES = {
203+
"default": {
204+
"ENGINE": "django.db.backends.postgresql",
205+
"NAME": os.environ.get("DJANGO_DB_NAME", "django"),
206+
"USER": os.environ.get("DJANGO_DB_USER", "django"),
207+
"PASSWORD": os.environ.get("DJANGO_DB_PASSWORD"),
208+
"HOST": os.environ.get("POSTGRES_HOSTNAME", "postgres"),
209+
"PORT": os.environ.get("POSTGRES_PORT", "5432"),
210+
"OPTIONS": {
211+
"sslmode": sslmode,
212+
"sslrootcert": sslrootcert,
213+
# add these lines to enable TCP keepalives --
214+
# tiny network packets that keep the connection active and prevent
215+
# network hardware or the database server from thinking it's idle
216+
"keepalives": 1,
217+
"keepalives_idle": 60,
218+
"keepalives_interval": 10,
219+
"keepalives_count": 5,
220+
},
231221
}
222+
}
223+
232224

233225
# Password handling
234226

bin/setup.sh

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
USE_POSTGRES="${USE_POSTGRES:-false}"
5-
6-
if [[ $USE_POSTGRES == "true" ]]; then
7-
# Ensure databases, users, migrations, and superuser are set up
8-
should_reset=${REMOTE_CONTAINERS:-false}
9-
if [[ $should_reset == "true" ]]; then
10-
# running in a devcontainer, reset the DB
11-
python manage.py ensure_db --reset
12-
else
13-
python manage.py ensure_db
14-
fi
4+
# Ensure databases, users, migrations, and superuser are set up
5+
should_reset=${REMOTE_CONTAINERS:-false}
6+
if [[ $should_reset == "true" ]]; then
7+
# running in a devcontainer, reset the DB
8+
python manage.py ensure_db --reset
159
else
16-
# construct the path to the database file from environment or default
17-
DB_DIR="${DJANGO_STORAGE_DIR:-.}"
18-
DB_FILE="${DJANGO_DB_FILE:-django.db}"
19-
DB_PATH="${DB_DIR}/${DB_FILE}"
20-
21-
if ! [[ -f "${DB_PATH}" ]]; then
22-
# definitely reset if the database file is not found
23-
DB_RESET=true
24-
else
25-
# use the DJANGO_DB_RESET env var or default to false
26-
DB_RESET="${DJANGO_DB_RESET:-false}"
27-
fi
28-
29-
if [[ $DB_RESET = true ]]; then
30-
echo "DB_RESET is true, deleting existing DB (if present)"
31-
rm -f "${DB_PATH}"
32-
33-
# run database migrations
34-
python manage.py migrate
35-
36-
# create a superuser account for backend admin access
37-
# set username, email, and password using environment variables
38-
# DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL, and DJANGO_SUPERUSER_PASSWORD
39-
python manage.py createsuperuser --no-input
40-
else
41-
echo "DB_RESET is false, migrating existing database"
42-
python manage.py migrate
43-
fi
10+
python manage.py ensure_db
4411
fi
4512

4613
valid_fixtures=$(echo "$DJANGO_DB_FIXTURES" | grep -e fixtures\.json$ || test $? = 1)

docs/explanation/deployment.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Deployment
22

3-
The Benefits app is currently deployed into a Microsoft Azure account provided by [California Department of Technology (CDT)'s Office of Enterprise Technology (OET)][oet], a.k.a. the "DevSecOps" team. More specifically, it uses [custom containers][app-service-containers] on [Azure App Service][app-service]. [More about the infrastructure.](infrastructure.md)
3+
The Benefits app is currently deployed into a Microsoft Azure account provided by [California Department of Technology (CDT)'s Office of Enterprise Technology (OET)][oet], a.k.a. the "DevSecOps" team. More specifically, it uses [Azure Container Apps][container-apps]. [More about the infrastructure.](infrastructure.md)
44

55
## Deployment process
66

77
The Django application gets built into a [Docker image][dockerfile] with [NGINX](https://www.nginx.com/) and
88
[Gunicorn](https://gunicorn.org/). SQLite is used within that same container to store configuration data; there is no external database.
99

10-
The application is deployed to an [Azure Web App Container][az-webapp] using three separate environments for `dev`, `test`,
10+
The application is deployed to an [Azure Container App][container-apps] using three separate environments for `dev`, `test`,
1111
and `prod`.
1212

1313
The [Deploy][deploy-workflow] workflow is responsible for building that branch's image and pushing to [GitHub Container
14-
Registry (GHCR)][ghcr]. It also deploys to the Azure Web App, telling Azure to restart the app and pull the latest image.
14+
Registry (GHCR)][ghcr]. It also deploys to the Azure Container App, telling Azure to restart the app and pull the latest image.
1515

1616
You can view what Git commit is deployed for a given environment by visiting the URL path `/static/sha.txt`.
1717

@@ -42,9 +42,9 @@ Build the root [`Dockerfile`][dockerfile], tagging with the SHA from the HEAD co
4242

4343
Push this image:tag into [GHCR][ghcr].
4444

45-
### 4. App Service deploy
45+
### 4. Container App deploy
4646

47-
Push the new image:tag to the Azure App Service instance.
47+
Push the new image:tag to the Azure Container App.
4848

4949
## Configuration
5050

@@ -59,10 +59,8 @@ Docker images for each of the deploy branches are available from GitHub Containe
5959
- Image path: `ghcr.io/cal-itp/benefits`
6060

6161
[oet]: https://techblog.cdt.ca.gov/2020/06/cdt-taking-the-lead-in-digital-transformation/
62-
[app-service-containers]: https://docs.microsoft.com/en-us/azure/app-service/configure-custom-container
63-
[app-service]: https://docs.microsoft.com/en-us/azure/app-service/overview
62+
[container-apps]: https://learn.microsoft.com/en-us/azure/container-apps/overview
6463
[deploy-workflow]: https://github.com/cal-itp/benefits/blob/main/.github/workflows/deploy.yml
65-
[az-webapp]: https://azure.microsoft.com/en-us/services/app-service/containers/
6664
[ghcr]: https://github.com/features/packages
6765
[deploy]: https://github.com/cal-itp/benefits/blob/main/.github/workflows/deploy.yml
6866
[dockerfile]: https://github.com/cal-itp/benefits/blob/main/appcontainer/Dockerfile

docs/explanation/infrastructure.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ flowchart LR
5959
subgraph Azure
6060
frontdoor --> NGINX
6161
62-
subgraph App Service
63-
subgraph Custom container
64-
direction TB
65-
NGINX --> django
66-
end
62+
subgraph Container App
63+
direction TB
64+
NGINX --> django
6765
end
6866
end
6967
```
@@ -123,23 +121,23 @@ The DevSecOps team sets the following naming convention for Resources:
123121
### Sample Names
124122

125123
- `RG-CDT-PUB-VIP-BNSCN-E-D-001`
126-
- `ASP-CDT-PUB-VIP-BNSCN-EL-P-001`
127-
- `AS-CDT-PUB-VIP-BNSCN-EL-D-001`
124+
- `CAE-CDT-PUB-VIP-BNSCN-EL-P-001`
125+
- `CA-CDT-PUB-VIP-BNSCN-EL-D-001`
128126

129127
### Resource Types
130128

131129
Use the following shorthand for conveying the Resource Type as part of the Resource Name:
132130

133-
| Resource | Convention |
134-
| ---------------- | ---------- |
135-
| App Service | `AS` |
136-
| App Service Plan | `ASP` |
137-
| Virtual Network | `VNET` |
138-
| Resource Group | `RG` |
139-
| Virtual Machine | `VM` |
140-
| Database | `DB` |
141-
| Subnet | `SNET` |
142-
| Front Door | `FD` |
131+
| Resource | Convention |
132+
| -------------------------- | ---------- |
133+
| Container Apps Environment | `CAE` |
134+
| Container App | `CA` |
135+
| Virtual Network | `VNET` |
136+
| Resource Group | `RG` |
137+
| Virtual Machine | `VM` |
138+
| Database | `DB` |
139+
| Subnet | `SNET` |
140+
| Front Door | `FD` |
143141

144142
## Making changes
145143

@@ -199,6 +197,6 @@ These steps were followed when setting up our Azure deployment for the first tim
199197
- CDT team creates the [resources that they own](#ownership)
200198
- `terraform apply`
201199
- Set up Slack notifications by [creating a Slack email](https://slack.com/help/articles/206819278-Send-emails-to-Slack) for the [#notify-benefits](https://cal-itp.slack.com/archives/C022HHSEE3F) channel, then [setting it as a Secret in the Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal#add-a-secret-to-key-vault) named `slack-benefits-notify-email`
202-
- Set required [App Service configuration](../reference/environment-variables.md) and [configuration](../tutorials/load-sample-data.md) by setting values in Key Vault (the mapping is defined in [app_service.tf](https://github.com/cal-itp/benefits/blob/main/terraform/app_service.tf))
200+
- Set required [Container App configuration](../reference/environment-variables.md) and [configuration](../tutorials/load-sample-data.md) by setting values in Key Vault (the mapping is defined in [app_service.tf](https://github.com/cal-itp/benefits/blob/main/terraform/app_service.tf))
203201

204202
This is not a complete step-by-step guide; more a list of things to remember. This may be useful as part of [incident response](https://docs.google.com/document/d/1qtev8qItPiTB4Tp9FQ87XsLtWZ4HlNXqoe9vF2VuGcY/edit#).

docs/guides/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ Compiler developers, be sure to follow the instructions in the [Django Admin upd
128128

129129
If you have a need to maintain some test data that you've added via the Django Admin across multiple development sessions:
130130

131-
1. Set `DJANGO_DB_RESET=false` in your `.env` file
132131
1. Create a new set of temporary fixtures:
133132
```bash
134133
python manage.py dumpdata --indent 2 --output benefits/core/migrations/temp_fixtures.json
135134
```
135+
136136
- It's important that the filename end in `fixtures.json` so that it's ignored by Git.
137137
1. Set `DJANGO_DB_FIXTURES` to the path of the new file you just created in `.env`
138138
1. Rebuild the devcontainer

0 commit comments

Comments
 (0)