Merge pull request 'Automatic cleanup' (#7) from feature/staging into main
Reviewed-on: #7
This commit is contained in:
commit
e2cd7ebee1
2 changed files with 37 additions and 0 deletions
35
.forgejo/workflows/cleanup.yaml
Normal file
35
.forgejo/workflows/cleanup.yaml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
name: Cleanup Staging
|
||||
|
||||
on:
|
||||
delete:
|
||||
branches:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
cleanup:
|
||||
if: github.event.ref_type == 'branch' && github.event.ref != 'main'
|
||||
runs-on: arch-latest
|
||||
steps:
|
||||
- name: Remove staging environment
|
||||
uses: appleboy/ssh-action@v1.2.3
|
||||
env:
|
||||
BRANCH_NAME: ${{ github.event.ref }}
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_IP }}
|
||||
username: ${{ secrets.DEPLOY_USER }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
envs: BRANCH_NAME
|
||||
script: |
|
||||
BRANCH_SLUG=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
|
||||
DEPLOY_DIR="/opt/czsk-${BRANCH_SLUG}"
|
||||
CONTAINER_NAME="czsk-${BRANCH_SLUG}"
|
||||
|
||||
if [ -d "$DEPLOY_DIR" ]; then
|
||||
cd $DEPLOY_DIR
|
||||
docker compose down --rmi all 2>/dev/null || true
|
||||
cd /
|
||||
rm -rf $DEPLOY_DIR
|
||||
echo "Cleaned up staging: ${BRANCH_SLUG}"
|
||||
else
|
||||
echo "No staging environment found for: ${BRANCH_SLUG}"
|
||||
fi
|
||||
|
|
@ -12,3 +12,5 @@ Deployments are automatic on push via Forgejo Actions.
|
|||
Branch names are sanitized to `a-z0-9` only (lowercase, symbols removed).
|
||||
|
||||
**Example:** `fix1/blabla` deploys to `fix1blabla.staging.czsk.it`
|
||||
|
||||
Staging environments are automatically removed when the branch is deleted.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue