update: ci/cd
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
name: Deploy Production Server
|
||||
|
||||
# Only run the workflow when a PR is merged on main and closed
|
||||
on: [push]
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
# Here we check that the PR was correctly merged to main
|
||||
jobs:
|
||||
if_merged:
|
||||
if: github.event.pull_request.merged == true
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -17,19 +24,66 @@ jobs:
|
||||
distribution: 'graalvm'
|
||||
cache: 'maven'
|
||||
|
||||
- name: Build site
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: src/main/webapp/package-lock.json
|
||||
|
||||
- name: Build frontend
|
||||
run: |
|
||||
cp vite.env src/main/webapp/.env
|
||||
echo "${{ vars.VITE_ENV }}" > src/main/webapp/.env
|
||||
cd src/main/webapp
|
||||
npm install
|
||||
npm run build
|
||||
cd ../../..
|
||||
|
||||
- name: Inject frontend in backend
|
||||
run: |
|
||||
rm -rf src/main/resources/META-INF/resources
|
||||
mkdir -p src/main/resources/META-INF/
|
||||
mv dist src/main/resources/META-INF/resources
|
||||
mv src/main/webapp/dist src/main/resources/META-INF/resources
|
||||
|
||||
- name: Build application
|
||||
- name: Build backend
|
||||
run: |
|
||||
cp ../vite.env src/main/webapp/.env
|
||||
chmod 740 mvnw
|
||||
./mvnw package -Pnative -DskipTests
|
||||
./mvnw package -Pnative -DskipTests
|
||||
|
||||
- name: Copy runner to vps via scp
|
||||
uses: appleboy/scp-action@v0.1.7 # Latest in date when creating the workflow
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
port: ${{ secrets.SSH_PORT }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
source: "target/*-runner,src/main/resources/cacerts,src/main/docker/Dockerfile.native,docker-compose.yml,.dockerignore"
|
||||
target: ${{ secrets.TARGET_DIR }} # Need to create it first on the VPS
|
||||
|
||||
- name: Re-start ffsaf container
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
port: ${{ secrets.SSH_PORT }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
script: |
|
||||
cd ${{ secrets.TARGET_DIR }}
|
||||
docker stop ffsaf
|
||||
docker rm ffsaf
|
||||
docker compose up --build -d ffsaf
|
||||
|
||||
- name: Check ffsaf container
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
port: ${{ secrets.SSH_PORT }}
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
script: |
|
||||
if docker ps | grep ffsaf; then
|
||||
echo 'Container is running'
|
||||
else
|
||||
echo 'Container is not running'
|
||||
exit 1 # This mark the pipeline as failed
|
||||
fi
|
||||
Reference in New Issue
Block a user