You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: deployment.md
+51-16
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,7 @@ But you have to configure a couple things first. 🤓
12
12
13
13
* Have a remote server ready and available.
14
14
* 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).
21
16
22
17
## Public Traefik
23
18
@@ -27,7 +22,13 @@ You need to do these next steps only once.
27
22
28
23
### Traefik Docker Compose
29
24
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:
31
32
32
33
```bash
33
34
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
39
40
40
41
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.
41
42
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:
43
44
44
45
```bash
45
46
docker network create traefik-public
46
47
```
47
48
48
49
### Traefik Environment Variables
49
50
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.
To verify that the hashed password is correct, you can print it:
72
+
73
+
```bash
74
+
echo$HASHED_PASSWORD
75
+
```
76
+
70
77
* Create an environment variable with the domain name for your server, e.g.:
71
78
72
79
```bash
@@ -83,7 +90,13 @@ export EMAIL=admin@example.com
83
90
84
91
### Start the Traefik Docker Compose
85
92
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:
87
100
88
101
```bash
89
102
docker compose -f docker-compose.traefik.yml up -d
@@ -93,6 +106,8 @@ docker compose -f docker-compose.traefik.yml up -d
93
106
94
107
Now that you have Traefik in place you can deploy your FastAPI project with Docker Compose.
95
108
109
+
**Note**: You might want to jump ahead to the section about Continuous Deployment with GitHub Actions.
Copy the content and use that as password / secret key. And run that again to generate another secure key.
158
+
134
159
### Deploy with Docker Compose
135
160
136
161
With the environment variables in place, you can deploy with Docker Compose:
@@ -177,7 +202,7 @@ cd
177
202
178
203
*[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).
179
204
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.
181
206
182
207
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.
183
208
@@ -195,7 +220,7 @@ After you do it, you would be on the `root` user again. And you will be on the p
195
220
cd /home/github/actions-runner
196
221
```
197
222
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`:
199
224
200
225
```bash
201
226
./svc.sh install github
@@ -207,9 +232,19 @@ cd /home/github/actions-runner
207
232
./svc.sh start
208
233
```
209
234
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
+
210
243
### Set Secrets
211
244
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`.
213
248
214
249
## GitHub Action Deployment Workflows
215
250
@@ -218,7 +253,7 @@ There are GitHub Action workflows in the `.github/workflows` directory already c
218
253
*`staging`: after pushing (or merging) to the branch `master`.
219
254
*`production`: after publishing a release.
220
255
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.
0 commit comments