Skip to content

Commit 3012586

Browse files
authored
Merge pull request #262 from DefangLabs/kevin/railpack
Railpack doc
2 parents 55324ad + 3d101d3 commit 3012586

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

docs/concepts/railpack.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
title: Railpack
3+
description: Defang will use Railpack to make an OCI-Compliant container image for your project.
4+
sidebar_position: 500
5+
---
6+
7+
# Railpack
8+
9+
[Railpack](https://railpack.com/) is a tool for building container images from source code with minimal configuration. It is the successor to [Nixpacks](https://nixpacks.com/) and incorporates several lessons learned from running Nixpacks in production at [Railway](https://railway.com/) over the years.
10+
11+
In Defang deployments, one of the most common issues faced by users is a missing or invalid Dockerfile that can’t produce OCI-compliant images. This is especially common when Dockerfile are generated by LLMs or created by users with limited Docker experience. Since integrating Railpack into Defang, if no Dockerfile is provided, we now automatically build a working image for you using Railpack.
12+
13+
## How to trigger a Defang Railpack deployment
14+
15+
When you run a Defang Railpack deployment, you need 2 components:
16+
17+
1. A working application
18+
2. A valid Compose file
19+
20+
Your Compose file should not mention a Dockerfile.
21+
22+
For example,
23+
24+
```yaml
25+
services:
26+
app:
27+
restart: unless-stopped
28+
build:
29+
context: .
30+
deploy:
31+
resources:
32+
reservations:
33+
cpus: "1.0"
34+
memory: 512M
35+
ports:
36+
- mode: ingress
37+
target: 3000
38+
published: 3000
39+
```
40+
41+
## Troubleshooting and tips
42+
43+
If the deployment fails, here are some things you can try.
44+
45+
### Railpack Detection
46+
47+
To allow Railpack to generate a build plan for your project, please restructure or rename your existing project files to be Railpack-compatible, as described for each framework below.
48+
49+
#### [Node](https://railpack.com/languages/node/)
50+
51+
Your project will be detected as a Node.js application if a `package.json` file exists in the root directory.
52+
53+
Here is an example of:
54+
55+
- A Railpack-ready [React Vite project](https://github.com/DefangLabs/samples/tree/main/samples/react-vite-railpack)
56+
- A Railpack-ready [NextJS project](https://github.com/DefangLabs/samples/tree/main/samples/nextjs-railpack)
57+
58+
#### [Python](https://railpack.com/languages/python)
59+
60+
Your project will be detected as a Python application if any of these conditions are met:
61+
62+
- A main.py file exists in the root directory (If your main.py is named anything else)
63+
- A requirements.txt file exists
64+
- A pyproject.toml file exists
65+
- A Pipfile exists
66+
67+
Here is an example of:
68+
69+
- A Railpack-ready [Django project](https://github.com/DefangLabs/samples/tree/main/samples/django-railpack)
70+
- A Railpack-ready [Flask project](https://github.com/DefangLabs/samples/tree/main/samples/flask-railpack)
71+
72+
#### [Go](https://railpack.com/languages/golang)
73+
74+
Your project will be detected as a Go application if any of these conditions are met:
75+
76+
- A go.mod file exists in the root directory
77+
- A go.work file exists in the root directory (Go workspaces)
78+
- A main.go file exists in the root directory
79+
80+
Here is an example of:
81+
82+
- A Railpack-ready [Golang project](https://github.com/DefangLabs/samples/tree/main/samples/golang-http-form-railpack)
83+
84+
#### [PHP](https://railpack.com/languages/php)
85+
86+
Your project will be detected as a PHP application if any of these conditions are met:
87+
88+
- An index.php file exists in the root directory
89+
- A composer.json file exists in the root directory
90+
91+
#### [Java](https://railpack.com/languages/java)
92+
93+
Your project will be detected as a Java application if any of these conditions are met:
94+
95+
- A gradlew (Gradle wrapper) file exists in the root directory (to create this, if you don’t have one, run gradle wrapper)
96+
- A `pom.{xml,atom,clj,groovy,rb,scala,yaml,yml}` file exists in the root directory
97+
98+
#### [Ruby](https://railpack.com/languages/ruby)
99+
100+
Your project will be detected as a Ruby application if any of these conditions are met:
101+
102+
- A Gemfile file is present
103+
104+
#### [Rust](https://railpack.com/languages/rust)
105+
106+
Your project will be detected as a Rust application if any of these conditions are met:
107+
108+
- A Cargo.toml file is present
109+
110+
#### [Elixir](https://railpack.com/languages/elixir)
111+
112+
Your project will be detected as a Elixir application if any of these conditions are met:
113+
114+
- A mix.exs file exists in the root directory
115+
116+
#### [Static Sites](https://railpack.com/languages/staticfile)
117+
118+
Railpack can automatically build and setup a server for static sites that require no build steps. The [Caddy](https://caddyserver.com/) server is used as the underlying web server.
119+
120+
Your project will be automatically detected as a static site if any of these conditions are met:
121+
122+
- A Staticfile configuration file exists in the root directory
123+
- An index.html file exists in the root directory
124+
- A public directory exists
125+
- The `RAILPACK_STATIC_FILE_ROOT` environment variable is set
126+
127+
Static sites are served using the Caddy web server and you need to have the environment variable `PORT` exposed like this in the Compose file to map to the correct port:
128+
129+
```
130+
services:
131+
app:
132+
restart: "unless-stopped"
133+
build:
134+
context: ./app
135+
# This is the port you need to add
136+
environment:
137+
PORT: 5173 # <--- PORT
138+
ports:
139+
- target: 5173
140+
published: 5173
141+
mode: ingress
142+
deploy:
143+
resources:
144+
reservations:
145+
memory: 512M
146+
```

0 commit comments

Comments
 (0)