Skip to content

Commit 8037cbd

Browse files
committed
efw
1 parent 5da6e43 commit 8037cbd

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

.github/workflows/deployVPS.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Deploy to VPS
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag to deploy'
8+
required: false
9+
type: string
10+
default: 'latest'
11+
workflow_call:
12+
inputs:
13+
tag:
14+
required: false
15+
type: string
16+
default: 'latest'
17+
18+
jobs:
19+
buildAndPush:
20+
name: Build and Push Docker Image
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
environment: [production-ca, production-uk]
25+
26+
environment: ${{ matrix.environment }}
27+
28+
env:
29+
IMAGE_TAG: ${{ inputs.tag }}
30+
permissions:
31+
contents: read
32+
packages: write
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v2
37+
38+
- name: Login to Docker Hub
39+
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
40+
41+
- name: Login to GitHub Container Registry
42+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
43+
44+
- name: Build Docker image
45+
run: |
46+
docker build \
47+
--build-arg REACT_APP_BACKEND_URL=${{ secrets.BACKEND_URL }} \
48+
--build-arg REACT_APP_BACKEND_PORT=${{ secrets.BACKEND_PORT }} \
49+
--build-arg REACT_APP_SALT_HASH=${{ secrets.BACKEND_SALT }} \
50+
-t ${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.IMAGE_TAG }} .
51+
52+
- name: Push Docker image (Docker Hub)
53+
run: docker push ${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.IMAGE_TAG }}
54+
55+
- name: Tag image for GHCR
56+
if: matrix.environment == 'production-uk'
57+
run: |
58+
IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
59+
docker tag ${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.IMAGE_TAG }} ghcr.io/$IMAGE_NAME:${{ env.IMAGE_TAG }}
60+
61+
- name: Push image to GHCR
62+
if: matrix.environment == 'production-uk'
63+
run: |
64+
IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
65+
docker push ghcr.io/$IMAGE_NAME:${{ env.IMAGE_TAG }}
66+
67+
68+
deploy:
69+
name: Deploy to VPS
70+
needs: buildAndPush
71+
runs-on: ubuntu-latest
72+
strategy:
73+
matrix:
74+
environment: [production-ca, production-uk]
75+
76+
environment: ${{ matrix.environment }}
77+
env:
78+
IMAGE_TAG: ${{ inputs.tag }}
79+
steps:
80+
81+
- name: Checkout code
82+
uses: actions/checkout@v2
83+
84+
- name: Deploy config & restart POS on VPS
85+
uses: easingthemes/ssh-deploy@main
86+
with:
87+
SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH }}
88+
REMOTE_HOST: ${{ secrets.VPS_HOST }}
89+
REMOTE_USER: ${{ secrets.VPS_USERNAME }}
90+
TARGET: ${{ secrets.VPS_TARGET }}
91+
ARGS: "-rlgoDzvc --delete"
92+
SOURCE: docker-compose.yml
93+
SCRIPT_AFTER: |
94+
echo "POS_IMAGE_TAG=${{ env.IMAGE_TAG }}" > ${{ secrets.VPS_TARGET }}.env
95+
sleep 2
96+
echo "Pull and restart POS container"
97+
cd ${{ secrets.VPS_TARGET }}
98+
echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
99+
docker-compose down
100+
docker rm -f pos || true
101+
docker-compose pull
102+
docker-compose up -d
103+
SCRIPT_AFTER_REQUIRED: true

0 commit comments

Comments
 (0)