modified yaml deploy script #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_IP }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| echo "[INFO] Stopping and removing running container (if exists)..." | |
| docker stop codeboxes-server || true | |
| docker rm -f codeboxes-server || true | |
| echo "[INFO] Killing any process explicitly using port 8080 (as a fallback)..." | |
| # Use 'lsof' which is generally more reliable and available on Ubuntu | |
| if command -v lsof >/dev/null 2>&1; then | |
| sudo lsof -t -i:8080 | xargs -r kill -9 || true | |
| else | |
| # Fallback for systems without lsof, though Ubuntu usually has it | |
| if command -v fuser >/dev/null 2>&1; then | |
| fuser -k 8080/tcp || true | |
| else | |
| # Install psmisc if fuser is not found (for Alpine-like systems, less common on Ubuntu) | |
| sudo apt-get update && sudo apt-get install -y psmisc || true | |
| fuser -k 8080/tcp || true | |
| fi | |
| fi | |
| echo "[INFO] Pruning unused Docker networks..." | |
| docker network prune -f | |
| docker image prune -f | |
| echo "[INFO] Cloning latest code..." | |
| rm -rf codeboxes-server | |
| git clone https://github.com/harshpx/codeboxes-server.git | |
| cd codeboxes-server | |
| echo "[INFO] Building codeboxes-server..." | |
| cd server | |
| docker build -t codeboxes-server . | |
| echo "[INFO] Building code-runner..." | |
| cd ../code-runner | |
| docker build -t code-runner . | |
| echo "[INFO] Starting updated codeboxes-server container..." | |
| docker run -d --name codeboxes-server \ | |
| --restart unless-stopped \ | |
| -v /var/run/docker.sock:/var/run/docker.sock \ | |
| -p 8080:8080 codeboxes-server | |
| echo "[INFO] Deployment complete." | |