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: docs/concepts/configuration.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,3 +89,12 @@ Here are the different ways sensitive config values are stored depending on the
89
89
:::info
90
90
Please note that while Defang supports setting sensitive config, it does not support the [`secrets`](https://docs.docker.com/reference/compose-file/secrets/) top-level element as seen in the Compose specification. Please see our [Compose](/docs/concepts/compose) page for more details.
description: Defang enables you to run one-off jobs during your deployment workflow.
4
+
sidebar_position: 280
5
+
---
6
+
7
+
# One-off Jobs
8
+
Defang enables you to run one-off jobs during your deployment workflow. One-off jobs are commands that run at specific points in the deployment process, such as after your database is ready but before your application starts.
9
+
10
+
One-off jobs are run a single time, and failure to run a one-off job will cause the entire deployment to fail.
11
+
12
+
:::info
13
+
Currently, AWS and GCP are supported for one-off jobs. Support for Digital Ocean is coming soon.
14
+
:::
15
+
16
+
## When should one-off jobs be used?
17
+
One-off jobs are useful for running commands that need to be executed before your application starts. Common use cases include:
18
+
19
+
- Database migrations
20
+
- Warming or cleaning caches
21
+
- Running build scripts
22
+
23
+
## How to configure one-off jobs
24
+
25
+
One-off jobs can be configured in your `compose.yaml` file as services with a [Restart Policy](https://docs.docker.com/reference/compose-file/services/#restart) set to `"no"`.
26
+
27
+
In the example below, we define a one-off job called `release` that runs a script called `release.sh`. This job will run once during the deployment process. It will be run concurrently with the `web` service.
28
+
29
+
<tablewidth="100%">
30
+
<thead>
31
+
<tr>
32
+
<th><code>compose.yaml</code></th>
33
+
<th>Workflow</th>
34
+
</tr>
35
+
</thead>
36
+
<tbody>
37
+
<tr>
38
+
<tdvalign="top">
39
+
40
+
```yaml
41
+
services:
42
+
app:
43
+
build: .
44
+
ports:
45
+
- "80:80"
46
+
47
+
release:
48
+
build: .
49
+
command: ["./release.sh"]
50
+
restart: "no"
51
+
```
52
+
53
+
</td>
54
+
<td valign="top">
55
+
56
+
```mermaid
57
+
flowchart LR
58
+
subgraph workspace["Deployment Workflow"]
59
+
deployment_start
60
+
app
61
+
release
62
+
deployment_complete
63
+
64
+
deployment_start --> app
65
+
deployment_start --> release
66
+
app --> deployment_complete
67
+
release --> deployment_complete
68
+
end
69
+
```
70
+
71
+
</td>
72
+
</tr>
73
+
</tbody>
74
+
</table>
75
+
76
+
### How to specify job dependencies
77
+
78
+
You can specify when the job should run by using [`depends_on`](https://docs.docker.com/reference/compose-file/services/#depends_on) to define dependencies on other services. For example, when running database migrations, you would typically want to ensure that the database service is ready before executing the migration job.
79
+
80
+
Here is an example configuration for a one-off job that runs database migrations after the database service is ready:
81
+
82
+
<tablewidth="100%">
83
+
<thead>
84
+
<tr>
85
+
<th><code>compose.yaml</code></th>
86
+
<th>Workflow</th>
87
+
</tr>
88
+
</thead>
89
+
<tbody>
90
+
<tr>
91
+
<tdvalign="top">
92
+
93
+
```yaml
94
+
services:
95
+
db:
96
+
image: postgres:latest
97
+
98
+
migrate:
99
+
build: .
100
+
command: ["./migrate.sh"]
101
+
depends_on:
102
+
- db
103
+
restart: "no"
104
+
105
+
web:
106
+
build: .
107
+
ports:
108
+
- "80:80"
109
+
depends_on:
110
+
- migrate
111
+
```
112
+
113
+
</td>
114
+
<td valign="top">
115
+
116
+
```mermaid
117
+
flowchart LR
118
+
subgraph workspace["Deployment Workflow"]
119
+
deployment_start
120
+
db
121
+
web
122
+
migrate
123
+
deployment_complete
124
+
125
+
deployment_start --> db
126
+
db --> migrate
127
+
migrate --> web
128
+
web --> deployment_complete
129
+
end
130
+
```
131
+
132
+
</td>
133
+
</tr>
134
+
</tbody>
135
+
</table>
136
+
137
+
## How do one-off jobs work under the hood?
138
+
139
+
One off jobs are deployed as temporary containers on the same infrastructure as your main services. They are deployed as separate containers to ensure that they do not interfere with the main application services, so resources can be configured independently. They will share the same network and security groups as your other services, allowing them to communicate with your application and database services as needed.
@@ -167,7 +167,7 @@ Now all you need to do is deploy your application to the cloud.
167
167
168
168
### Deploying to AWS
169
169
170
-
If you're deploying to AWS, you'll need to invoke `defang compose up` with your AWS access credentials in the environment:
170
+
If you're deploying to AWS, you'll need to invoke `defang compose up --provider aws` with your AWS access credentials in the environment:
171
171
172
172
<details>
173
173
<summary>
@@ -285,7 +285,86 @@ See our full tutorial on [deploying to AWS](/docs/tutorials/deploy-to-aws).
285
285
286
286
### Deploying to GCP
287
287
288
-
GCP support for deployments without Dockerfiles coming soon.
288
+
If you're deploying to GCP, you'll need to invoke `defang compose up --provider gcp` with your GCP access credentials in the environment:
289
+
290
+
<details>
291
+
<summary>
292
+
Run the following command
293
+
```
294
+
GCP_PROJECT_ID=my-project-123456 defang compose up --provider gcp
295
+
```
296
+
</summary>
297
+
```
298
+
* Using Google Cloud Platform provider from command line flag
299
+
! Defang cannot monitor status of the following managed service(s): [postgres release].
300
+
To check if the managed service is up, check the status of the service which depends on it.
301
+
! service "postgres": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
302
+
! service "web": ingress port without healthcheck defaults to GET / HTTP/1.1
303
+
* Packaging the project files for web at /Users/defang/wk/vast-badlands
304
+
* Uploading the project files for web
305
+
* Setting up defang CD in GCP project my-project-123456, this could take a few minutes
306
+
* Packaging the project files for release at /Users/defang/wk/vast-badlands
307
+
* Uploading the project files for release
308
+
* Tailing logs for deployment ID fgdh4ct0hopz ; press Ctrl+C to detach:
309
+
* Showing only build logs and runtime errors. Press V to toggle verbose mode.
310
+
2025-09-08T10:28:08.634-04:00 cd ** Update started for stack beta
311
+
2025-09-08T10:28:17.990-04:00 cd ** Updating service "postgres"
312
+
2025-09-08T10:28:44.773-04:00 cd ** Building image for "release"...
313
+
2025-09-08T10:28:58.012-04:00 cd ** Building image for "web"...
314
+
2025-09-08T10:47:02.479-04:00 release I, [2025-09-08T14:47:02.409371 #1] INFO -- : Migrating to CreateMembers (20240416182733)
2025-09-08T10:48:16.157-04:00 web => Rails 7.1.3.2 application starting in production
337
+
2025-09-08T10:48:16.157-04:00 web => Run `bin/rails server --help` for more startup options
338
+
2025-09-08T10:48:18.625-04:00 web [1] Puma starting in cluster mode...
339
+
2025-09-08T10:48:18.625-04:00 web [1] * Puma version: 6.4.2 (ruby 3.3.4-p94) ("The Eagle of Durango")
340
+
2025-09-08T10:48:18.625-04:00 web [1] * Min threads: 5
341
+
2025-09-08T10:48:18.625-04:00 web [1] * Max threads: 5
342
+
2025-09-08T10:48:18.625-04:00 web [1] * Environment: production
343
+
2025-09-08T10:48:18.626-04:00 web [1] * Master PID: 1
344
+
2025-09-08T10:48:18.626-04:00 web [1] * Workers: 2
345
+
2025-09-08T10:48:18.626-04:00 web [1] * Restarts: (✔) hot (✔) phased
346
+
2025-09-08T10:48:18.626-04:00 web [1] * Listening on http://0.0.0.0:5000
347
+
2025-09-08T10:48:18.627-04:00 web [1] Use Ctrl-C to stop
348
+
```
349
+
</details>
350
+
351
+
### Deploying to DigitalOcean
352
+
353
+
If you're deploying to GCP, you'll need to invoke `defang compose up --provider digitalocean` with your DigitalOcean access credentials in the environment:
354
+
355
+
:::warning
356
+
Some Heroku applications may require some manual adjustments to be deployed to DigitalOcean with Defang.
357
+
Dockerfiles are required for deployments to DigitalOcean, so you may need to create one if your application does not already have one. Support for automatic Dockerfile generation is coming soon with [Railpack](/docs/concepts/railpack.md).
358
+
Defang also does not yet support [one-off jobs](/docs/concepts/one_off_jobs) on DigitalOcean, so you will need to modify your services to run these tasks during initialization.
0 commit comments