Code Monkey home page Code Monkey logo

kamal-deploy's Introduction

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
$ ssh-keygen -t ed25519
  1. Export public key to the authorized_keys to allow the usage of this keypair to login
$ 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.
$ 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

# This is a basic workflow to help you get started with Actions
name: Deploy with Capistrano

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [main]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  deploy:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - uses: ruby/setup-ruby@v1
        with:
          # ruby-version: 3.0.1 # Not needed with a .ruby-version file
          bundler-cache: true # runs 'bundle install' and caches installed gems automatically
      - uses: miloserdow/capistrano-deploy@v3 # you can use miloserdow/capistrano-deploy@master for the cuurent stable dev version
        with:
          target: development # Defines the environment that will be used for the deployment
          deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your github project
          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: 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: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event

Workflow file:

name: Start Rails and Sidekiq with Capistrano

on:
  workflow_dispatch:
    inputs:
      environment:
        description: "The environment to deploy"
        required: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Turnstyle
        uses: softprops/turnstyle@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          abort-after-seconds: 3600
      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.6.6
          bundler-cache: true
      - name: Deploy
        uses: kaspernj/capistrano-deploy@custom-capistrano-command
        with:
          capistrano_commands: '["puma:start", "sidekiq:start"]'
          target: ${{ github.event.inputs.environment }}
          deploy_key: ${{ secrets.DEPLOY_ENC_KEY }}
          enc_rsa_key_pth: config/deploy_id_ed25519_enc

Curl command

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

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

kamal-deploy's People

Contributors

miloserdow avatar davertmik avatar tvdeyen avatar kaspernj avatar felipecsl avatar cassiompf avatar c10ne avatar dependabot[bot] avatar benpickles avatar karolsojko avatar kevinluo201 avatar milanito avatar mjkim avatar sulmanweb avatar vadim7j7 avatar ksz2k avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.