项目作者: miloserdow

项目描述 :
Github Actions for Capistrano
高级语言: JavaScript
项目地址: git://github.com/miloserdow/capistrano-deploy.git
创建时间: 2019-10-19T23:07:16Z
项目社区:https://github.com/miloserdow/capistrano-deploy

开源协议:MIT License

下载


Capistrano actions

Github deploy action for Capistrano. Use this action to automate your capistrano deployment process.

Dependencies

This action expects Ruby to be installed along with Capistrano, see below for a basic workflow example that uses ruby/setup-ruby.

Inputs

target

Environment where deploy is to be performed to. E.g. “production”, “staging”. Default value is empty.

deploy_key

Required Symmetric key to decrypt private
key. Must be a string.

enc_rsa_key_pth

Path to the encrypted key. Default "config/deploy_id_rsa_enc". You have to use either enc_rsa_key_pth or enc_rsa_key_val.

enc_rsa_key_val

Contents of the encrypted key. Best to use as repository secret. You have to use either enc_rsa_key_pth or enc_rsa_key_val.

working-directory

The directory from which to run the deploy commands, including bundle install.

Outputs

No outputs

Setting up CD using this action

  1. Generate SSH keys on the target machine
  1. $ ssh-keygen -t ed25519
  1. Export public key to the authorized_keys to allow the usage of this keypair to login
  1. $ cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
  1. Add public key from ~/.ssh/id_ed25519.pub to your repository’s deployment keys via Settings / Deploy keys / Add
  2. Encrypt your private key with a strong password. Please use these options, otherwise this action may not be able to decrypt your key.
  1. $ openssl enc -aes-256-cbc -md sha512 -salt -in ~/.ssh/id_ed25519 -out deploy_id_ed25519_enc -k "PASSWORD" -a -pbkdf2
  1. Add deploy_id_ed25519_enc file to your repository. Suggested path is config/deploy_id_ed25519_enc
  2. Save the password used in step 4 as a secret in repository settings via Settings / Secrets / Add
  3. Create YAML configuration for your workflow (example below)

Workflow example

  1. # This is a basic workflow to help you get started with Actions
  2. name: Deploy with Capistrano
  3. # Controls when the action will run.
  4. on:
  5. # Triggers the workflow on push or pull request events but only for the main branch
  6. push:
  7. branches: [main]
  8. # Allows you to run this workflow manually from the Actions tab
  9. workflow_dispatch:
  10. # A workflow run is made up of one or more jobs that can run sequentially or in parallel
  11. jobs:
  12. # This workflow contains a single job called "build"
  13. deploy:
  14. # The type of runner that the job will run on
  15. runs-on: ubuntu-latest
  16. # Steps represent a sequence of tasks that will be executed as part of the job
  17. steps:
  18. # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
  19. - uses: actions/checkout@v2
  20. - uses: ruby/setup-ruby@v1
  21. with:
  22. # ruby-version: 3.0.1 # Not needed with a .ruby-version file
  23. bundler-cache: true # runs 'bundle install' and caches installed gems automatically
  24. - uses: miloserdow/capistrano-deploy@v3 # you can use miloserdow/capistrano-deploy@master for the cuurent stable dev version
  25. with:
  26. target: development # Defines the environment that will be used for the deployment
  27. deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project
  28. enc_rsa_key_pth: config/deploy_id_ed25519_enc

Example running this action with custom commands

In this example we are starting rails and Sidekiq with Capistrano

Personal access token

You need to create a personal access token with “repo” access like described here:
@latest/github/authenticating-to-github/creating-a-personal-access-token"">https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token

Dispatch workflow

Create a new dispatch workflow like described here: @latest/rest/reference/actions#create-a-workflow-dispatch-event"">https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event

Workflow file:

  1. name: Start Rails and Sidekiq with Capistrano
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. environment:
  6. description: "The environment to deploy"
  7. required: true
  8. jobs:
  9. deploy:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - name: Checkout
  13. uses: actions/checkout@v2
  14. - name: Turnstyle
  15. uses: softprops/turnstyle@master
  16. env:
  17. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  18. with:
  19. abort-after-seconds: 3600
  20. - name: Set up Ruby
  21. uses: ruby/setup-ruby@v1
  22. with:
  23. ruby-version: 2.6.6
  24. bundler-cache: true
  25. - name: Deploy
  26. uses: kaspernj/capistrano-deploy@custom-capistrano-command
  27. with:
  28. capistrano_commands: '["puma:start", "sidekiq:start"]'
  29. target: ${{ github.event.inputs.environment }}
  30. deploy_key: ${{ secrets.DEPLOY_ENC_KEY }}
  31. enc_rsa_key_pth: config/deploy_id_ed25519_enc

Curl command

  1. curl \
  2. -X POST \
  3. -H "Accept: application/vnd.github.v3+json" \
  4. -H "Authorization: Bearer $PERSONAL_GITHUB_TOKEN" \
  5. https://api.github.com/repos/$GITHUB_USERNAME/$GITHUB_REPO_NAME/actions/workflows/$WORKFLOW_FILE_NAME/dispatches \
  6. -d "{\"ref\":\"master\",\"inputs\":{\"environment\":\"$ENVIRONMENT_TO_DEPLOY\"}}"

This command makes Github start Rails and Sidekiq at the deployment.