Skip to content

Commit

Permalink
Refactor deploy-to-vps.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mega-JC committed Aug 15, 2024
1 parent c382f7f commit bc3422c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/deploy-to-vps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@ jobs:

- name: Deploy to VPS
uses: easingthemes/ssh-deploy@main
env:
VPS_ENV_DIRECTORY: ${{ secrets.VPS_ENV_DIRECTORY }}
with:
SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc --delete"
REMOTE_HOST: ${{ secrets.VPS_HOST }}
REMOTE_USER: ${{ secrets.VPS_USER }}
TARGET: ${{ secrets.VPS_TARGET }}
SCRIPT_AFTER: |
# Check if a directory for environment and config files is specified and copy its contents to the current directory if yes
if [ -n "${{ secrets.VPS_ENV_DIRECTORY }}" ] && [ -d "${{ secrets.VPS_ENV_DIRECTORY }}" ]; then cp -ar "${{ secrets.VPS_ENV_DIRECTORY }}"/. .; fi
# Get environment and config files
cp -ar ${{ env.VPS_ENV_DIRECTORY }}/. .
# Detect all usable Compose files ([docker-]compose.yml and [docker-]compose.override.yml) and prefix their filename with "-f "
COMPOSE=$( [ -f "docker-compose.yml" ] && echo -n "-f docker-compose.yml " || true; \
[ -f "docker-compose.override.yml" ] && echo -n "-f docker-compose.override.yml " || true; \
[ -f "compose.yml" ] && echo -n "-f compose.yml " || true; \
[ -f "compose.override.yml" ] && echo -n "-f compose.override.yml " || true )
# Stop, remove, and build the Docker Compose stack
docker compose $COMPOSE stop
docker compose $COMPOSE rm
docker compose $COMPOSE down -v --remove-orphans
sleep 60
docker compose $COMPOSE build --no-cache
docker compose $COMPOSE up -d
docker image prune -af
SCRIPT_AFTER_REQUIRED: true

0 comments on commit bc3422c

Please sign in to comment.