-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (87 loc) · 4.08 KB
/
prisma-migrate-private-rds.yml
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
name: Prisma Migrate Deploy
on:
# Purely set up to be a manual trigger at the moment
workflow_dispatch:
jobs:
setup:
runs-on: ubuntu-latest
env:
AWS_SECURITY_GROUP : ${{ secrets.AWS_SECURITY_GROUP }}
AWS_SUBNET_ID : ${{ secrets.AWS_SUBNET_ID }}
AWS_AMI : ${{ secrets.AWS_AMI }}
AWS_EC2_INSTANCE_NAME : ${{ secrets.AWS_EC2_INSTANCE_NAME }}
AWS_KEY_NAME : ${{ secrets.AWS_KEY_NAME }}
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BEEEM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BEEEM_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Create EC2 Instance
run: |
aws ec2 run-instances --image-id $AWS_AMI --count 1 --instance-type t2.micro --key-name $AWS_KEY_NAME --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=${AWS_EC2_INSTANCE_NAME} }]" --security-group-ids $AWS_SECURITY_GROUP --subnet-id $AWS_SUBNET_ID
# TODO: Replace this with an ec2 instance-running wait command
- name: Sleep for 60 seconds
run: sleep 60s
shell: bash
migration:
runs-on: ubuntu-latest
needs: [setup]
env:
PRIVATE_KEY: ${{ secrets.BEEEM_UPSTIX_PEM }}
DATABASE_URL : ${{ secrets.DATABASE_URL }}
AWS_SECURITY_GROUP : ${{ secrets.AWS_SECURITY_GROUP }}
AWS_SUBNET_ID : ${{ secrets.AWS_SUBNET_ID }}
AWS_AMI : ${{ secrets.AWS_AMI }}
AWS_EC2_INSTANCE_NAME : ${{ secrets.AWS_EC2_INSTANCE_NAME }}
AWS_KEY_NAME : ${{ secrets.AWS_KEY_NAME }}
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BEEEM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BEEEM_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Run EC2 Activity
run: |
# set the hostname variable
HOSTNAME=`aws ec2 describe-instances --filters "Name=tag:Name,Values=${AWS_EC2_INSTANCE_NAME}" "Name=instance-state-name,Values=running" --query "Reservations[].Instances[].PublicDnsName" --max-items 1 | grep -vE '\[|\]' | awk -F'"' '{ print $2 }'`
# set the private key
echo "$PRIVATE_KEY" > private_key.pem && chmod 400 private_key.pem
# Copy the files
echo DATABASE_URL=$DATABASE_URL > .env
ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@$HOSTNAME 'ls'
scp -r -o StrictHostKeyChecking=no -i private_key.pem .env apps/api/prisma ec2-user@$HOSTNAME:~/
# SSH in to the box and run commands
ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@$HOSTNAME '
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash &&
. ~/.nvm/nvm.sh &&
nvm install node && npm install --global yarn &&
yarn add @prisma/client@3.2.1 &&
yarn add prisma@3.2.1 &&
yarn add prisma-dbml-generator@0.8.1 &&
yarn prisma generate &&
yarn prisma migrate deploy '
shut_down:
runs-on: ubuntu-latest
needs: [setup, migration]
env:
AWS_EC2_INSTANCE_NAME : ${{ secrets.AWS_EC2_INSTANCE_NAME }}
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BEEEM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BEEEM_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Terminate EC2
run: |
INSTANCE=`aws ec2 describe-instances --filters "Name=tag:Name,Values=${AWS_EC2_INSTANCE_NAME}" --query "Reservations[].Instances[].InstanceId" --output text`
aws ec2 terminate-instances --instance-ids $INSTANCE