-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (47 loc) · 2 KB
/
putfiles2ec2.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
# Action Repository: https://github.com/antoniohernan/putfiles2ec2/blob/main/.github/workflows/deployec2.yml
name: Deploy Ec2
on:
push:
branches:
- main
paths: 'data/**'
env:
IP_RUNNER: 192.168.1.1/32
jobs:
deploy:
name: Deploy file to EC2
runs-on: ubuntu-latest
steps:
- name: Configure AWS
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Obtain public IP
run: echo "IP_RUNNER=$(wget -qO- https://ipecho.net/plain)" >> $GITHUB_ENV ${{ secrets.TRASH }}
- name: Authorize Access
run: aws ec2 authorize-security-group-ingress --group-id "${{ secrets.AWS_SGWEB }}" --protocol tcp --port "${{ secrets.AWS_VMPORT }}" --cidr "${{ env.IP_RUNNER }}/32"
- name: Prepare Runner
shell: bash
env:
AWSKEY: ${{ secrets.AWS_KEY }}
run: |
config_ssh=~/.ssh/config
keyfile=~/.ssh/Key.pem
mkdir ~/.ssh && echo -e "ExitOnForwardFailure=yes\nStrictHostKeyChecking=no" > ${config_ssh} && chmod 600 ${config_ssh}
echo "${AWSKEY}" > ${keyfile} && chmod 600 ${keyfile}
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Copy Files
shell: bash
env:
AWSDESTINATION: "${{ secrets.AWS_DESTINATION }}"
AWSVMUSERNAME: "${{ secrets.AWS_VMUSERNAME }}"
AWSVMFQDN: "${{ secrets.AWS_VMFQDN }}"
run: |
keyfile=~/.ssh/Key.pem
scp -r -i ${keyfile} $GITHUB_WORKSPACE/data/* ${AWSVMUSERNAME}@${AWSVMFQDN}:/${AWSDESTINATION} 2>/dev/null
- name: Revoke Access
if: always()
run: aws ec2 revoke-security-group-ingress --group-id "${{ secrets.AWS_SGWEB }}" --protocol tcp --port "${{ secrets.AWS_VMPORT }}" --cidr "${{ env.IP_RUNNER }}/32"