Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Capistrano command #28

Merged
merged 4 commits into from
Dec 1, 2020

Conversation

kaspernj
Copy link
Contributor

@kaspernj kaspernj commented Nov 30, 2020

I am working on a project that uses Docker to host the project and Capistrano to deploy.

When the container restarts, I want it to call a Github Action Workflow to start Rails, Sidekiq and other services through existing setup based on Github Actions.

This gem is perfect for that if I could just change the command that is called.

Guide to make it work

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

Example 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 }}

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\"}}"

I made Docker run this Curl command on startup which makes Github start Rails and Sidekiq.

@kaspernj kaspernj marked this pull request as ready for review November 30, 2020 20:32
@miloserdow miloserdow merged commit 423fcb1 into miloserdow:master Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants