-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (49 loc) · 1.91 KB
/
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
name: Deployment Workflow
on:
push:
branches:
- main
workflow_dispatch:
env:
CONFIG_ENV: ${{ secrets.CONFIG_ENV }}
REGISTRY: ${{ secrets.REGISTRY }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_IMAGE: ${{ secrets.REGISTRY_IMAGE }}
REGISTRY_ACCESS_TOKEN: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
jobs:
Deploy-to-EC2:
name: Deploy to EC2
runs-on: ubuntu-22.04
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Sign in to Container Registry
run: echo $REGISTRY_ACCESS_TOKEN | docker login -u $REGISTRY_USER --password-stdin $REGISTRY
- name: Build and Tag Image
run: |
echo $CONFIG_ENV | tr ' ' '\n' > .env
docker build -t "$REGISTRY/$REGISTRY_IMAGE:${{ github.sha }}" .
docker tag "$REGISTRY/$REGISTRY_IMAGE:${{ github.sha }}" "$REGISTRY/$REGISTRY_IMAGE:latest"
- name: Publish to Container Registry
run: docker push "$REGISTRY/$REGISTRY_IMAGE:latest"
- name: Pull Latest Image and Run Container
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATEKEY }}
envs: CONFIG_ENV,REGISTRY_ACCESS_TOKEN,REGISTRY_USER,REGISTRY,REGISTRY_IMAGE
script: |
mkdir -pv ./app/chiral/config
cd ./app/chiral
echo $CONFIG_ENV | tr ' ' '\n' > .env
echo $REGISTRY_ACCESS_TOKEN | docker login -u $REGISTRY_USER --password-stdin $REGISTRY
docker rm -f chiral
docker rmi "$REGISTRY/$REGISTRY_IMAGE" &>2
docker pull "$REGISTRY/$REGISTRY_IMAGE:latest"
docker run -d --name chiral \
--restart always \
-v "$(pwd)/.env:/app/.env:ro" \
-v "$(pwd)/config:/app/config" \
-p "3000:3000" \
"$REGISTRY/$REGISTRY_IMAGE:latest"