DEV Community

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 -o && bash
Sample Github Repo:\

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 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 not exist in your root dir of your project, It’ll create with the following snippet
  • Setup NODE_ENV as env variable
  • Deploy the project by executing,

If you’ve not added in root dir of your project then the script will create 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 within 5 min

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

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

Top comments (0)