Table of Contents
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).
Want even more boilerplate code? Try following variant:
You must have following software installed in your System:
docker
docker-compose
-
Clone the repo:
git clone https://github.com/adefrutoscasado/pern-dockerized-stack.git
-
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
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
- ☑ 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).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
Project Link: https://github.com/adefrutoscasado/pern-dockerized-stack