R
Railway•14mo ago
drdrigg

How to deploy Angular on Railway?

How can I deploy my Angular 14 app on railway. Do I need to do anything? Like create a dockerfile (if yes, any template I can use)? Project ID: 988851b6-78d5-44de-a73d-3e5b6468c8bf
43 Replies
Percy
Percy•14mo ago
Project ID: 988851b6-78d5-44de-a73d-3e5b6468c8bf
Brody
Brody•14mo ago
https://github.com/brody192/angular-template - copy the nixpacks.toml and Caddyfile from that repo into yours - make sure your outputPath is set to dist in your angular.json
drdrigg
drdriggOP•14mo ago
Ok, will try, keep the dockerfile? Correct? "outputPath": "dist/theapp-app", I added nixpacks.toml and Caddyfile (and kept dockerfile) and the deploy went without errors but I get 503 when trying to access the url to the app Deploy fails if I remove the dockerfile
Brody
Brody•14mo ago
I didn't know you had a dockerfile, delete the dockerfile as previously mentioned, your outputPath should be dist
drdrigg
drdriggOP•14mo ago
Ok changing to this and now redeploying "outputPath": "dist", Nope deploy failed anyway
Brody
Brody•14mo ago
you have dependency conflicts, please fix that
drdrigg
drdriggOP•14mo ago
ok will try Works fine on Vercel but will try to fix
Brody
Brody•14mo ago
vercel is probably ignoring them
drdrigg
drdriggOP•14mo ago
True I do like this on Vercel? Can I do the same here on Railway? npm install --legacy-peer-deps
Brody
Brody•14mo ago
you can but you really should fix the deps issues if you really don't want to, then yes I'll modify your nixpacks.toml file to run that install command instead
drdrigg
drdriggOP•14mo ago
Absolutely, but I am just trying it out to see if I can run my entire stack on Railway
drdrigg
drdriggOP•14mo ago
Tried this in the settings but it did not work
No description
drdrigg
drdriggOP•14mo ago
How can I add it to the nixpacks?
Brody
Brody•14mo ago
that's where the build command goes you don't want to fix the deps issues?
drdrigg
drdriggOP•14mo ago
I will fix them, but I am just checking all works on Railway first. Then I can go deeper
Brody
Brody•14mo ago
okay then when I'm back at my computer I will send you a new nixpacks.toml file, in the mean time make sure you clear any build or start commands you may have set yourself anywhere
drdrigg
drdriggOP•14mo ago
Yes, no rush! Its 2.30 am here in Sweden so I am going to bed anyway. BTW, fantastic releases this week. Super well done!
Brody
Brody•14mo ago
haha i dont work for railway, i didnt release anything
# 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
CADDY_VERSION = '2.7.4' # specify the caddy version to use here, without a 'v' prefix. https://github.com/caddyserver/caddy/releases

[phases.install]
cmds = ['npm install --legacy-peer-deps']

# download and untar caddy
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"', # download the caddy release specified by 'CADDY_VERSION' from GitHub
'tar -zxvf caddy.tar.gz caddy', # only extract 'caddy' from the tarball
'chmod +x caddy' # enable file execution for caddy, needed to execute downloaded files
]

# 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

# copy caddy and build artifacts to a new image and start the caddy web server
[start]
runImage = 'ubuntu:20.04' # use a new ubuntu image to run the caddy server in
onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist'] # copy only the needed files and folders into the new image (Angular is configured to build to a 'dist' folder)
cmd = './caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
# 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
CADDY_VERSION = '2.7.4' # specify the caddy version to use here, without a 'v' prefix. https://github.com/caddyserver/caddy/releases

[phases.install]
cmds = ['npm install --legacy-peer-deps']

# download and untar caddy
[phases.caddy]
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
cmds = [
'curl -fsSLo caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/v${CADDY_VERSION}/caddy_${CADDY_VERSION}_linux_amd64.tar.gz"', # download the caddy release specified by 'CADDY_VERSION' from GitHub
'tar -zxvf caddy.tar.gz caddy', # only extract 'caddy' from the tarball
'chmod +x caddy' # enable file execution for caddy, needed to execute downloaded files
]

# 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

# copy caddy and build artifacts to a new image and start the caddy web server
[start]
runImage = 'ubuntu:20.04' # use a new ubuntu image to run the caddy server in
onlyIncludeFiles = ['caddy', 'Caddyfile', 'dist'] # copy only the needed files and folders into the new image (Angular is configured to build to a 'dist' folder)
cmd = './caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter
drdrigg
drdriggOP•14mo ago
Ah ok haha, I thought this was the Railway support, sorry for bombarding you with these requests Brody!
Brody
Brody•14mo ago
thats what im here for though
drdrigg
drdriggOP•14mo ago
Ah ok Since you are always here and always awake I guess your are AI or really dedicated 🙂 Will try the nixfile, thx!
Brody
Brody•14mo ago
both
drdrigg
drdriggOP•14mo ago
haha
Brody
Brody•14mo ago
well how did it go?
drdrigg
drdriggOP•14mo ago
Well it worked at the end but the overall connection to Rails is so slow so it will not work for this project. Also this project are using white label custom domains for each user and the Railway way of handling domains are a bit of a hassle. It uses some type of cnames that not even Dnsimple.com supports.
Brody
Brody•14mo ago
pretty sure dnsimple does support cnames, at the root level @macwilko sorry for the ping, but you use dnsimple with railway without issues right, and do you have cnames at the root level?
macwilko
macwilko•14mo ago
hey! I do use DNSimple, without issues! Let me check the setup it won't verify the domain, at least on railway
macwilko
macwilko•14mo ago
No description
macwilko
macwilko•14mo ago
but it does work I use ALIAS
Brody
Brody•14mo ago
how often does that alias update again?
macwilko
macwilko•14mo ago
i mean its been like that for months... I don't think it ever updates lol
macwilko
macwilko•14mo ago
No description
macwilko
macwilko•14mo ago
and I'de totally be using Cloudflare if they weren't blocking my traffic to the apps lol even after turning everything off, it was still throwing challenges to users, and the app isn't a web app
Brody
Brody•14mo ago
even with the proxy off?
macwilko
macwilko•14mo ago
i'm gonna setup the mTLS thingy down the road, but it's a challenge for another time no i never turned it off... but its kind of one of these things i need to test alot, otherwise traffic to the site is blocked and nobody can use the app lol i'm reluctant to play around with it too much
Brody
Brody•14mo ago
use fastly
macwilko
macwilko•14mo ago
yeah gonna look into both Cloudflare / Fastly kinda expecting around February for stuff like this to be necisary gonna try this!
macwilko
macwilko•14mo ago
No description
Brody
Brody•14mo ago
interesting
celebrations
celebrations•14mo ago
@macwilko those screenshots look rlly nice, what are you using to take them?
macwilko
macwilko•14mo ago
Xnapper
Want results from more Discord servers?
Add your server