Automating Deployments of AdonisJS Project with DeployHQ
Prerequisites:
- A hosted server with Node.js and npm installed.
- An AdonisJS project
DeployHQ Setup
Create a Project:
Sign up and log in to DeployHQ. Go to Projects > New Project. Follow the wizard to connect your project repository.
Server Configuration:
Go to Servers > New Server.
Choose a name and select SSH as the protocol.
Enter your server's IP address and username (usually deployhq
).
Enable Use SSH key rather than password for authentication?.
On your server, run the following commands (replace deployhq
with your username if different):
sudo adduser deployhq
sudo usermod -a -G www-data deployhq
su - deployhq
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
Paste DeployHQ's public key into the nano
editor. Save (Ctrl+X
, Y
, then Enter
).
Set permissions:
bash
chmod 600 ~/.ssh/authorized_keys
Set the Deployment Path to your project's directory (e.g., /var/www/your-adonis-app
).
Enable Perform zero-downtime deployments on this server (optional).
Set the Environment to production
and enable Automatically deploy.
Save the server configuration.
Config Files (Optional):
Go to Config Files and add any sensitive files (e.g., .env
) that you don't want in your repository.
SSH Commands:
Go to SSH Commands and add new commands:
- Install Dependencies: cd %path% && npm ci
- Build Application: cd %path% && node ace build --production
- Start Application: cd %path%/build && npm run start:prod
(Or use PM2: cd %path%/build && pm2 start server.js
)
Additional AdonisJS-Specific Considerations:
- Ensure you have a production-ready
start:prod
script in yourpackage.json
:
{
"scripts": {
"start:prod": "node ace start --watch"
}
}
- If using PM2, install it globally on your server:
npm install -g pm2
Deployment
- Click Deploy Project in the header.
- Select your server and deployment options.
- Click Deploy to start the deployment process.
Congratulations! You've automated deployments for your AdonisJS project with DeployHQ.
Key Differences from Express:
- Uses
node ace build
for production build - Specific AdonisJS build and start commands
- Slightly different dependency and start process
Notes:
- Ensure your
.env.production
file is properly configured - Use AdonisJS's built-in environment management
- Consider using PM2 for process management in production
If you've got any other projects you'd like to automate deployments for, we've written lots of guides for deploying the most popular application frameworks and content management systems.