1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

令和最新版CircleCIでSSH踏み台でSSHする

Last updated at Posted at 2022-06-19

version: 2.1
jobs:
  job-deploy:
    docker:
      - image: cimg/base:stable
    steps:
      - add_ssh_keys:
          fingerprints:
          - ${RELAY_FINGERPRINT}
      - run:
          command: "ssh -o StrictHostKeyChecking=no ${RELAY_USER}@${RELAY_HOST} -p ${RELAY_SSH_PORT} \
          \"ssh ${REMOTE_HOST} \
          'cd ~/Git/TempKeeper && git pull && sudo systemctl restart TempKeeper.service'\""
          no_output_timeout: 10m
workflows:
  version: 2
  job-deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only: main

リモートで実行される任意のコマンドをシングルクォーテーションで囲う

'git -C /var/myrepo pull && sudo systemctl restart MyRepo.service'

環境変数

変数名 内容
RELAY_FINGERPRINT 踏み台サーバのフィンガープリント※1
RELAY_USER 踏み台サーバのユーザ
RELAY_HOST 踏み台サーバのホスト
RELAY_SSH_PORT 踏み台サーバのポート
REMOTE_HOST デプロイ対象のホスト

※1 Project Setting -> SSH Keys -> Additional SSH Keys -> Add SSH Key より秘密鍵を登録した際に生成されるフィンガープリントを Environment Variables (環境変数)へ追加する

スクリーンショット 2022-06-20 7.32.26.png

参照元ドキュメント

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?