Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit b68da82

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 9b5fb4f + 0b1d19e commit b68da82

17 files changed

+1123
-49
lines changed

docs/deployment-guides/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"label": "Deployment Guides",
33
"position": 3,
44
"collapsible": false,
5-
"collapsed": false,
5+
"collapsed": false
66
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"label": "Exhaustive Documentation",
3+
"position": 4,
4+
"collapsible": false,
5+
"collapsed": false
6+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Crons
6+
7+
You can specify crons in your `disco.json` file:
8+
```json
9+
{
10+
"version": "1.0",
11+
"services": {
12+
"web": {
13+
"port": 8080,
14+
"command": "./bin/serve.sh"
15+
},
16+
"mycron": {
17+
"type": "cron",
18+
"schedule": "0 * * * *",
19+
"command": "./bin/crons/hour.sh"
20+
}
21+
}
22+
}
23+
```
24+
25+
## Useful Examples
26+
27+
Here are a few useful examples of `crontab` notation to get you started:
28+
```json
29+
{
30+
"version": "1.0",
31+
"services": {
32+
"web": {
33+
"port": 8080,
34+
"command": "./bin/serve.sh"
35+
},
36+
"minutecron": {
37+
"type": "cron",
38+
"schedule": "* * * * *",
39+
"command": "./bin/cron/oneminute.sh"
40+
},
41+
"hourcron": {
42+
"type": "cron",
43+
"schedule": "0 * * * *",
44+
"command": "./bin/cron/onehour.sh"
45+
},
46+
"daycron": {
47+
"type": "cron",
48+
"schedule": "0 0 * * *",
49+
"command": "./bin/cron/oneday.sh"
50+
}
51+
}
52+
}
53+
```
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Environment Variables
6+
7+
To set environment variables for you project, you can use the CLI commands:
8+
9+
```bash
10+
disco env:set --project my-project VAR_NAME=value
11+
```
12+
13+
You can set many of them at once:
14+
```bash
15+
disco env:set --project my-project VAR_NAME=value OTHER_VAR="other value"
16+
```
17+
18+
To retrieve a specific value:
19+
```bash
20+
disco env:get --project my-project VAR_NAME
21+
```
22+
23+
Or to retrieve all key/values:
24+
```bash
25+
disco env:list --project my-project
26+
```
27+
28+
## Using Environment Variables in your App
29+
30+
Your code can use environment variables like anywhere else.
31+
32+
E.g. in Bash
33+
```bash
34+
echo "Hello $VAR_NAME"
35+
```
36+
in Python
37+
```python
38+
import os
39+
print(f"Hello {os.getenv('VAR_NAME')")
40+
```
41+
or in JavaScript with NodeJS
42+
```javascript
43+
console.log(`Hello ${process.env.VAR_NAME}`)
44+
```
45+
46+
## Using Environment Variables When Building Images
47+
48+
When building Docker images, we need to be careful to avoid including the variables in the images. Disco uses the recommended way to expose environment variables without baking them into the images.
49+
50+
See Docker documentation about [Build Secrets](https://docs.docker.com/build/building/secrets/) for more info.
51+
52+
### Dot Env (.env)
53+
54+
You can either access all of the variables as a `.env` file, where each line is `VAR_NAME=value`
55+
56+
```Dockerfile
57+
RUN --mount=type=secret,id=.env your-command
58+
```
59+
60+
Docker will make the file available as `/run/secrets/.env` for that one command. If the base image you're using supports it, you could use the `.env` file as follows
61+
```Dockerfile
62+
RUN --mount=type=secret,id=.env env $(cat /run/secrets/.env | xargs) your-command
63+
```
64+
65+
That way, `your-command` will have the environment loaded just before it runs.
66+
67+
Make sure to not set the environment variable with `export`, because it would set it in the environment of the image and it would mean your secrets have leaked.
68+
69+
### Individual Variable
70+
71+
If you only want access to a single variable, you can do this
72+
73+
```Dockerfile
74+
RUN --mount=type=secret,id=VAR_NAME your-command
75+
```
76+
77+
and `/run/secrets/VAR_NAME` will contain the value of the variable.
78+
79+
You could add many variables using this method:
80+
```Dockerfile
81+
RUN --mount=type=secret,id=VAR_NAME --mount=type=secret,id=OTHER_VAR your-command
82+
```
83+
84+
### Specifying the File Path and File Name to Use
85+
86+
If you need to use a specific path for the files that Docker makes available, instead of e.g. `/run/secrets/.env`, you can specify it with `target`.
87+
88+
The [Docker documentation](https://docs.docker.com/build/building/secrets/#target) contains this example
89+
```Dockerfile
90+
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
91+
aws s3 cp ...
92+
```
93+
We can adapt it to Disco's environment variables like
94+
```bash
95+
disco env:set --projecct my-project AWS_CREDENTIALS='...'
96+
```
97+
```Dockerfile
98+
RUN --mount=type=secret,id=AWS_CREDENTIALS,target=/root/.aws/credentials \
99+
aws s3 cp ...
100+
```
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Images
6+
7+
Each service uses a Docker image.
8+
9+
## Specifying a Dockerfile
10+
11+
You can define many images in `disco.json` and refer to them in your services.
12+
13+
```json
14+
{
15+
"version": "1.0",
16+
"services": {
17+
"web": {
18+
"port": 8080,
19+
"command": "./bin/serve.sh",
20+
"image": "webimage"
21+
}
22+
},
23+
"images": {
24+
"webimage": {
25+
"dockerfile": "Dockerfile",
26+
"context": "."
27+
}
28+
}
29+
}
30+
```
31+
32+
## Default Image
33+
34+
You can avoid talking about images in your `disco.json` file by relying on the default of using the `Dockerfile` and build context at the root of the repository.
35+
36+
```json
37+
{
38+
"version": "1.0",
39+
"services": {
40+
"web": {
41+
"port": 8080,
42+
"command": "./bin/serve.sh"
43+
}
44+
}
45+
}
46+
```
47+
48+
This `disco.json` above uses the defaults. More on this below.
49+
50+
When you don't specify the image to use for a service, Disco will default to the image named `default`.
51+
52+
Those two `disco.json` are equivalent, defining `"image"` or not in the definition of `"web"`:
53+
54+
```json
55+
{
56+
"version": "1.0",
57+
"services": {
58+
"web": {
59+
"port": 8080,
60+
"command": "./bin/serve.sh"
61+
}
62+
},
63+
"images": {
64+
"default": {
65+
"dockerfile": "Dockerfile",
66+
"context": "."
67+
}
68+
}
69+
}
70+
```
71+
and
72+
```json
73+
{
74+
"version": "1.0",
75+
"services": {
76+
"web": {
77+
"port": 8080,
78+
"command": "./bin/serve.sh",
79+
"image": "default"
80+
}
81+
},
82+
"images": {
83+
"default": {
84+
"dockerfile": "Dockerfile",
85+
"context": "."
86+
}
87+
}
88+
}
89+
```
90+
91+
Also, when not defining the `default` image, Disco will assume the default value shown above. That is, the `Dockerfile` at the root of the repository, the build context as well. Meaning that this third `disco.json` is also equivalent:
92+
```json
93+
{
94+
"version": "1.0",
95+
"services": {
96+
"web": {
97+
"port": 8080,
98+
"command": "./bin/serve.sh"
99+
}
100+
}
101+
}
102+
```
103+
104+
In other words, if the `Dockerfile` you want to use is at the root of the repository, and the build context is also the root of the repository, you can just avoid thinking about images in your `disco.json`.
105+
106+
## Many images, many services
107+
108+
Each service can use a different Docker image.
109+
110+
```json
111+
{
112+
"version": "1.0",
113+
"services": {
114+
"web": {
115+
"port": 8080,
116+
"command": "./bin/serve.sh",
117+
"image": "webimage"
118+
},
119+
"worker": {
120+
"command": "./bin/worker.sh",
121+
"image": "workerimage"
122+
}
123+
},
124+
"images": {
125+
"webimage": {
126+
"dockerfile": "Dockerfile",
127+
"context": "."
128+
},
129+
"workerimage": {
130+
"dockerfile": "Dockerfile.worker",
131+
"context": "."
132+
}
133+
}
134+
}
135+
```
136+
137+
## Using Dockerfiles in Sub-Directories
138+
139+
You can pass the path to your Dockerfile, and also the path for the [local context](https://docs.docker.com/build/building/context/#local-context).
140+
141+
For example:
142+
```json
143+
{
144+
"version": "1.0",
145+
"services": {
146+
"web": {
147+
"port": 8080,
148+
"command": "./bin/serve.sh",
149+
"image": "webimage"
150+
}
151+
},
152+
"images": {
153+
"webimage": {
154+
"dockerfile": "webapp/Dockerfile",
155+
"context": "webapp/."
156+
}
157+
}
158+
}
159+
```
160+
or another exmaple, if the Dockerfile is in a sub-directory, but should be built using the root as the context:
161+
```json
162+
{
163+
"version": "1.0",
164+
"services": {
165+
"web": {
166+
"port": 8080,
167+
"command": "./bin/serve.sh",
168+
"image": "webimage"
169+
}
170+
},
171+
"images": {
172+
"webimage": {
173+
"dockerfile": "webapp/Dockerfile",
174+
"context": "."
175+
}
176+
}
177+
}
178+
```
179+
180+
## Using Publicly Downloadable Images
181+
182+
If the name of the image to use is not defined in `images`, Disco will see if it can download it.
183+
184+
```json
185+
{
186+
"version": "1.0",
187+
"services": {
188+
"worker": {
189+
"command": "python -c $'import time\nwhile True:\n time.sleep(1)'",
190+
"image": "python:3.12.3"
191+
}
192+
}
193+
}
194+
```
195+
196+
In this case, it would use the [official Python image](https://hub.docker.com/_/python) from Docker Hub.
197+
198+
It's the equivalent of running
199+
```bash
200+
docker pull python:3.12.3
201+
docker run python:3.12.3 python -c $'import time\nwhile True:\n time.sleep(1)'
202+
```

0 commit comments

Comments
 (0)