DEV Community

Max Diamond
Max Diamond

Posted on

How to deploy an Adonis Application with ServerSinc

What is AdonisJS?

Adonisjs is a fully-featured Typescript framework that enables developers to build modern full stack applications. With a few basic commands, any developer can setup an Adonis app with Authentication, Database ORM, Routing, Queues and more.

Your first Adonis app

For this guide, we'll be using the basic adonis app available on our Github.

Pushing to GitHub

As ServerSinc relies on Github to deploy your code, you'll need to push the latest version of the adonis app to your own repo.

Initialize Git: Navigate to your project folder in the command line and run:

git init

Create a GitHub Repository: On GitHub, create a new repository and note the repository URL.

If you have the Github CLI tool installed, running gh repo create [name] --private will create a new private repo for you.

Add a Remote: Use this command, replacing with your GitHub repository URL:

git remote add origin <repository_url>

Push Your Code: Push your code to GitHub's "master" branch (or your branch) with:

git push -u origin master

Setting up our Adonis App

Log into your ServerSinc account and click Servers, then view the Server you want to deploy the app to. If you don't have one already, create or import a new one.

Next, go to Applications and click 'Create Application'.

Start by providing a Name for your app in the designated field. Optionally, you can also specify a Domain for your app.

Under Repository, choose your Adonis app's repository. A new dropdown menu will appear, prompting you to select the specific Branch you wish to use.

Additionally, you have the option to enable "Automatic Deploys," which will automatically deploy your app with each new commit made to the selected branch.

As our application is written in Typescript, we'll need to add Adonis' output folder, build, to the Build Directory,

In the "Index File" field, input the entry point file of your Adonis app. As we're building the app beforehand, this will be "build/server.js.".

Finally, enter the PORT value from your .env file and click 'Create Application'

This will not deploy your app straight away.

Configuring Deploy Script and Environment Variables

Once your app has been created, you'll see the application overview page.

Firstly, we'll delete the "<!-- Your Code Here -->" line from the deploy script and replace it with "npm run build", then save it.
The deploy script is run on your server each time your code is ready to deploy, here we can run build scripts, migrations and more.

Next, we'll navigate to the "Environment Variables" tab and add our variables from the .env file.

PORT=3333
HOST=0.0.0.0
NODE_ENV=production
APP_KEY=_kalGfjdLloaA7Kl0AWKqMhf2SksOp0Y
DRIVE_DISK=local
SESSION_DRIVER=cookie
CACHE_VIEWS=false
DB_CONNECTION=mysql
Enter fullscreen mode Exit fullscreen mode

Domain Settings

If you added a domain to your application during creation, you'll see the domain in the "Domain & SSL" tab. During the first deploy, ServerSinc will automatically configure NGINX to point the domain at your application.

Triggering a Deploy

Finally, click 'Deploy' and navigate to the "Activity" tab to see the latest deploy. Once the app has deployed, you'll see a green tick against the deploy.

To view the deploy logs, click the logs icon at the end of each completed deploy, this is handy way of knowing if everything went smoothly during deployment.

Voila!

Navigate to your servers IP , or Domain, to see your application live!

Top comments (0)