Skip to content

PostgreSQL, Express, React, Node.js - Dockerized Application Boilerplate

License

Notifications You must be signed in to change notification settings

adefrutoscasado/pern-dockerized-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation


PERN Dockerized Stack


PostgreSQL Express React Nodejs Docker


Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Variants
  3. Getting Started
  4. Usage
  5. Roadmap
  6. Contributing
  7. Contact

About The Project

This project implements the main features to deploy a PERN stack application.

  • No create-react-app clones. A minimal webpack config is provided. No hacks to configure!
  • Development hot reload for both backend and frontend.
  • Node modules managed entirely by docker. Package version integrity across developers and environments. Including IDE access to node modules.
  • Docker versioning for easy deploys and rollbacks.
  • Endpoint and docker volume to upload files.
  • Database migrations (Optional).

Variants

Want even more boilerplate code? Try following variant:

Getting Started

Prerequisites

You must have following software installed in your System:

  • docker
  • docker-compose

Installation

  1. Clone the repo:

    git clone https://github.com/adefrutoscasado/pern-dockerized-stack.git
  2. Start the container:

    cd pern-dockerized-stack/docker
    docker-compose -f docker-compose-dev.yml up

    Or, to keep logs separate, start each service individually in different terminals:

    cd pern-dockerized-stack/docker
    docker-compose -f docker-compose-dev.yml up database
    docker-compose -f docker-compose-dev.yml up backend
    docker-compose -f docker-compose-dev.yml up frontend

    Frontend will be served at localhost:3010

Usage

Installing a package

    In order to share a similar environment across team, packages are managed inside the container. This is important, since different machines, node versions or packages can behave differently. Never execute npm install package by yourself, since it would be running under your local node installation. Instead, add the package to the package.json and then run:

    docker-compose -f docker-compose-dev.yml build backend
    # or
    docker-compose -f docker-compose-dev.yml build frontend

    After this, starting the containuer will dump the updated node modules to your local machine, so your IDE will be able to access it.


Erasing all data (uploads folder and database data)

    To reset all volumes completely use following command (data will be lost):

    docker-compose -f docker-compose-dev.yml down -v
    

Erasing uploads folder

    List all volumes using:

    docker volume ls

    Remove the specified volume using:

    docker volume rm docker_backend-uploads

Erasing database data

    List all volumes using:

    docker volume ls

    Remove the specified volume using:

    docker volume rm docker_database-data

Log management

    Logs can take up a lot of space on a server's hard drive, which can result in a lack of available space for other important files. By limiting the size of the logs, you can ensure that enough space is available for the necessary files. Following configuration at docker/docker-compose-prod.yml sets a maximum of 5 log files with a max size of 10 Mb each. So at most 50 Mb of logs for that container. Tune those numbers as you see fit.

    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"

Migrations

    Migrations are optional. If you prefer to manage dabatase changes manually, just ignore this part. Migrations are configured at backend/database/migrations and are managed by Knex. Two disabled files are included as example. To create a migration, just create a new file using <filename>.js. The order of execution of migrations is defined by the filename.


Installing docker `buildx` plugin to push images to different machine architectures

    Download buildx binaries for your development local machine: https://github.com/docker/buildx/releases

    Rename the binary to docker-buildx and move the binary file to ~/.docker/cli-plugins/docker-buildx. Give permissions to execute:

    chmod +x ~/.docker/cli-plugins/docker-buildx

    Install following needed packages:

    sudo apt install -y qemu-user-static binfmt-support

Pulling changes from original repository

    Once you cloned this repository, you can still pull changes from original repository using following steps:

    git remote add upstream [email protected]:adefrutoscasado/pern-dockerized-stack.git
    git pull upstream main

Roadmap

  • ☑ Backend
    • ☑ Hot reload at development
    • ☑ Package version integrity
    • ☑ Production docker compose
    • ☑ Database migrations
    • ☑ Create upload file endpoint
    • ☑ Log management
  • ☑ Frontend
    • ☑ Hot reload at development
    • ☑ Package version integrity
    • ☑ Production docker compose
  • ☐ Docker registry instructions (Docker versioning)
  • ☐ Usage instructions

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.md for more information.

Contact

Project Link: https://github.com/adefrutoscasado/pern-dockerized-stack

About

PostgreSQL, Express, React, Node.js - Dockerized Application Boilerplate

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published