2 years ago
Django backend core folder 'pizza' not found after deployment, frontend crashes. Previously 'startCommand' was not found until I fiddled with nixpacks.toml (unsure whether that's best practice). Backend Django API deploys fine and goes live, but there is a NetworkError blocking operations. Overall project works on local server. Using the recommended Caddyfile and nixpacks.toml in the frontend. Deployed recommended railway.json at root of project directory. Would love assistance, please.
Objective would be to get frontend and backend on the same domain.
My files are configured as recommended:-
├── frontend/
│ ├── package.json
│ └── ...
└── backend/
├── manage.py
└── ...
Error deploy logs - frontend
[2024-09-16 18:04:05 +0000] [1] [INFO] Starting gunicorn 21.2.0
[2024-09-16 18:04:05 +0000] [1] [INFO] Listening at: http://[::]:3000 (1)
[2024-09-16 18:04:05 +0000] [1] [INFO] Using worker: sync
[2024-09-16 18:04:05 +0000] [4] [INFO] Booting worker with pid: 4
[2024-09-16 18:04:05 +0000] [4] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/nix/store/xi98zcjhri5v76hdbnlmp7g1qglpvp8w-python3.10-gunicorn-21.2.0/lib/python3.10/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/nix/store/xi98zcjhri5v76hdbnlmp7g1qglpvp8w-python3.10-gunicorn-21.2.0/lib/python3.10/site-packages/gunicorn/util.py", line 371, in import_app
mod = importlib.import_module(module)
File "/nix/store/lx8vhp4fxclp494svlfis3sb2g8z4l9h-python3-3.10.12/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pizza'
[2024-09-16 18:04:05 +0000] [4] [INFO] Worker exiting (pid: 4)
[2024-09-16 18:04:05 +0000] [1] [ERROR] Worker (pid:4) exited with code 3
[2024-09-16 18:04:05 +0000] [1] [ERROR] Shutting down: Master
[2024-09-16 18:04:05 +0000] [1] [ERROR] Reason: Worker failed to boot.
Caddyfile
global options
{
admin off # theres no need for the admin api in railway's environment
persist_config off # storage isn't persistent anyway
auto_https off # railway handles https for us, this would cause issues if left enabled
# runtime logs
log {
format json # set runtime log format to json mode
}
# server options
servers {
trusted_proxies static private_ranges 100.0.0.0/8 # trust railway's proxy
}
}
site block, listens on the $PORT environment variable, automatically assigned by railway
:{$PORT:3000} {
# access logs
log {
format json # set access log format to json mode
}
# health check for railway
rewrite /health /*
# serve from the 'dist' folder (Vite builds into the 'dist' folder)
root * dist
# enable gzipping responses
encode gzip
# serve files from 'dist'
file_server
# if path doesn't exist, redirect it to 'index.html' for client side routing
try_files {path} /index.html}
nixpacks.toml
https://nixpacks.com/docs/configuration/file
set up some variables to minimize annoyance
[variables]
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
download caddy from nix
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
nixpkgsArchive = 'ba913eda2df8eb72147259189d55932012df6301' # Caddy v2.8.4 - https://github.com/NixOS/nixpkgs/commit/ba913eda2df8eb72147259189d55932012df6301
nixPkgs = ['caddy'] # install caddy as a nix package
Install Gunicorn (Python WSGI server)
[phases.python]
dependsOn = ['setup'] # ensure it runs after the setup phase
nixPkgs = ['python3Packages.gunicorn'] # install Gunicorn as a Nix package
format the Caddyfile with fmt
[phases.fmt]
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
cmds = ['caddy fmt --overwrite Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies
start the caddy web server
[start]
cmd = 'exec caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
> ⓘ Deployment information is only viewable by project members and Railway employees.
0 Replies