Skip to content

Capistrano Deployment #421

Capistrano Deployment

Capistrano Deployment #421

Workflow file for this run

name: Capistrano Deployment
# Controls when the action will run.
on:
push:
branches:
- stage
- test
# Allows running this workflow manually from the Actions tab
workflow_dispatch:
inputs:
BRANCH:
description: "Branch/tag to deploy"
default: stage
required: true
environment:
description: "Target environment to deploy to"
type: choice
options:
- staging
- agroportal
- test
default: staging
jobs:
deploy:
runs-on: ubuntu-latest
env:
BUNDLE_WITHOUT: default # Install gems required primarily for deployment to speed up workflow
PRIVATE_CONFIG_REPO: ${{ format('git@github.com:{0}.git', secrets.CONFIG_REPO) }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Set branch/tag and environment to deploy from inputs
run: |
# Set default branch/tag for push events
BRANCH=${{ github.head_ref || 'master' }}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
# Set default environment for push events
if [ "${{ github.event_name }}" = "push" ]; then
TARGET="staging" # Default to staging for push
else
TARGET=${{ inputs.environment }}
fi
echo "TARGET=$TARGET" >> $GITHUB_ENV
CONFIG_REPO=${{ secrets.CONFIG_REPO }}
GH_PAT=${{ secrets.GH_PAT }}
echo "PRIVATE_CONFIG_REPO=https://${GH_PAT}@github.com/${CONFIG_REPO}" >> $GITHUB_ENV
echo "SSH_JUMPHOST=${{ secrets.SSH_JUMPHOST }}" >> $GITHUB_ENV
echo "SSH_JUMPHOST_USER=${{ secrets.SSH_JUMPHOST_USER }}" >> $GITHUB_ENV
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.6 # Not needed with a .ruby-version file
bundler-cache: true # Runs 'bundle install' and caches installed gems automatically
- name: Get deployment config
uses: actions/checkout@v3
with:
repository: ${{ secrets.CONFIG_REPO }} # Repository containing deployment settings
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
path: deploy_config
- name: Copy deployment config
run: cp -r deploy_config/ontoportal_web_ui/${{ env.TARGET }}/* .
# Add SSH host key so that Capistrano doesn't complain
- name: Add jumphost's hostkey to Known Hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_JUMPHOST }}"
ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts
shell: bash
- uses: miloserdow/capistrano-deploy@master
with:
target: ${{ env.TARGET }} # Which environment to deploy
deploy_key: ${{ secrets.DEPLOY_ENC_KEY }} # Name of the variable configured in Settings/Secrets of your GitHub project