-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (41 loc) · 1.62 KB
/
deploy-node.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
name: Build and Deploy Node Docker Image to EC2
on:
push:
branches:
- deploy-node
jobs:
build-node-api-image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to Docker Hub
run: echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin
- name: Build Docker image
run: docker build -t elarsaks/gorilla-labs-api:${{ github.sha }} ./apps/api
- name: Push Docker image to Docker Hub
run: docker push elarsaks/gorilla-labs-api:${{ github.sha }}
deploy-to-ec2:
needs: build-node-api-image
runs-on: ubuntu-latest
steps:
- name: Deploy New Image and Cleanup
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
username: ubuntu
script: |
echo ${{ secrets.DOCKER_REGISTRY_TOKEN }} | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin
docker pull elarsaks/gorilla-labs-api:${{ github.sha }}
# Stop and remove any existing container (ignore errors if not existing)
docker stop gorilla-labs-api || true
docker rm gorilla-labs-api || true
# Run the new container
docker run -d --restart=always \
--name gorilla-labs-api \
--network gorilla-labs-network \
-p 4000:4000 \
elarsaks/gorilla-labs-api:${{ github.sha }}
# Cleanup unused Docker images
docker image prune -af