Skip to content

Commit 6a23ef5

Browse files
authored
Support Platform CLI (#240)
Switch to the Platform CLI[1] for install/update. - Add `copier.yml` config file - Move template files into `template/` - And tag the app services in Compose files with `{{app_name}}` - Move `.hadolint.yaml` and `.dockleconfig` from project root to `{{app_name}}/`. Upstream scanning CI has been updated to apply app-specific configs when running for those apps. - Remove old install/update scripts - Update from unsupported GitHub actions - Update template CD to use platform-cli [1] https://github.com/navapbc/platform-cli https://github.com/navapbc/template-application-nextjs
1 parent f715d8d commit 6a23ef5

File tree

141 files changed

+165
-220
lines changed

Some content is hidden

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

141 files changed

+165
-220
lines changed

.github/workflows/template-only-cd.yml renamed to .github/cd.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,43 @@ on:
77
workflow_dispatch:
88

99
# Only allow one workflow at a time to prevent race conditions when pushing changes to the project repo
10-
concurrency: template-only-cd
10+
concurrency: cd
1111

1212
jobs:
1313
deploy:
1414
name: Deploy
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout template repo
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919
with:
2020
path: template-application-flask
21+
2122
- name: Checkout project repo
22-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2324
with:
2425
path: project-repo
2526
repository: navapbc/platform-test-flask
2627
token: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }}
2728

28-
- name: Update application template
29-
working-directory: project-repo
30-
run: ../template-application-flask/template-only-bin/update-template.sh
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.13'
3133

