⛵Generate a ready-to-use local docker environment for your Adonis application

Overview

Adonis Sail

Generate a ready-to-use local docker environment for your Adonis application

Installation

npm i --save-dev adonis-sail
node ace configure adonis-sail

Available services

  • PostgreSQL
  • MySQL
  • Redis
  • MinIO
  • MailHog

Usage

Make sure to install needed Adonis Package, and follow instructions before running Sail's commands. @adonisjs/redis, @adonisjs/lucid, @adonisjs/drive-*, @adonisjs/mail.

Now you can set your environment variables. Many of these will also be used in the generated docker-compose (look inside once created to know which ones). Especially the *_PORT or *_PASSWORD.

Once this is done you can run the command node ace sail:install and select the services you want. A docker-compose.yml file will be created at the root of your project, you now just have to launch it by doing docker-compose up -d.

You can launch again the node ace sail:install command at any time to add new services.

MinIO

If you plan to use Amazon S3 to store files while running your application in its production environment, you may wish to install the MinIO service when installing Sail. MinIO provides an S3 compatible API that you may use to develop locally using Adonis's s3 storage driver without creating "test" storage buckets in your production S3 environment. If you choose to install MinIO while installing Sail, a MinIO configuration section will be added to your application's docker-compose.yml file.

You will need to install the official Adonis drive-s3 package to use MinIO locally. So install the package by following the documentation correctly, then in your .env file, use these variables :

S3_KEY=sail
S3_SECRET=password
S3_BUCKET=local
S3_REGION=us-east-1
S3_ENDPOINT=http://localhost:9000

And add this to config/drive.ts :

...
  s3: {
      forcePathStyle: true, // 👈 Don't forget this !
      key: Env.get('S3_KEY'),
      secret: Env.get('S3_SECRET'),
      region: Env.get('S3_REGION'),
      bucket: Env.get('S3_BUCKET'),
      endpoint: Env.get('S3_ENDPOINT'),
  }
...

You can now use the @adonisjs/drive-s3 package to store and fetch files like you would do normally on a real AWS bucket. You can also access MinIO dashboard at : http://localhost:8900/dashboard

Databases

To connect to your application's databases from your local machine, you may use a graphical database management application such as TablePlus. By default, exposed ports are :

  • MySQL: 3306
  • PostgreSQL: 5432
  • Redis: 6379

MailHog

MailHog intercepts emails sent by your application during local development and provides a convenient web interface so that you can preview your email messages in your browser. To use MailHog install install the official Adonis Mailer package. Follow the installation instructions, and select SMTP when prompted. You have to set theses variables in your .env file :

SMTP_HOST=localhost
SMTP_PORT=1025
SMTP_USERNAME=
SMTP_PASSWORD=

In config/mail.ts, remove the auth part in the smtp configuration object.

...
  smtp: {
    driver: 'smtp',
    host: Env.get('SMTP_HOST'),
    port: Env.get('SMTP_PORT'),
  },
...

You can now access the MailHog dashboard at http://localhost:8025/ to preview emails.

Known issues

MySQL 8

If you are using MySQL 8 (the default image), and you encounter the following error:

ER_NOT_SUPPORTED_AUTH_MODE: 
  Client does not support authentication protocol requested by server; consider upgrading MySQL client 

You need to install mysql2 :

npm install mysql2

And now configure Adonis to use it, in config/database.ts :

...
mysql: {
  client: 'mysql2' // 👈 Set this to 'mysql2'
  connection: {
    user: Env.get('MYSQL_USER'),
    password: Env.get('MYSQL_PASSWORD'),
    database: Env.get('MYSQL_DB_NAME'),
  },
...

Details

Currently, the Adonis application is not dockerised. I rarely encountered problems on my applications depending on the version of Node.JS I use (it happens, but with a tool like nvm it's usually fixed pretty quickly). And it's obviously easier to handle your Adonis application when it's running outside a docker container. That's why I decided not to dockerise the Adonis app.

If you think it's really necessary to dockerise the Adonis application in local development, let me know and we'll see what we can do !

Comments
  • Cannot find module '../src/services'

    Cannot find module '../src/services'

    After installing this package, and running node ace configure adonis-sail, I get this errror thrown:

    Cannot find module '../src/services'
    Require stack:
    - /home/travis/projects/<project>/node_modules/.pnpm/[email protected]/node_modules/adonis-sail/build/commands/InstallSail.js
    

    Which makes sense - in /node_modules/adonis-sail/build/commands/InstallSail.js, there is a line that requires the file const services_1 = require("../src/services");, but this file is not included in the NPM package:

    image image

    bug 
    opened by thetre97 3
  •  ER_NOT_SUPPORTED_AUTH_MODE: Mysql 8.0

    ER_NOT_SUPPORTED_AUTH_MODE: Mysql 8.0

    When MySQL 8 is used this error is encountered:

    ER_NOT_SUPPORTED_AUTH_MODE: 
      Client does not support authentication protocol requested by server; consider upgrading MySQL client 
    

    Workaround

    Replace mysql image in docker-compose.yml :

      mysql:
        image: 'mysql/mysql-server:8.0'
        container_name: mysql
    

    with this :

      mysql:
        image: 'mysql/mysql-server:5.7'
        container_name: mysql
    

    See : https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server

    bug 
    opened by Julien-R44 3
  • aide docker

    aide docker

    Bonjour, je suis vraiment désoler d'écrire ici , je ne sait pas du tous comment vous contactez, sans vous déranger.

    Donc je vous contact car j'aime adonis mais là j'ai les yeux qui pleure ^^ j'essaie tant bien que mal de dockerizer mon projet adonis, je suis la doc partie dockerization tous ce passe bien mon docker compose s'execute etc ... mais quand j'ouvre le navigateur là aussi la partie serveur du site fonctionne mais le webpack encore fait défaut et n'arrive pas à rendre les fichiers. (j'ai bien suivis la partie de la doc qui modifie le docker-compose pour webpack encore) donc de ce coté là je suis sur que tout est ok.

    j'ai tester beaucoup de chose sans réponse positive. j'ai trouver un contournement et mais cela me fait perdre mes cheveux => dans public/entrypoints.json je modifie à la main le host, je passe 0.0.0.0 à localhost et sa fonctionne bien sur si j'arrête le contenu faut que je recommence, donc c'est clairement pas une bonne solution (même de contournement ^^) j'ai donc par la suite essayer de modifier mon host au lieu de 0.0.0.0 => localhost cela ne règle pas le soucis je dois le faire manuellement pour que sa fonctionne (c'est là que je pleure), je vous demande de l'aide car j'aimerais dockerizer pour la prod. (donc je test)

    si vous avez une solution je suis preneur, je vous dérange, passer mon message à la poubelle je ne veux vraiment pas vous faire perdre votre temps, encore une fois désoler d'écrire ici, j'ai demandé sur discord mais je n'ai pas réussis à trouvé une solution merci de m'avoir lu à bientôt j'espère Capture d’écran 2022-06-07 145417 Capture d’écran 2022-06-07 145632

    invalid 
    opened by j314h 1
  • I got this error after running docker compose up -d

    I got this error after running docker compose up -d

    I got this error after running docker-compose up -d

    docker-compose up -d Traceback (most recent call last): File "urllib3/connectionpool.py", line 670, in urlopen File "urllib3/connectionpool.py", line 392, in _make_request File "http/client.py", line 1255, in request File "http/client.py", line 1301, in _send_request File "http/client.py", line 1250, in endheaders File "http/client.py", line 1010, in _send_output File "http/client.py", line 950, in send File "docker/transport/unixconn.py", line 43, in connect FileNotFoundError: [Errno 2] No such file or directory

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "requests/adapters.py", line 439, in send File "urllib3/connectionpool.py", line 726, in urlopen File "urllib3/util/retry.py", line 410, in increment File "urllib3/packages/six.py", line 734, in reraise File "urllib3/connectionpool.py", line 670, in urlopen File "urllib3/connectionpool.py", line 392, in _make_request File "http/client.py", line 1255, in request File "http/client.py", line 1301, in _send_request File "http/client.py", line 1250, in endheaders File "http/client.py", line 1010, in _send_output File "http/client.py", line 950, in send File "docker/transport/unixconn.py", line 43, in connect urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "docker/api/client.py", line 214, in _retrieve_server_version File "docker/api/daemon.py", line 181, in version File "docker/utils/decorators.py", line 46, in inner File "docker/api/client.py", line 237, in _get File "requests/sessions.py", line 543, in get File "requests/sessions.py", line 530, in request File "requests/sessions.py", line 643, in send File "requests/adapters.py", line 498, in send requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "docker-compose", line 3, in File "compose/cli/main.py", line 81, in main File "compose/cli/main.py", line 200, in perform_command File "compose/cli/command.py", line 60, in project_from_options File "compose/cli/command.py", line 152, in get_project File "compose/cli/docker_client.py", line 41, in get_client File "compose/cli/docker_client.py", line 170, in docker_client File "docker/api/client.py", line 197, in init File "docker/api/client.py", line 221, in _retrieve_server_version docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')) [4825] Failed to execute script docker-compose

    invalid 
    opened by Thatogafane 1
  • [feature] mailhog remove 'auth' from config/mail automatically via env variable during testing

    [feature] mailhog remove 'auth' from config/mail automatically via env variable during testing

    Hi, First of all thanks for this piece of tech. I found myself in some trouble between the local development and our CI/CD pipeline. Problem was that i couldn't really reliably remove or add a piece of code to run on the CI/CD. So Tried to find a possible solution to remove the auth property from the smtp object with env variables.

    After some searching and fiddling around i think i found a viable way, Maybe something you want to implement here in the docs or if possible in the install command itself. It looks something like this:

    smtp: {
          driver: 'smtp',
          host: Env.get('SMTP_HOST'),
          port: Env.get('SMTP_PORT'),
          ...(!Env.get('MAILER_TESTING', true) && {
            auth: {
              user: Env.get('SMTP_USERNAME'),
              pass: Env.get('SMTP_PASSWORD'),
              type: 'login',
            },
          }),
        },
    

    or via the NODE_ENV variable?

    smtp: {
          driver: 'smtp',
          host: Env.get('SMTP_HOST'),
          port: Env.get('SMTP_PORT'),
          ...(Env.get('NODE_ENV') !== 'development' && {
            auth: {
              user: Env.get('SMTP_USERNAME'),
              pass: Env.get('SMTP_PASSWORD'),
              type: 'login',
            },
          }),
        },
    

    POC can be found here: https://jsfiddle.net/0k16jos7/

    opened by MiniKraken-Team 1
Releases(v0.0.7)
Owner
Julien Ripouteau
Julien Ripouteau
local docker-compose environment to deploy and configure backoffice

backoffice-local local docker-compose environment to deploy and configure backoffice How to install To install the repo dependencies yarn install be s

micro-lc 2 Dec 15, 2022
Atlan is a CLI that helps you to manage local dockerized infrastructure without any needed knowledge on Docker and Docker Compose.

Atlan CLI Atlan is a CLI that helps you to manage local dockerized infrastructure without any needed knowledge on Docker and Docker Compose. What is A

Myastro 10 Aug 17, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate application for learning out how to build, run and deploy a multi-container environment (docker-compose).

foodtrucks-app-docker-compose The app's backend is written in Python (Flask) and for search it uses Elasticsearch. I used this app as candidate applic

Selçuk Şan 3 Oct 24, 2022
mirrord lets you easily mirror traffic from your production environment to your development environment.

mirrord lets you easily mirror traffic from your Kubernetes cluster to your development environment. It comes as both Visual Studio Code extension and a CLI tool.

MetalBear 2.1k Dec 24, 2022
A high-resolution local database that uses precise algorithms to easily record data in local files within a project with persistent JSON and YAML support designed to be easy to set up and use

About A high-resolution local database that uses precise algorithms to easily record data in local files within a project with persistent JSON and YML

Shuruhatik 5 Dec 28, 2022
A secure MERN Stack boilerplate ready for Production that uses Docker & Nginx.

A production ready & secure boilerplate for the MERN Stack that uses Docker & Nginx. Focus on the product and not the setup. You can directly start wo

Karan Jagtiani 34 Dec 23, 2022
A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose

Turborepo + Strapi + Next.js + Docker A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose. ⚠️ Prerequisit

Elvin Chu 60 Dec 29, 2022
Docker Extension to backup and restore docker volumes.

vackup-docker-extension This repository contains a Docker Extension that backups Docker volumes. This extension is purely a demonstration of how it'd

Felipe Cruz Martinez 34 Dec 28, 2022
This provides an extension integration with Docker Desktop to run k9s quickly and easily through the Docker Desktop interface.

k9s extension for Docker Desktop This provides an extension integration with Docker Desktop to allow k9s quickly and easily through the Docker Desktop

James Spurin 14 Dec 16, 2022
An example T3 app containerized with Docker, Docker Compose, and deployed on Railway

Create T3 App This is an app bootstrapped according to the init.tips stack, also known as the T3-Stack. What's next? How do I make an app with this? W

Anthony Campolo 15 Dec 19, 2022
Follow along with blog posts, code samples, and practical exercises to learn how to build serverless applications from your local Integrated development environment (IDE).

Getting started with serverless This getting started series is written by the serverless developer advocate team @AWSCloud. It has been designed for d

AWS Samples 55 Dec 28, 2022
For this workshop, we're going to learn more about cloud computing by exploring how to use Pulumi to build, configure, and deploy a real-life, modern application using Docker

For this workshop, we're going to learn more about cloud computing by exploring how to use Pulumi to build, configure, and deploy a real-life, modern application using Docker. We will create a frontend, a backend, and a database to deploy the Pulumipus Boba Tea Shop. Along the way, we'll learn more about how Pulumi works.

Kat Cosgrove 9 Dec 29, 2022
📸 A command-line tool to generate code images of your local code right away from the terminal

?? rayli ?? A command-line tool to generate code images of your local code right away from the terminal Usage Commands Usage $ npm install -g rayli $

buidler's hub 45 Nov 4, 2022
⚡ A multipurpose meme marketplace and editor for creating, downloading and sharing memes with a ready to use API powered by Hasura GraphQL

Rocketmeme A multipurpose meme marketplace and editor for creating and downloading memes. View meme collection, browse different meme categories, like

Victor Eke 31 Nov 18, 2022
Ready-to-use Remix + Tailwind CSS routes and components.

remix-blocks What is RemixBlocks? Ready-to-use Remix + Tailwind CSS routes, and UI components, all blocks: Are full-stack routes. Are independent of e

Alexandro Martínez 111 Jan 5, 2023
There can be more than Notion and Miro. Affine is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

AFFiNE.PRO The Next-Gen Knowledge Base to Replace Notion & Miro. Planning, Sorting and Creating all Together. Open-source, Privacy-First, and Free to

Toeverything 12.1k Jan 9, 2023