generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 9
CI CD Pipeline with Docker and Github Actions with Heroku
Anton Gluschuk edited this page Nov 28, 2020
·
1 revision
A CI/CD pipeline automates your software delivery process. The pipeline builds code, runs tests (CI), and safely deploys a new version of the application (CD).
Automated pipelines remove manual errors, provide standardized feedback loops to developers, and enable fast product iterations.
Tutorial based on typescript React application placed on github:
- Create account on Heroku
- On a dashboard click New -> Create new app -> write some meaningful name for your app and choose region (e.g. dokazovi-fe)
- Go to the Account Settings -> API Key -> Reveal -> copy API key
- Go to your repo on github and click Settings tab -> Secrets -> New repository secret -> write secret name HEROKU_API_KEY and paste copied key into value field.
- Create another secret called HEROKU_EMAIL and paste an email of your heroku account.
- Create a Dockerfile in the root directory of your project with next content:
CMD sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'
Important command for deploy because heroku set a dynamic port to your free dokazovi-fe app
- Create docker-compose.yml file in the root directory of your project:
ports: - '3000'
- here usually needs to set both ports e.g. 3000:3000 but again because of the dynamic port setting on heroku we have setup only one.
- Create ci-cd.yml config file and place in the root directory / workflow directory and fill it with the next content:
- This action will trigger when you make a push to the release branch, you may change this using different triggers from official docs event triggers
- line 28 run your Dockerfile created above to make a image of your project
- lines 33-35 use already prepared secrets - created in Prepare heroku part and our docker-compose.yml file to deploy on heroku
-
heroku_apps: '[{"imagename":"dokazovi_fe","appname":"dokazovi-fe","apptype":"web"}]'
- Important line where you have to set correct imagename written in line 28
- Correct appname written when you create an app on heroku dashboard in our case it is dokazovi-fe
- Set apptype to "web"