32-
- name: Push changes to project repo
34+
- name: Install nava-platform CLI
35+
run: pipx install --python "$(which python)" git+https://github.com/navapbc/platform-cli
36+
37+
- name: Configure git
3338
working-directory: project-repo
3439
run: |
3540
git config user.name nava-platform-bot
3641
git config user.email [email protected]
37-
git add --all
38-
# Commit changes (if no changes then no-op)
39-
git diff-index --quiet HEAD || git commit -m "Template application deploy #${{ github.run_id }}"
40-
git push
42+
43+
- name: Update application template
44+
working-directory: project-repo
45+
run: nava-platform app update --template-uri ${{ github.server_url }}/${{ github.repository }} --version HEAD . app
46+
47+
- name: Push changes to project repo
48+
working-directory: project-repo
49+
run: git push

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@ The template application is intended to work with the infrastructure from [templ
1919

2020
To get started using the template application on your project:
2121

22-
1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory.
23-
24-
```bash
25-
curl https://raw.githubusercontent.com/navapbc/template-application-flask/main/template-only-bin/download-and-install-template.sh | bash -s
22+
1. [Install the nava-platform tool](https://github.com/navapbc/platform-cli).
23+
2. Install template by running in your project's root:
24+
```sh
25+
nava-platform app install --template-uri https://github.com/navapbc/template-application-flask . <APP_NAME>
2626
```
27-
28-
This script will:
29-
30-
1. Clone the template repository
31-
2. Copy the template files into your project directory
32-
3. Remove any files specific to the template repository.
33-
2. Optional, if using the Platform infra template: [Follow the steps in the `template-infra` README](https://github.com/navapbc/template-infra#installation) to set up the various pieces of your infrastructure.
27+
3. Follow the steps in `/docs/<APP_NAME>/getting-started.md` to set up the application locally.
28+
4. Optional, if using the Platform infrastructure template: [Follow the steps in the `template-infra` README](https://github.com/navapbc/template-infra#installation) to set up the various pieces of your infrastructure.
3429

3530
## Note on memory usage
3631

37-
If you are using [template-infra](https://github.com/navapbc/template-infra), you may want to increase the [default memory](https://github.com/navapbc/template-infra/blob/main/infra/modules/service/variables.tf#L33) allocated to the ECS service to 2048 Mb (2 Gb) to avoid the gunicorn workers running out of memory. This is because the application is currently [configured to create multiple workers](https://github.com/navapbc/template-application-flask/blob/main/app/gunicorn.conf.py#L24) based on the number of virtual CPUs available, which can take up more memory.
38-
39-
## Getting started
40-
41-
Now you're ready to [get started](/docs/app/getting-started.md).
32+
If you are using [template-infra](https://github.com/navapbc/template-infra),
33+
you may want to increase the [default
34+
memory](https://github.com/navapbc/template-infra/blob/main/infra/modules/service/variables.tf#L33)
35+
allocated to the ECS service to 2048 Mb (2 Gb) to avoid the gunicorn workers
36+
running out of memory. This is because the application is currently configured
37+
to create multiple workers based on the number of virtual CPUs available, which
38+
can take up more memory (see `/<APP_NAME>/gunicorn.conf.py`).

copier.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# App vars
3+
#
4+
app_name:
5+
type: str
6+
help: The name of the app
7+
validator: >-
8+
{% if not (app_name | regex_search('^[a-z0-9\-_]+$')) %}
9+
The app name can not be empty and should only contain lower case letters, digits, dashes, and underscores.
10+
{% endif %}
11+
12+
app_local_port:
13+
type: int
14+
help: "The port to be used in local development of '{{ app_name }}'"
15+
default: 3000
16+
17+
_envops:
18+
trim_blocks: true
19+
lstrip_blocks: true
20+
21+
# ideally we could just:
22+
#
23+
# _answers_file: .template-application-flask/{{app_name}}.yml
24+
#
25+
# but alas, no:
26+
#
27+
# https://github.com/copier-org/copier/issues/1868
28+
29+
_subdirectory: template

docs/app/api-details.md

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

template-only-bin/download-and-install-template.sh

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

template-only-bin/install-template.sh

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

template-only-bin/update-template.sh

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

.github/workflows/ci-openapi.yml renamed to template/.github/workflows/ci-{{app_name}}-openapi.yml.jinja

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ name: Update OpenAPI Docs
44
on:
55
pull_request:
66
paths:
7-
- app/**
7+
- {{app_name}}/**
88
- Makefile
9-
- .github/workflows/ci-openapi.yml
9+
- .github/workflows/ci-{{app_name}}-openapi.yml
1010

1111
defaults:
1212
run:
@@ -16,18 +16,18 @@ defaults:
1616
# If new commits are pushed to the branch, cancel in progress runs and start
1717
# a new one.
1818
concurrency:
19-
group: ${{ github.head_ref }}
19+
group: ${{'{{'}} github.head_ref {{'}}'}}
2020
cancel-in-progress: true
2121

2222

2323
jobs:
2424
update-openapi-docs:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
with:
2929
# Checkout the feature branch associated with the pull request
30-
ref: ${{ github.head_ref }}
30+
ref: ${{'{{'}} github.head_ref {{'}}'}}
3131

3232
- name: Update OpenAPI spec
3333
run: make openapi-spec

.github/workflows/ci-app.yml renamed to template/.github/workflows/ci-{{app_name}}.yml.jinja

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
name: CI - App
1+
name: CI - {{app_name}}
22

33
on:
44
push:
55
branches:
66
- main
77
paths:
8-
- app/**
9-
- .github/workflows/ci-app.yml
8+
- {{app_name}}/**
9+
- .github/workflows/ci-{{app_name}}.yml
1010
pull_request:
1111
paths:
12-
- app/**
13-
- .github/workflows/ci-app.yml
12+
- {{app_name}}/**
13+
- .github/workflows/ci-{{app_name}}.yml
1414

1515
defaults:
1616
run:
17-
working-directory: ./app
17+
working-directory: ./{{app_name}}
1818

1919
jobs:
2020
# As an enhancement, it is possible to share the built docker image and share
@@ -24,7 +24,7 @@ jobs:
2424
name: Lint
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828

2929
- name: Run format check
3030
run: make format-check
@@ -35,15 +35,15 @@ jobs:
3535
name: Security scan
3636
runs-on: ubuntu-latest
3737
steps:
38-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@v4
3939

4040
- name: Run security linting
4141
run: make lint-security
4242
test:
4343
name: Test
4444
runs-on: ubuntu-latest
4545
steps:
46-
- uses: actions/checkout@v3
46+
- uses: actions/checkout@v4
4747

4848
- name: Start tests
4949
run: |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Changes here will be overwritten by Copier
2+
{{ _copier_answers|to_nice_yaml -}}

docs/decisions/0003-keep-generated-openapi-spec-to-source-control.md renamed to template/docs/decisions/0003-keep-generated-openapi-spec-to-source-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ With the switch from Connexion to APIFlask (see [Connection replacement ADR](./0
1818

1919
We chose to keep the openapi.yml file in source control because we want changes to the API to be called out explicitly so that developers do not accidentally make backwards-incompatible changes to the API as part of a code change. This is particularly important since the API spec is now implicit as the OpenAPI specification is automatically generated from the code.
2020

21-
We chose to keep the openapi.yml file in sync with the API application automatically using a [CI workflow that generates the OpenAPI and pushes and changes to the PR branch](../../.github/workflows/ci-openapi.yml). This reduces the amount of manual work required by the engineer compared to a CI check that only checks for diffs but does not make the change. That said, we don't feel strongly about this decision so are open to changes in the future.
21+
We chose to keep the openapi.yml file in sync with the API application automatically using a CI workflow that generates the OpenAPI and pushes and changes to the PR branch (`.github/workflows/ci-<APP_NAME>-openapi.yml`). This reduces the amount of manual work required by the engineer compared to a CI check that only checks for diffs but does not make the change. That said, we don't feel strongly about this decision so are open to changes in the future.
2222

2323
To minimize developer confusion, we chose to rename the `openapi.yml` file to `openapi.generated.yml` to clearly indicate that it is a generated file and not something that the developer should manually adjust.
File renamed without changes.
File renamed without changes.

docs/app/README.md renamed to template/docs/{{app_name}}/README.md.jinja

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ root
4646

4747
`make clean-volumes` will spin down the docker containers + delete the volumes. This can be useful to reset your DB, or fix any bad states your local environment may have gotten into.
4848

49-
See the [Makefile](/app/Makefile) for a full list of commands you can run.
49+
See the [Makefile](/{{ app_name }}/Makefile) for a full list of commands you can run.
5050

5151
## Docker and Native Development
5252

@@ -88,18 +88,18 @@ export DB_HOST=localhost
8888
And then running `direnv allow .` in the /app folder. You should see something like:
8989
```shell
9090
➜ template-application-flask git:(main) ✗ cd app
91-
direnv: loading ~/workspace/template-application-flask/app/.envrc
91+
direnv: loading ~/workspace/template-application-flask/{{ app_name }}/.envrc
9292
direnv: export +API_AUTH_TOKEN +AWS_ACCESS_KEY_ID +AWS_DEFAULT_REGION +AWS_SECRET_ACCESS_KEY +DB_HOST +DB_NAME +DB_PASSWORD +DB_SCHEMA +DB_SSL_MODE +DB_USER +ENVIRONMENT +FLASK_APP +HIDE_SQL_PARAMETER_LOGS +LOG_ENABLE_AUDIT +LOG_FORMAT +PORT +PYTHONPATH
9393
```
9494

9595
## Environment Variables
9696

9797
Most configuration options are managed by environment variables.
9898

99-
Environment variables for local development are stored in the [local.env](/app/local.env) file. This file is automatically loaded when running. If running within Docker, this file is specified as an `env_file` in the [docker-compose](/app/docker-compose.yml) file, and loaded [by a script](/app/src/util/local.py) automatically when running unit tests (see running natively above for other cases).
99+
Environment variables for local development are stored in the [local.env](/{{ app_name }}/local.env) file. This file is automatically loaded when running. If running within Docker, this file is specified as an `env_file` in the [docker-compose](/{{ app_name }}/docker-compose.yml) file, and loaded [by a script](/{{ app_name }}/src/util/local.py) automatically when running unit tests (see running natively above for other cases).
100100
To override environment variables for locally, create an `override.env` file in the same directory as local.env. The docker-compose file [optionally checks this file](https://docs.docker.com/reference/compose-file/services/#required) as well.
101101

102-
Any environment variables specified directly in the [docker-compose](/app/docker-compose.yml) file will take precedent over those specified in the [local.env](/app/local.env) file.
102+
Any environment variables specified directly in the [docker-compose](/{{ app_name }}/docker-compose.yml) file will take precedent over those specified in the [local.env](/{{ app_name }}/local.env) file.
103103

104104
## Authentication
105105

@@ -117,7 +117,7 @@ The API can be run in debug mode that allows for remote attach debugging (curren
117117
- First create a file `./vscode/launch.json` - as shown below. (Default name of `Python: Remote Attach`)
118118

119119
- Start the server in debug mode via `make start-debug` or `make start-debug run-logs`.
120-
- This will start the `main-app` service with port 5678 exposed.
120+
- This will start the `{{ app_name }}` service with port 5678 exposed.
121121

122122
- The server will start in waiting mode, waiting for you to attach the debugger (see `/src/app.py`) before continuing to run.
123123

@@ -169,14 +169,14 @@ for any breaking changes of features you may use
169169

170170
### Upgrade Steps
171171
To upgrade the Python version, make changes in the following places:
172-
1. Local Python version (see more about managing local Python versions in [getting started](/docs/app/getting-started.md))
173-
2. [Dockerfile](/app/Dockerfile)
172+
1. Local Python version (see more about managing local Python versions in [getting started](/docs/{{ app_name }}/getting-started.md))
173+
2. [Dockerfile](/{{ app_name }}/Dockerfile)
174174
search for the line `FROM python:3.12-slim as base` - supported versions can be found on [Dockerhub](https://hub.docker.com/_/python)
175-
3. [pyproject.toml](/app/pyproject.toml)
175+
3. [pyproject.toml](/{{ app_name }}/pyproject.toml)
176176
search for the line
177177
```toml
178178
[tool.poetry.dependencies]
179179
python = "~3.12"
180180
```
181-
Then run `poetry lock --no-update` to update the [poetry.lock](/app/poetry.lock) file.
182-
4. [.python-version](/app/.python-version) which is used by tools like pyenv
181+
Then run `poetry lock --no-update` to update the [poetry.lock](/{{ app_name }}/poetry.lock) file.
182+
4. [.python-version](/{{ app_name }}/.python-version) which is used by tools like pyenv

0 commit comments

Comments
 (0)