113 lines
3.1 KiB
YAML
113 lines
3.1 KiB
YAML
name: Deploy On Server
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "main"
|
|
|
|
env:
|
|
REMOTE_WORKING_DIRECTORY: compose/wedding-website
|
|
|
|
jobs:
|
|
prepare-repository-remotely:
|
|
name: Prepare Repository Remotely
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
path: repository
|
|
|
|
- name: Prepare Remote Directory
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script_stop: true
|
|
script: |
|
|
mkdir -p ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
cd ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
find . -mindepth 1 -maxdepth 1 \
|
|
! -name wedding-db-data \
|
|
! -name wedding-minio-data \
|
|
-exec rm -rf {} +
|
|
|
|
- name: Copy Repository over SSH
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
port: 22
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
source: "repository/*"
|
|
target: ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
rm: false
|
|
strip_components: 1
|
|
|
|
- name: Build ENV
|
|
run: |
|
|
mkdir env
|
|
echo "${{ secrets.WEDDING_WEBSITE_ENV }}" | base64 -d > env/.env
|
|
|
|
- name: Copy ENV over SSH
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
port: 22
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
source: "env/.env"
|
|
target: ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
rm: false
|
|
strip_components: 1
|
|
|
|
start-services:
|
|
name: Docker Compose Up
|
|
runs-on: ubuntu-latest
|
|
needs: prepare-repository-remotely
|
|
steps:
|
|
- name: Start Services
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script_stop: false
|
|
script: |
|
|
cd ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
docker compose up --build -d
|
|
|
|
prune-images:
|
|
name: Prune Images
|
|
runs-on: ubuntu-latest
|
|
needs: start-services
|
|
steps:
|
|
- name: Prune All Images
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script_stop: true
|
|
script: |
|
|
cd ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
docker compose images
|
|
docker image prune --all --force
|
|
|
|
remove-env-file:
|
|
name: Remove .env File
|
|
needs: start-services
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Execute rm .env
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script_stop: true
|
|
script: |
|
|
cd ${{ env.REMOTE_WORKING_DIRECTORY }}
|
|
rm .env
|