-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (83 loc) · 3.42 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
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
88
89
90
91
name: Docker Build And Deploy
on:
push:
branches:
- prod
- main
jobs:
next-build:
name: Build Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Step 1: Checkout the code from the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Docker Buildx for multi-platform builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
# Step 4: Build and Push Docker Image
- name: Build and Push Docker Image
env:
ENV_FILE: ${{ secrets.DISCOVER_ENV_FILE }}
run: |
echo "$ENV_FILE" > .env
export CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
export TAG=$([[ $CURRENT_BRANCH == $(basename ${{ github.ref }}) ]] && echo $CURRENT_BRANCH || echo "latest")
echo $TAG
export GITHUB_REF_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
export GITHUB_BRANCH_IMAGE=ghcr.io/$GITHUB_REPOSITORY:$TAG
export GITHUB_REF_IMAGE=$(echo $GITHUB_REF_IMAGE | tr '[:upper:]' '[:lower:]')
export GITHUB_BRANCH_IMAGE=$(echo $GITHUB_BRANCH_IMAGE | tr '[:upper:]' '[:lower:]')
docker build --build-arg version=$GITHUB_SHA -t $GITHUB_REF_IMAGE -t $GITHUB_BRANCH_IMAGE .
echo "Pushing Image to GitHub Container Registry"
docker push $GITHUB_REF_IMAGE
docker push $GITHUB_BRANCH_IMAGE
rm -rf .env
deploy-prod:
name: Deploy to Production
needs: next-build
if: github.ref == 'refs/heads/prod'
runs-on: ubuntu-latest
steps:
- name: Deploy on Production Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.REMOTE_SERVER_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
pwd
sudo docker stop discover && sudo docker rm discover && sudo docker rmi hcr.io/myriadflow/discover:prod
echo ${{ secrets.GHCR_TOKEN }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
sudo docker pull ghcr.io/myriadflow/discover:prod
sudo docker run --name="discover" -p 9082:3000 -d ghcr.io/myriadflow/discover:prod
deploy-dev:
name: Deploy to Development
needs: next-build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Deploy on Development Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.DEV_REMOTE_SERVER_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
pwd
sudo docker stop discover && sudo docker rm discover && sudo docker rmi hcr.io/myriadflow/discover:main
echo ${{ secrets.GHCR_TOKEN }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
sudo docker pull ghcr.io/myriadflow/discover:main
sudo docker run --name="discover" -p 9082:3000 -d ghcr.io/myriadflow/discover:main