Deployment

Deployment

Deployment is an extremely important part of the process, but one that most developers dread because it falls outside the developer's core business and into that of devops.

Build your application

The principal aim of Mineral is to simplify the developer experience. That's why we've created a simple command to build your application and create an executable.

This executable is a single file that you can deploy anywhere, without having to worry about dependencies or other configuration.

Besides, this allows you to share only the executable with your customers and not all the source code.

Dart creates an executable for your operating system. If you build on Windows, you will receive a Windows executable which doesn't work on Linux.

Docker

Docker is a powerful cross-platform containerisation tool that is widely used in the professional world.

Before starting a deployment with Docker, please refer to the official documentation to ensure that your installation is correct.

Setup image

Now that your installation is done, we will create a Dockerfile at the root of our project with the following information.

In our instructions we use the official Docker image of the Dart language.

Dockerfile
FROM dart:stable AS build
WORKDIR /app
COPY . /app
WORKDIR /app
RUN dart pub get
RUN dart compile exe src/main.dart -o mineral
FROM scratch
COPY --from=build /runtime /
COPY --from=build /app/mineral /app/
COPY --from=build /app/pubspec.yaml /
CMD ["/app/mineral"]

Starting using Docker CLI

Now that the Docker image is configured, all we have to do is build it with the following command and then start it.

# Build the image
docker build -t <name>:latest .
# Starting our application
docker run -d --name <display name> <name>

Starting using Docker Compose

Docker Compose is a tool that allows you to manage multiple containers at the same time. It can be very useful if you want to deploy your application with a database for example.

To use it, you just have to create a docker-compose.yml file at the root of your project with the following information.

docker-compose.yaml
version: '3.8'
services:
bot:
container_name: bot
image: mineral
restart: always
environment:
- DART_ENV=production
- TOKEN=Nzg1ODgxOTk1NDc2ODYwOTc5.GW2skT._c5UijrPvZYNz-UU0_EfxTTPt2ZhCbFWxLk9N4
- HTTP_VERSION=10
- WSS_VERSION=10
- INTENT=3276799
- LOG_LEVEL=TRACE

If you have chosen Redis as your caching solution, please add the service to the docker-compose.yaml.

docker-compose.yaml
version: '3.8'
services:
bot:
container_name: bot
image: mineral
restart: always
depends_on:
- cache
environment:
- DART_ENV=production
- TOKEN=Nzg1ODgxOTk1NDc2ODYwOTc5.GW2skT._c5UijrPvZYNz-UU0_EfxTTPt2ZhCbFWxLk9N4
- HTTP_VERSION=10
- WSS_VERSION=10
- INTENT=3276799
- LOG_LEVEL=TRACE
cache:
container_name: cache
image: redis
restart: always
ports:
- '6380:6379'
environment:
- REDIS_PASSWORD=redis