forked from CodeYourFuture/Full-Stack-Project-Assessment
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (74 loc) · 2.68 KB
/
deploy-image.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
name: Deploy to VM
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Environment File
run: |
echo "DB_HOST=${{ secrets.RDS_DB_HOST }}" > video.env
echo "DB_USER=${{ secrets.RDS_DB_USER }}" >> video.env
echo "DB_PASSWORD=${{ secrets.RDS_DB_PASSWORD }}" >> video.env
echo "DB_PORT=${{ secrets.RDS_DB_NAME }}" >> video.env
- name: Display Environment File
run: |
mkdir -p /tmp/context
cp video.env /tmp/context
- name: Create tag
id: create_tag
run: |
TAG=$(date +'%Y%m%d%H%M%S')
echo "::set-output name=tag::$TAG"
- name: Build Docker image
run: |
cd server
docker build -t olhadanylevska/video-server:${{ steps.create_tag.outputs.tag }} .
cd ..
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image to Docker Hub
run: |
docker push olhadanylevska/video-server:${{ steps.create_tag.outputs.tag }}
- name: clean images
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: docker system prune -a -f
- name: Pull image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker pull olhadanylevska/video-server:${{ steps.create_tag.outputs.tag }}
- name: Identify and stop previous container
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
CONTAINER_ID=$(docker ps -q --filter ancestor=olhadanylevska/video-server)
if [ ! -z "$CONTAINER_ID" ]; then
docker stop $CONTAINER_ID
docker rm $CONTAINER_ID
fi
- name: Run container on VM server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker run -d --env-file /tmp/context/video.env -p 80:3000 olhadanylevska/video-server:${{ steps.create_tag.outputs.tag }}