DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sunil More
Sunil More

Posted on

Deploy Docker based project using github in 5 min with simple CI/CD integration

To Setup new project using docker approach, run following command on Ubuntu

curl https://s3-us-west-2.amazonaws.com/opt-scripts/project-setup.sh -o project-setup.sh && bash project-setup.sh
Sample Github Repo: https://github.com/sunilmore690/expressjexample\

By running this script it’ll ask for below things

Gihub Project Name: expressjexample

Github Orgnization/User Name: sunilmore690

Git Branch: master

Github ACCESS TOKEN(Optional): For private github repo

NODE_ENV: staging/production

App port on which your server will run: 3000

Script perform the following operation

  • Install Docker & Docker-compose
  • Install Git
  • Clone the project
  • Setup post-merge hooks & which will execute deployment.sh if there changes when you pull the code
  • If NODE_ENV other than production, It’ll set up cron to execute git pull to get the latest code
  • If deployment.sh not exist in your root dir of your project, It’ll create deployment.sh with the following snippet
  • Setup NODE_ENV as env variable
  • Deploy the project by executing, deployment.sh

If you’ve not added deployment.sh in root dir of your project then the script will create deployment.sh in your dir with the following snippet

docker build -t <Github Project Name>.

docker stop <Github Project Name>-container

docker rm <Github Project Name>-container

docker runβ€Šβ€”β€Šrestart always -dβ€Šβ€”β€Šname <Github Project Name>-containerβ€Šβ€”β€Šenv NODE_ENV=<NODE_ENV> -p 80:<PORT> <Github Project Name>:latest

Test a simple CI/CD integration

If you’ve provided NODE_ENV other than production then you can push your code to provided GitHub branch and It’ll run deployment.sh within 5 min

For NODE_ENV >> production, you’ve to manually pull the code and by pulling the code it’ll trigger deployment.sh

The deployment log file (deployment.log) will be available in project home dir.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.