Skip to content

Commit

Permalink
feature: add deploy config for agroportal
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 10, 2024
1 parent 97c12e4 commit 88c6855
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 48 deletions.
97 changes: 49 additions & 48 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ name: Capistrano Deployment
# Controls when the action will run.
on:
push:
branches: [ stage test]
branches:
- stage
- test
# Allows running this workflow manually from the Actions tab
workflow_dispatch:
inputs:
BRANCH:
description: 'Branch/tag to deploy'
description: "Branch/tag to deploy"
options:
- stage
- test
- master
default: test
default: stage
required: true
environment:
description: 'target environment to deploy to'
description: "target environment to deploy to"
type: choice
options:
- staging
- production
- appliance
- agroportal
- test
default: test
default: stage
jobs:
deploy:
runs-on: ubuntu-latest
Expand All @@ -47,45 +48,45 @@ jobs:
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: |
# workflow_dispatch default input doesn't get set on push so we need to set defaults
# via shell parameter expansion
# https://dev.to/mrmike/github-action-handling-input-default-value-5f2g
USER_INPUT_BRANCH=${{ inputs.branch }}
echo "BRANCH=${USER_INPUT_BRANCH:github.head_ref:-master}" >> $GITHUB_ENV
- name: set branch/tag and environment to deploy from inputs
run: |
# workflow_dispatch default input doesn't get set on push so we need to set defaults
# via shell parameter expansion
# https://dev.to/mrmike/github-action-handling-input-default-value-5f2g
USER_INPUT_BRANCH=${{ inputs.branch }}
echo "BRANCH=${USER_INPUT_BRANCH:github.head_ref:-master}" >> $GITHUB_ENV
USER_INPUT_ENVIRONMENT=${{ inputs.environment }}
echo "TARGET=${USER_INPUT_ENVIRONMENT:-staging}" >> $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/${{ inputs.environment }}/* .
# add ssh hostkey 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
USER_INPUT_ENVIRONMENT=${{ inputs.environment }}
echo "TARGET=${USER_INPUT_ENVIRONMENT:-staging}" >> $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/${{ inputs.environment }}/* .
# add ssh hostkey 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
17 changes: 17 additions & 0 deletions config/deploy/agroportal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
# Don't declare `role :all`, it's a meta role
role :app, %w[agroportal.lirmm.fr]
role :db, %w[agroportal.lirmm.fr] # sufficient to run db:migrate only on one system
set :branch, ENV.include?('BRANCH') ? ENV['BRANCH'] : 'master'
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
# server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
set :log_level, :error

0 comments on commit 88c6855

Please sign in to comment.