-
Notifications
You must be signed in to change notification settings - Fork 2
64 lines (64 loc) · 3.03 KB
/
start_process.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
name: start_process
on:
workflow_dispatch:
concurrency: only_one_run_at_a_time
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
start_process:
needs: call_context_check
runs-on: ubuntu-latest
env:
INSTANCE_ID: ${{ secrets.INSTANCE_ID }}
INSTANCE_IP: ${{ secrets.INSTANCE_IP }}
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: start worker instance
run: |
echo "INFO::start worker instance"
aws ec2 start-instances --instance-ids ${INSTANCE_ID}
sleep 90
- name: start process
run: |
echo "INFO::start process"
ssh-keygen -t rsa -b 2048 -C arseny -f ./arseny_temp_ssh -q -N ""
aws ec2-instance-connect send-ssh-public-key \
--instance-id ${INSTANCE_ID} \
--instance-os-user ubuntu \
--availability-zone us-east-1a \
--ssh-public-key file://${PWD}/arseny_temp_ssh.pub
ssh -o "StrictHostKeyChecking no" -i arseny_temp_ssh ubuntu@${INSTANCE_IP} "sudo rm -rf /home/ubuntu/ArsenyLabWorkflow;git clone https://github.com/${GITHUB_REPOSITORY}.git /home/ubuntu/ArsenyLabWorkflow;bash /home/ubuntu/ArsenyLabWorkflow/entrypoint.sh" || true
rm -f ./arseny_temp_ssh*
echo "INFO::process finished"
- name: stop worker instance
run: |
echo "INFO::stop worker instance"
ssh-keygen -t rsa -b 2048 -C arseny -f ./arseny_temp_ssh -q -N ""
aws ec2-instance-connect send-ssh-public-key \
--instance-id ${INSTANCE_ID} \
--instance-os-user ubuntu \
--availability-zone us-east-1a \
--ssh-public-key file://${PWD}/arseny_temp_ssh.pub
ssh -o "StrictHostKeyChecking no" -i arseny_temp_ssh ubuntu@${INSTANCE_IP} "sudo shutdown now" || true
rm -f ./arseny_temp_ssh*
echo "INFO::instance stopped"