-
Notifications
You must be signed in to change notification settings - Fork 2
57 lines (52 loc) · 2.18 KB
/
deploy-prod.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
49
50
51
52
53
54
55
56
57
name: "Build and Push to GHCR"
on:
push:
branches:
- prod
jobs:
build_push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and Push Docker Image
env:
PROD_ENV_FILE: ${{ secrets.PROD_ENV_FILE }}
run: |
echo "$PROD_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_dev:
needs: build_push
runs-on: ubuntu-latest
steps:
- name: Deploy on PROD server
if: github.ref == 'refs/heads/prod'
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_REMOTE_SERVER_ADDRESS }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_REMOTE_SERVER_KEY }}
port: ${{ secrets.PROD_SSH_PORT }}
script: |
pwd
docker stop sotreus-frontend || true && docker image rm ghcr.io/netsepio/sotreus-frontend:prod
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
docker pull ghcr.io/netsepio/sotreus-frontend:prod
docker run --name="sotreus-frontend" --rm -p 4040:8080 --net=bridge -d ghcr.io/netsepio/sotreus-frontend:prod