Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2017 10:25
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
capistrano deployment using CircleCI 2.0
version: 2
- image: ruby:2.3.3-alpine
working_directory: /home/circleci/
- setup_remote_docker:
reusable: true
- run:
name: Install System Dependencies
# See also
command: apk add --update --no-cache git openssh-client tar gzip build-base tzdata
- run:
name: Set timezone to Asia/Tokyo
command: cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
- checkout
- restore_cache:
name: Restore bundler cache
- gems-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "Gemfile.lock" }}
- gems-{{ .Environment.COMMON_CACHE_KEY }}-
- run:
name: Install Ruby Dependencies
command: bundle check || bundle install --jobs=4 --retry=3
- save_cache:
name: Save bundler cache
key: gems-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "Gemfile.lock" }}
- /usr/local/bundle
- add_ssh_keys:
# for ssh to
# See
- "43:7f:b2:..."
- deploy:
name: Maybe Deploy
command: |
if [ "${CIRCLE_BRANCH}" != "master" ]; then
exit 0
if [ -z "${BUNDLE_UPDATE}" ]; then
gem install -N bundler circleci-bundle-update-pr
circleci-bundle-update-pr CircleCI
#!/bin/sh -eu
cat <<EOF >> $HOME/.ssh/config
User masutaka
ForwardAgent yes
# Add the preferred key for getting GitHub Permission
# See
eval $(ssh-agent)
bundle exec cap prod deploy
Copy link

masutaka commented Apr 16, 2017

The target repository is which is a private one.

Copy link

autobolt commented Nov 2, 2017

Thanks for sharing the circleci config! It has been very useful!

Copy link

When I try to adapt this setup to my own project, CircleCI asks for my deploy user's password when it gets to the cap production deploy step. But that doesn't happen when I run that command manually. I'm assuming I have the wrong SSH keys set up in the wrong place? Do you have any insight into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment