-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (62 loc) · 2.18 KB
/
docker_build_and_deploy.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
name: Docker Image CI and Deploy to Amazon EC2
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker Setup Buildx
uses: docker/[email protected]
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set image name with date
run: echo "IMAGE_NAME=bada308/mooluck-node:$(date +%s)" >> $GITHUB_ENV
- name: Build and push the Docker image
run: |
docker build . --file Dockerfile -t ${{ env.IMAGE_NAME }}
docker push ${{ env.IMAGE_NAME }}
- name: Save image name to file
run: echo ${{ env.IMAGE_NAME }} > image-name.txt
- name: Upload image name artifact
uses: actions/[email protected]
with:
name: image-name
path: image-name.txt
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download image name artifact
uses: actions/[email protected]
with:
name: image-name
- name: Read image name from file
id: read-image-name
run: echo "IMAGE_NAME=$(cat image-name.txt)" >> $GITHUB_ENV
- name: SSH into EC2 and deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker pull ${{ env.IMAGE_NAME }}
sudo docker stop mooluck-node || true
sudo docker rm mooluck-node || true
sudo docker run -d --name mooluck-node -p 3000:8080 \
-e LIVEKIT_API_KEY=${{ secrets.LIVEKIT_API_KEY }} \
-e LIVEKIT_API_SECRET=${{ secrets.LIVEKIT_API_SECRET }} \
-e LOCALHOST_URL=${{ secrets.LOCALHOST_URL }} \
-e APP_URL=${{ secrets.APP_URL }} \
${{ env.IMAGE_NAME }}