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 -}}

0 commit comments

Comments
 (0)