-
Notifications
You must be signed in to change notification settings - Fork 1
75 lines (65 loc) · 2.37 KB
/
main.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
name: Deploy to EC2
on:
push:
branches: [ main ]
jobs:
deploy:
name: Deploy to EC2
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: write env file
run: |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" > .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
echo "NCP_CLIENT_ID=${{ secrets.NCP_CLIENT_ID }}" >> .env
echo "NCP_CLIENT_SECRET=${{ secrets.NCP_CLIENT_SECRET }}" >> .env
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> .env
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> .env
echo "HASH_SALT=${{ secrets.HASH_SALT }}" >> .env
- name: Set up and build Docker Compose
run: |
sudo apt-get update
sudo apt-get -y install docker-compose
docker-compose build
- name: Docker Hub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Hub Push
run: |
docker-compose push
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
source: docker-compose.yml
target: /home/ec2-user/
- name: Copy .env to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.WAS_HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
source: .env
target: /home/ec2-user/
- name: Connect and Deploy to EC2
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.WAS_HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
script: |
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
cd /home/ec2-user/
docker-compose pull # Pull the latest images on EC2
docker-compose up -d # Run the containers on EC2