Deploy Astro to Coolify
1. Update Package.json to use node 20
Section titled “1. Update Package.json to use node 20”For both (SSR and SSG), add this to Package.json, after ‘dependencies’ section, if not already set:
{ "dependencies": { ... } "engines": { "node": ">=20.3.0" }}2. Create Coolify project
Section titled “2. Create Coolify project”- Go to https://apps.darideveloper.com/projects
- Create new project (if required) with project name, example: “project-name”
- Open the project
- Open “production” environment
3. Create app in coolify
Section titled “3. Create app in coolify”Inside the project:
- Click in ”+ Add New Resource”
- Select “Public Repository”
- Paste github repository url
- Click in “Check Repository”
- In Build Pack select “Nixpacks”
- Click in “Save”
4. App setup
Section titled “4. App setup”- Go to “General” tab
- Change name to repository name, example: “project-name”
- Update subdomain to repository name, example: “https://project-name.apps.darideveloper.com”
- Press “Enter” at last field to save changes
4. Update general commands in coolify
Section titled “4. Update general commands in coolify”Setup the follosing commands in each section:
# Install Commandnpm i
# Build Commandnpm run build5. Setup environment variables in coolify
Section titled “5. Setup environment variables in coolify”Go to “Environment Variables” tab inside the coolify app:
- Click in “Developer view”
- Setup all env variables from env file (copy and paste)
- Click in “Save All Environment Variables”
- Add the following env variable if not already set in your env files
NIXPACKS_NIXPKGS=nodejs_20,npm-9_x6. Advanced settings in coolify
Section titled “6. Advanced settings in coolify”- Go to “Advanced” tab
- Set “Custom Container Name” to project name, example: “project-name”
- Press “Enter” at last field to save changes
7. SSR
Section titled “7. SSR”Follow this steps for server side rendering deployment only.
7.1. Install @astrojs/node
Section titled “7.1. Install @astrojs/node”Install the folllowing package in the project
Install @astrojs/node package to use Node.js in Astro.
Be sure to setup as “standalone” mode
7.2. Validate build mode
Section titled “7.2. Validate build mode”Build project and run it in local to validate it’s working
npm run buildnode dist/server/entry.mjs7.3. Update General settings in coolify
Section titled “7.3. Update General settings in coolify”- Setup the follosing start command in coolify “General” tab
# Start Commandnode ./dist/server/entry.mjs- Set “Ports Exposes” to “3000”
- Press “Enter” at last field to save changes
8. SSG
Section titled “8. SSG”Follow this steps for static site generation deployment only.
TODO
10. Enable auto deploy
Section titled “10. Enable auto deploy”Follow this steps to enable auto deploy with coolify webhooks: