Giter Site home page Giter Site logo

loopback-mysql-docker-boilerplate's Introduction

Loopback & MySQL Docker Boilerplate

About

Description:

A Base docker project to get up and running with Loopback and MySQL. This project also includes boot scripts located in server/boot to automatically do database migration/update so that you can move a bit quicker with your schema, tables, and data structures. Apart from the migration scripts this project is a fresh sheet of ice, in that, there are no models, widgets, relations, or permissions set up.

Tech Specifications:

Node: 6.11.1 -> Latest LTS: Boron StrongLoop: 3.x MySQL: 5.6 -> Amazon Aurora DB drop-in at 1/10th of the cost!

Install/Set Up

Prerequisites:

You need to have both docker and docker-compose installed.

Notes:

Number one, I've created a make file to make life a bit easier. Number two, if you wish to do a complete fresh install, as in, remove all the current loopback scaffolding you can do so via:

   # deletes all loopback scaffolding
   make NUKE
   # loopback-cli scaffolding
   make setup-loopback

1) Install Dependencies:

First task of business is to install the npm dependencies:

   npm install
   # or use the make script
   make install-deps

2) Start docker-compose

Last task of business is to boot up the docker containers:

   make start # runs -> docker-compose up

3) Open Browser

To make sure everything worked according to plan open open localhost:3002. It should display a simple JSON Object with a "started" and "uptime" property. To view the api cruz on over to localhost:3002/explorer/.

Create Model

To create a new loopback model:

   make model a=Widget

IMPORTANT: After you create a new model you will have to perform a db migration which you can read about bellow.

Database Migration

For the most part db migration is automated through the boot scripts but you'll have to update the script accordingly. Let's say we create a new model, then we will have to edit the /server/boot/migration.custom.js file and add the new model to the MODELS Array in String format. However, if you add a alter/add the properties on a model the migration script will automaticaly sync up the new schema.

You can also do a db migration via /__scripts__/migrate.js and like the automated scripts you will have to add your custom models to the MODELS Array. You can then run this script via: make migrate.

Loopback Make Commands

There are a few Makefile commands to make life a bit easier. Nothing magical just a wrapper around docker-compose run api lb. You must pass an argument to the api and model command.

api

   make api a=middleware
   make api a='Model Widget'

model

   make model a=Widget

Relation -> (no arguments)

   make relation

Debug Node

To spawn a node inspect debugger within the container you must un-comment the debug port and debug command in the docker-compose.yml file like so:

api:
  ports:
    - 3002:3000
    # Debug port
    - 9229:9229
  # command: nodemon . -> comment out default command
  command: nodemon -L --inspect .

MySQL Environment

The MySQL docker image is setup via environment variables to set up the the db. These variables are set in the root .env file. Remember, these variables must correspond with /server/datasources.json.


Best, te

loopback-mysql-docker-boilerplate's People

Contributors

artisin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.