Skip to content

Commit 2a20c4b

Browse files
authored
📝 Update README.md and deployment.md (#678)
1 parent 36f1082 commit 2a20c4b

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ Make sure you at least change the value for `SECRET_KEY` in the main `.env` file
8686

8787
### Generate secret keys
8888

89-
You will be asked to provide passwords and **secret keys** for several components.
89+
Some environment variables in the `.env` file have a default value of `changethis`.
9090

91-
They have a default value of `changethis`. You can also update them later in the `.env` files after generating the project.
92-
93-
You could generate those secrets with:
91+
You have to change them with a secret key, to generate secret keys you can run the following command:
9492

9593
```bash
9694
python -c "import secrets; print(secrets.token_urlsafe(32))"
9795
```
9896

99-
Copy the contents and use that as password / secret key. And run that again to generate another secure key.
97+
Copy the content and use that as password / secret key. And run that again to generate another secure key.
10098

10199
## How to use it - alternative with Copier
102100

deployment.md

+51-16
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ But you have to configure a couple things first. 🤓
1212

1313
* Have a remote server ready and available.
1414
* Configure the DNS records of your domain to point to the IP of the server you just created.
15-
* Install and configure [Docker](https://docs.docker.com/engine/install/).
16-
* Create a remote directory to store your code, for example:
17-
18-
```bash
19-
mkdir -p /root/code/traefik-public/
20-
```
15+
* Install and configure [Docker](https://docs.docker.com/engine/install/) on the remote server (Docker Engine, not Docker Desktop).
2116

2217
## Public Traefik
2318

@@ -27,7 +22,13 @@ You need to do these next steps only once.
2722

2823
### Traefik Docker Compose
2924

30-
Copy the Traefik Docker Compose file to your server, to your code directory. You could do it with `rsync`:
25+
* Create a remote directory to store your Traefik Docker Compose file:
26+
27+
```bash
28+
mkdir -p /root/code/traefik-public/
29+
```
30+
31+
Copy the Traefik Docker Compose file to your server. You could do it by running the command `rsync` in your local terminal:
3132

3233
```bash
3334
rsync -a docker-compose.traefik.yml root@your-server.example.com:/root/code/traefik-public/
@@ -39,15 +40,15 @@ This Traefik will expect a Docker "public network" named `traefik-public` to com
3940

4041
This way, there will be a single public Traefik proxy that handles the communication (HTTP and HTTPS) with the outside world, and then behind that, you could have one or more stacks with different domains, even if they are on the same single server.
4142

42-
To create a Docker "public network" named `traefik-public` run:
43+
To create a Docker "public network" named `traefik-public` run the following command in your remote server:
4344

4445
```bash
4546
docker network create traefik-public
4647
```
4748

4849
### Traefik Environment Variables
4950

50-
The Traefik Docker Compose file expects some environment variables to be set.
51+
The Traefik Docker Compose file expects some environment variables to be set in your terminal before starting it. You can do it by running the following commands in your remote server.
5152

5253
* Create the username for HTTP Basic Auth, e.g.:
5354

@@ -67,6 +68,12 @@ export PASSWORD=changethis
6768
export HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD)
6869
```
6970

71+
To verify that the hashed password is correct, you can print it:
72+
73+
```bash
74+
echo $HASHED_PASSWORD
75+
```
76+
7077
* Create an environment variable with the domain name for your server, e.g.:
7178

7279
```bash
@@ -83,7 +90,13 @@ export EMAIL=admin@example.com
8390

8491
### Start the Traefik Docker Compose
8592

86-
Now with the environment variables set and the `docker-compose.traefik.yml` in place, you can start the Traefik Docker Compose:
93+
Go to the directory where you copied the Traefik Docker Compose file in your remote server:
94+
95+
```bash
96+
cd /root/code/traefik-public/
97+
```
98+
99+
Now with the environment variables set and the `docker-compose.traefik.yml` in place, you can start the Traefik Docker Compose running the following command:
87100

88101
```bash
89102
docker compose -f docker-compose.traefik.yml up -d
@@ -93,6 +106,8 @@ docker compose -f docker-compose.traefik.yml up -d
93106

94107
Now that you have Traefik in place you can deploy your FastAPI project with Docker Compose.
95108

109+
**Note**: You might want to jump ahead to the section about Continuous Deployment with GitHub Actions.
110+
96111
## Environment Variables
97112

98113
You need to set some environment variables first.
@@ -111,8 +126,6 @@ export DOMAIN=fastapi-project.example.com
111126

112127
You can set several variables, like:
113128

114-
* `ENVIRONMENT`: The current deployment environment, like `staging` or `production`.
115-
* `DOMAIN`: The current deployment domain, for example `fastapi-project.example.com`.
116129
* `BACKEND_CORS_ORIGINS`: A list of allowed CORS origins separated by commas.
117130
* `SECRET_KEY`: The secret key for the FastAPI project, used to sign tokens.
118131
* `FIRST_SUPERUSER`: The email of the first superuser, this superuser will be the one that can create new users.
@@ -131,6 +144,18 @@ You can set several variables, like:
131144
* `SENTRY_DSN`: The DSN for Sentry, if you are using it.
132145
* `FLOWER_BASIC_AUTH`: The HTTP Basic Auth for Flower.
133146

147+
### Generate secret keys
148+
149+
Some environment variables in the `.env` file have a default value of `changethis`.
150+
151+
You have to change them with a secret key, to generate secret keys you can run the following command:
152+
153+
```bash
154+
python -c "import secrets; print(secrets.token_urlsafe(32))"
155+
```
156+
157+
Copy the content and use that as password / secret key. And run that again to generate another secure key.
158+
134159
### Deploy with Docker Compose
135160

136161
With the environment variables in place, you can deploy with Docker Compose:
@@ -177,7 +202,7 @@ cd
177202

178203
* [Install a GitHub Action self-hosted runner following the official guide](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners#adding-a-self-hosted-runner-to-a-repository).
179204

180-
* When asked about labels, add a label for the environment, e.g. `production`.
205+
* When asked about labels, add a label for the environment, e.g. `production`. You can also add labels later.
181206

182207
After installing, the guide would tell you to run a command to start the runner. Nevertheless, it would stop once you terminate that process or if your local connection to your server is lost.
183208

@@ -195,7 +220,7 @@ After you do it, you would be on the `root` user again. And you will be on the p
195220
cd /home/github/actions-runner
196221
```
197222

198-
* From there, [install the GitHub Actions runner service following the official guide](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service#installing-the-service):
223+
* Install the self-hosted runner as a service with the user `github`:
199224

200225
```bash
201226
./svc.sh install github
@@ -207,9 +232,19 @@ cd /home/github/actions-runner
207232
./svc.sh start
208233
```
209234

235+
* Check the status of the service:
236+
237+
```bash
238+
./svc.sh status
239+
```
240+
241+
You can read more about it in the official guide: [Configuring the self-hosted runner application as a service](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service).
242+
210243
### Set Secrets
211244

212-
On your repository, configure secrets for the environment variables you need, the same ones described above, including `DOMAIN`, `SECRET_KEY`, etc. Follow the [official GitHub guide for setting repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
245+
On your repository, configure secrets for the environment variables you need, the same ones described above, including `SECRET_KEY`, etc. Follow the [official GitHub guide for setting repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
246+
247+
The current Github Actions workflows expect two secrets: `DOMAIN_STAGING` and `DOMAIN_PRODUCTION`.
213248

214249
## GitHub Action Deployment Workflows
215250

@@ -218,7 +253,7 @@ There are GitHub Action workflows in the `.github/workflows` directory already c
218253
* `staging`: after pushing (or merging) to the branch `master`.
219254
* `production`: after publishing a release.
220255

221-
If you need to add extra environments you could use those as starting point.
256+
If you need to add extra environments you could use those as a starting point.
222257

223258
## URLs
224259

0 commit comments

Comments
 (0)