forked from ArsenyFinkelsteinLab/DJ_cloud
-
Notifications
You must be signed in to change notification settings - Fork 2
66 lines (62 loc) · 2.67 KB
/
start.yaml
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
name: start
on:
workflow_dispatch:
jobs:
check_your_permission:
runs-on: ubuntu-latest
steps:
- name: Checkout workflow repo
uses: actions/checkout@v3
- name: check your permission
run: |
if grep -Fxq "$GITHUB_ACTOR" ./.github/workflows/start_process_allow_list
then
echo "INFO::Passed"
else
echo "ERROR::Please make a pull request to add your github username in '.github/workflows/start_process_allow_list'"
exit 1
fi
call_context_check:
needs: check_your_permission
uses: dj-sciops/djsciops-cicd/.github/workflows/context_check.yaml@main
check_if_instance_running:
needs: call_context_check
runs-on: ubuntu-latest
env:
INSTANCE_ID: ${{ secrets[format('{0}_instance_id', github.ref_name)] }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Check instance state
id: check_instance_state
run: |
[ -z "$INSTANCE_ID" ] && echo "ERROR::Can't find an instance for deployment branch: $GITHUB_REF_NAME" && exit 1
export STATE=$(aws ec2 describe-instances --output text --filters Name=instance-id,Values=$INSTANCE_ID --query "Reservations[].Instances[].State[].Name[]")
echo $STATE
echo "instance_state=$STATE" >> $GITHUB_OUTPUT
- name: Instance is running
if: steps.check_instance_state.outputs.instance_state == 'running'
run: |
echo "INFO:: Instance is still running, wait for the current process to finish or you can trigger 'force_stop' to stop the current process"
exit 1
- name: Instance is running
if: steps.check_instance_state.outputs.instance_state == 'stopping'
run: |
echo "INFO:: Instance is still stopping, give it a minute and then trigger 'start' again"
exit 1
outputs:
instance_state: ${{ steps.check_instance_state.outputs.instance_state }}
trigger_process:
needs: check_if_instance_running
if: needs.check_if_instance_running.outputs.instance_state == 'stopped'
uses: ./.github/workflows/start_process.yaml
secrets:
INSTANCE_ID: ${{ secrets[format('{0}_instance_id', github.ref_name)] }}
INSTANCE_IP: ${{ secrets[format('{0}_instance_ip', github.ref_name)] }}
SSH_KEY: ${{ secrets.SSH_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}