forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 12
111 lines (107 loc) · 4.68 KB
/
deploy.yml
File metadata and controls
111 lines (107 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Workflow for deploying ontologies_api to stage/prod systems via capistrano.
# This workflow runs after a successeful execution of the unit test workflow and it
# can also be triggered manually.
#
# Required github secrets:
#
# CONFIG_REPO - github repo containing config and customizations for the API. Format 'author/private_config_repo'
# it is used for getting capistrano deployment configuration for stages on the github actions runner and
# PRIVATE_CONFIG_REPO env var is constructed from it which is used by capistrano on the remote servers for pulling configs.
#
# GH_PAT - github Personal Access Token for accessing PRIVATE_CONFIG_REPO
#
# SSH_JUMPHOST - ssh jump/proxy host though which deployments have to though if app servers are hosted on private network.
#
# DEPLOY_ENC_KEY - key for decrypting deploymnet ssh key residing in config/deploy_id_rsa_enc (see miloserdow/capistrano-deploy)
# this SSH key is used for accessing jump host, UI nodes, and private github repo.
name: Capistrano Deployment
permissions:
contents: read
on:
# Trigger deployment to staging after unit test action completes
workflow_run:
workflows: ["Ruby Unit Tests"]
types:
- completed
branches: [develop] # trigger auto deployment to staging from develop branch
# Allows running this workflow manually from the Actions tab
workflow_dispatch:
inputs:
branch:
description: 'Branch/tag to deploy'
default: develop
required: true
environment:
description: 'target environment to deploy to'
type: choice
options:
- staging
- production
default: staging
jobs:
deploy:
concurrency:
group: deploy
runs-on: ubuntu-latest
# run deployment only if "Ruby Unit Tests" workflow completes sucessefully
# or when manually triggered
if: >
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success') ||
(github.event_name == 'workflow_dispatch')
env:
BUNDLE_WITHOUT: default:test:development #install gems required primarily for the deployment in order to speed this workflow
PRIVATE_CONFIG_REPO: ${{ format('git@github.com:{0}.git', secrets.CONFIG_REPO) }}
steps:
- name: set branch/tag and environment to deploy from inputs
run: |
if [ "${{ github.event_name }}" = "workflow_run" ]; then
# Auto: always deploy develop to staging
echo "BRANCH=develop" >> "$GITHUB_ENV"
# echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> "$GITHUB_ENV" # auto deploy from branch if needed
echo "TARGET=staging" >> "$GITHUB_ENV"
else
# Manual: use inputs, with defaulting via parameter expansion
USER_INPUT_BRANCH=${{ inputs.branch }}
USER_INPUT_ENVIRONMENT=${{ inputs.environment }}
echo "BRANCH=${USER_INPUT_BRANCH:-develop}" >> "$GITHUB_ENV"
echo "TARGET=${USER_INPUT_ENVIRONMENT:-staging}" >> "$GITHUB_ENV"
fi
- name: Provide deployment info
run: |
echo "=== Deployment Details ======================================"
echo "Time: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
echo "Branch/Tag: ${BRANCH}"
echo "Environment: ${TARGET}"
echo "Commit: ${GITHUB_SHA}"
echo "Triggered by: ${GITHUB_ACTOR}"
echo "Event: ${GITHUB_EVENT_NAME}"
if [ "${GITHUB_EVENT_NAME}" = "workflow_run" ]; then
echo "Mode: auto-deploy from develop"
else
echo "Mode: manual deployment"
fi
echo "=============================================================="
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v5
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: get-deployment-config
uses: actions/checkout@v5
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/ontologies_api/* .
# add ssh hostkey so that capistrano doesn't complain
- name: Add jumphost's hostkey to Known Hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SSH_JUMPHOST }} > ~/.ssh/known_hosts
shell: bash
- uses: miloserdow/capistrano-deploy@v3
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