Skip to content

Commit f09fb85

Browse files
authored
🔧 Simplify scripts and development (fastapi#155)
* 🔧 Update scripts and configs * 🔧 Add shebang to script * 🔥 Remove test and dev configs, pass inline * ✨ Add local development dev-link set up * 📝 Update generated docs with refactor * 📝 Add Contributing guide
1 parent a7fd258 commit f09fb85

13 files changed

+261
-152
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
testing-project
33
.mypy_cache
44
poetry.lock
5+
dev-link/

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ services:
99
- docker
1010

1111
script:
12-
- bash ./test.sh
12+
- bash ./scripts/test.sh

CONTRIBUTING.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Contributing
2+
3+
Here are some short guidelines to guide you if you want to contribute to the development of the Full Stack FastAPI PostgreSQL project generator itself.
4+
5+
After you clone the project, there are several scripts that can help during development.
6+
7+
* `./scripts/dev-fsfp.sh`:
8+
9+
Generate a new default project `dev-fsfp`.
10+
11+
Call it from one level above the project directory. So, if the project is at `~/code/full-stack-fastapi-postgresql/`, call it from `~/code/`, like:
12+
13+
```console
14+
$ cd ~/code/
15+
16+
$ bash ./full-stack-fastapi-postgresql/scripts/dev-fsfp.sh
17+
```
18+
19+
It will generate a new project with all the defaults at `~/code/dev-fsfp/`.
20+
21+
You can go to that directory with a full new project, edit files and test things, for example:
22+
23+
```console
24+
$ cd ./dev-fsfp/
25+
26+
$ docker-compose up -d
27+
```
28+
29+
It is outside of the project generator directory to let you add Git to it and compare versions and changes.
30+
31+
* `./scripts/dev-fsfp-back.sh`:
32+
33+
Move the changes from a project `dev-fsfp` back to the project generator.
34+
35+
You would call it after calling `./scripts/dev-fsfp.sh` and adding some modifications to `dev-fsfp`.
36+
37+
Call it from one level above the project directory. So, if the project is at `~/code/full-stack-fastapi-postgresql/`, call it from `~/code/`, like:
38+
39+
```console
40+
$ cd ~/code/
41+
42+
$ bash ./full-stack-fastapi-postgresql/scripts/dev-fsfp-back.sh
43+
```
44+
45+
That will also contain all the generated files with the generated variables, but it will let you compare the changes in `dev-fsfp` and the source in the project generator with git, and see what to commit.
46+
47+
* `./scripts/discard-dev-files.sh`:
48+
49+
After using `./scripts/dev-fsfp-back.sh`, there will be a bunch of generated files with the variables for the generated project that you don't want to commit, like `README.md` and `.gitlab-ci.yml`.
50+
51+
To discard all those changes at once, run `discard-dev-files.sh` from the root of the project, e.g.:
52+
53+
```console
54+
$ cd ~/code/full-stack-fastapi-postgresql/
55+
56+
$ bash ./scripts/dev-fsfp-back.sh
57+
```
58+
59+
* `./scripts/test.sh`:
60+
61+
Run the tests. It creates a project `testing-project` *inside* of the project generator and runs its tests.
62+
63+
Call it from the root of the project, e.g.:
64+
65+
```console
66+
$ cd ~/code/full-stack-fastapi-postgresql/
67+
68+
$ bash ./scripts/test.sh
69+
```
70+
71+
* `./scripts/dev-link.sh`:
72+
73+
Set up a local directory with links to the files for live development with the source files.
74+
75+
This script generates a project `dev-link` *inside* the project generator, just to generate the `.env` and `./frontend/.env` files.
76+
77+
Then it removes everything except those 2 files.
78+
79+
Then it creates links for each of the source files, and adds those 2 files back.
80+
81+
The end result is that you can go into the `dev-link` directory and develop locally with it as if it was a generated project, with all the variables set. But all the changes are actually done directly in the source files.
82+
83+
This is probably a lot faster to iterate than using `./scripts/dev-fsfp.sh`. But it's tested only in Linux, it might not work in other systems.

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ The input variables, with their default values (some auto generated) are:
117117
* `pgadmin_default_user_password`: PGAdmin default user password. Generate it with the method above.
118118

119119
* `traefik_constraint_tag`: The tag to be used by the internal Traefik load balancer (for example, to divide requests between backend and frontend) for production. Used to separate this stack from any other stack you might have. This should identify each stack in each environment (production, staging, etc).
120-
* `traefik_constraint_tag_staging`: The Traefik tag to be used while on staging.
120+
* `traefik_constraint_tag_staging`: The Traefik tag to be used while on staging.
121121
* `traefik_public_constraint_tag`: The tag that should be used by stack services that should communicate with the public.
122122

123-
* `flower_auth`: Basic HTTP authentication for flower, in the form`user:password`. By default: "`root:changethis`".
123+
* `flower_auth`: Basic HTTP authentication for flower, in the form`user:password`. By default: "`admin:changethis`".
124124

125-
* `sentry_dsn`: Key URL (DSN) of Sentry, for live error reporting. If you are not using it yet, you should, is open source. E.g.: `https://1234abcd:[email protected]/30`.
125+
* `sentry_dsn`: Key URL (DSN) of Sentry, for live error reporting. You can use the open source version or a free account. E.g.: `https://1234abcd:[email protected]/30`.
126126

127127
* `docker_image_prefix`: Prefix to use for Docker image names. If you are using GitLab Docker registry it would be based on your code repository. E.g.: `git.example.com/development-team/my-awesome-project/`.
128128
* `docker_image_backend`: Docker image name for the backend. By default, it will be based on your Docker image prefix, e.g.: `git.example.com/development-team/my-awesome-project/backend`. And depending on your environment, a different tag will be appended ( `prod`, `stag`, `branch` ). So, the final image names used will be like: `git.example.com/development-team/my-awesome-project/backend:prod`.
@@ -141,7 +141,7 @@ After using this generator, your new project (the directory created) will contai
141141

142142
## Sibling project generators
143143

144-
* Based on Couchbase: [https://github.com/tiangolo/full-stack-fastapi-couchbase](https://github.com/tiangolo/full-stack-fastapi-couchbase).
144+
* Full Stack FastAPI Couchbase: [https://github.com/tiangolo/full-stack-fastapi-couchbase](https://github.com/tiangolo/full-stack-fastapi-couchbase).
145145

146146
## Release Notes
147147

dev-fsfp-config.yml

-2
This file was deleted.

dev-fsfp.sh

-10
This file was deleted.

dev-fsfp-back.sh scripts/dev-fsfp-back.sh

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# Exit in case of error
66
set -e
77

8+
if [ ! -d ./full-stack-fastapi-postgresql ] ; then
9+
echo "Run this script from outside the project, to integrate a sibling dev-fsfp project with changes and review modifications"
10+
exit 1
11+
fi
12+
813
if [ $(uname -s) = "Linux" ]; then
914
echo "Remove __pycache__ files"
1015
sudo find ./dev-fsfp/ -type d -name __pycache__ -exec rm -r {} \+

scripts/dev-fsfp.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env bash
2+
3+
# Exit in case of error
4+
set -e
5+
6+
if [ ! -d ./full-stack-fastapi-postgresql ] ; then
7+
echo "Run this script from outside the project, to generate a sibling dev-fsfp project with independent git"
8+
exit 1
9+
fi
10+
11+
rm -rf ./dev-fsfp
12+
13+
cookiecutter --no-input -f ./full-stack-fastapi-postgresql project_name="Dev FSFP"

scripts/dev-link.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/env bash
2+
3+
# Exit in case of error
4+
set -e
5+
6+
# Run this from the root of the project to generate a dev-link project
7+
# It will contain a link to each of the files of the generator, except for
8+
# .env and frontend/.env, that will be the generated ones
9+
# This allows developing with a live stack while keeping the same source code
10+
# Without having to generate dev-fsfp and integrating back all the files
11+
12+
rm -rf dev-link
13+
mkdir -p tmp-dev-link/frontend
14+
15+
cookiecutter --no-input -f ./ project_name="Dev Link"
16+
17+
mv ./dev-link/.env ./tmp-dev-link/
18+
mv ./dev-link/frontend/.env ./tmp-dev-link/frontend/
19+
20+
rm -rf ./dev-link/
21+
mkdir -p ./dev-link/
22+
23+
cd ./dev-link/
24+
25+
for f in ../\{\{cookiecutter.project_slug\}\}/* ; do
26+
ln -s "$f" ./
27+
done
28+
29+
cd ..
30+
31+
mv ./tmp-dev-link/.env ./dev-link/
32+
mv ./tmp-dev-link/frontend/.env ./dev-link/frontend/
33+
34+
rm -rf ./tmp-dev-link

scripts/discard-dev-files.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
15
rm -rf \{\{cookiecutter.project_slug\}\}/.git
26
rm -rf \{\{cookiecutter.project_slug\}\}/backend/app/poetry.lock
37
rm -rf \{\{cookiecutter.project_slug\}\}/frontend/node_modules
48
rm -rf \{\{cookiecutter.project_slug\}\}/frontend/dist
59
git checkout \{\{cookiecutter.project_slug\}\}/README.md
610
git checkout \{\{cookiecutter.project_slug\}\}/.gitlab-ci.yml
711
git checkout \{\{cookiecutter.project_slug\}\}/cookiecutter-config-file.yml
8-
git checkout \{\{cookiecutter.project_slug\}\}/docker-compose.deploy.networks.yml
912
git checkout \{\{cookiecutter.project_slug\}\}/.env
1013
git checkout \{\{cookiecutter.project_slug\}\}/frontend/.env
11-

test.sh scripts/test.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# Exit in case of error
44
set -e
55

6+
# Run this from the root of the project
7+
68
rm -rf ./testing-project
79

8-
cookiecutter --config-file ./testing-config.yml --no-input -f ./
10+
cookiecutter --no-input -f ./ project_name="Testing Project"
911

1012
cd ./testing-project
1113

testing-config.yml

-2
This file was deleted.

0 commit comments

Comments
 (0)