Skip to main content

Deployment

These are just some of the ways in which one can deploy an ambiorix application.

caution

Remember to open the open the port used by the application on your server. Also remember to define a port in the app or it will serve on a dynamic port unknown at run time.

Belgic

There is now a load balancer for ambiorix applications so one can serve concurrent users with ease. The load balancer is documented here.

Service

The application can be deployed as a service on any Linux server. Create a new .service in the /etc/systemd/system/ directory.

note

The name of the file defines the name of the service.

vim /etc/systemd/system/ambiorix.service

In that .service file place the following, it creates a service that runs the application at the defined path (path/to/app).

[Unit]
Description=Ambiorix application

[Service]
ExecStart=cd path/to/app && /usr/bin/Rscript --no-save --slave -f app.R
Restart=on-abnormal
Type=simple

[Install]
WantedBy=multi-user.target

One the service is added restart the daemon, you might have to run it as sudo.

systemctl daemon-reload

You can then start and enable the service, again, you might have to run it as sudo.

systemctl start ambiorix
systemctl enable ambiorix

Once the app has started, check its status to make sure that everything runs well.

systemctl status ambiorix

Docker

The easiest way to deploy an ambiorix app is using docker.

Existing Image

This project comes with an image you can pull and use.

docker pull jcoenep/ambiorix

By default the image will use an internal very basic application and binds it to port 3000.

docker run -p 3000:3000 jcoenep/ambiorix

To use your own application mount your app in the images /app directory, so from the root of the app this would look like this:

docker run -v "$(pwd)"/.:/app -p 3000:3000 jcoenep/ambiorix

Generate

Or you can generate your own dockerfile.

create_dockerfile(port = 3000L)

The function create_dockerfile will parse the DESCRIPTION file to create a Dockerfile, below is an example of the output.

FROM jcoenep/ambiorix
RUN echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
RUN R -e "remotes::install_github('JohnCoene/echarts4r')"
COPY . .
EXPOSE 3000
RUN R -e "options(ambiorix.host='0.0.0.0', 'ambiorix.port'=3000);source('app.R')"

You can then build the image.

docker build -t ambiorix .

Finally, run it.

docker run ambiorix

With docker installed this will work just as well on your machine as on a remote server.