This article was created on the assumption that you have read the following. Let CircleCI perform a deployment to Heroku after a commit to the master branch on Github (https://qiita.com/NaokiIshimura/items/a897fba536caa4dd3338)
In this article, I will explain how to configure a CI/CD pipeline with Heroku using CircleCI for myself. Basically, I referred to the official document, so I recommend you to read this as well.
Deploy Configuration (://circleci.com/docs/ja/2.0/deployment-integrations/#heroku)
Ruby 2.6.5 Rails 6.0.0 Bundler 2.1.4 MySQL 5.6.50
It is assumed that you have set up the Heroku app, so if you haven't done so already, refer to here and manually ploy to Heroku before doing so.
Add the Heroku application name and Heroku API key as environment variables to automatically probe with CircleCI. (Environment variable settings in CircleCI are here)
Hereafter, the application name will be treated as
HEROKU_APP_NAME and the Heroku API key will be treated as
Below is the code.
deploy: docker: - image: buildpack-deps:trusty executor: heroku/default steps: - checkout # push/Checking merged code - run: name:Deploy master to Heroku command: | git push https://heroku:[email protected]/$HEROKU_APP_NAME.git master
By writing this code, it will check the code and perform automatic deployment.
workflows: version: 2.1 build-deploy: jobs: - build - deploy: requires: - build filters: branches: only: master
The official documentation allows customization, but as a beginner I haven't reached that area, so I used the workflow that was prepared with the goal of building a pipeline.
version: 2.1 orbs: ruby: circleci/[email protected] heroku: circleci/[email protected] jobs: build: docker: - image: circleci/ruby:2.6.5-stretch-node executor: ruby/default steps: - checkout - run: gem install bundler -v 2.1.4 - run: name: Which bundler? command: bundle -v - ruby/bundle-install deploy: docker: - image: buildpack-deps:trusty executor: heroku/default steps: - checkout - run: name:Deploy master to Heroku command: | git push https://heroku:[email protected]/$HEROKU_APP_NAME.git master workflows: version: 2.1 build-deploy: jobs: - build - deploy: requires: - build filters: branches: only: master
Now you have a CI/CD pipeline with Heroku.
You can see
This way of writing is just a beginner's edition, so I have not described the execution of the test by RSpec, but I would like you to keep in mind that you can also describe it.