Repository navigation
trenc is deploying to DEV... #172
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 DEV | |
| run-name: ${{ github.actor }} is deploying to DEV... | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| HOST: ${{ vars.DEV_HOST }} | |
| PORT: ${{ vars.DEV_PORT }} | |
| REMOTE_PATH: ${{ vars.DEV_REMOTE_PATH }} | |
| REMOTE_FOLDER: ${{ vars.DEV_REMOTE_FOLDER }} | |
| LOCAL_PATH: src | |
| SSH_KEY_PASS: ${{ secrets.DEV_SSH_KEY_PASS }} | |
| SSH_PRIVATE_KEY: ${{ secrets.DEV_SSH_PRIVATE_KEY }} | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Setup environment vars | |
| run: | | |
| echo "now=$(date +%s)" >> $GITHUB_ENV | |
| echo "remote_folder=$REMOTE_FOLDER" >> $GITHUB_ENV | |
| echo "remote_path=$REMOTE_PATH" >> $GITHUB_ENV | |
| echo "local_path=$LOCAL_PATH" >> $GITHUB_ENV | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up WireGuard Connection | |
| uses: niklaskeerl/easy-wireguard-action@v2 | |
| with: | |
| WG_CONFIG_FILE: ${{ secrets.WG_CONFIG }} | |
| - name: Wait for a VPN connection | |
| timeout-minutes: 1 | |
| run: until timeout 1 bash -c "</dev/tcp/$HOST/$PORT" 2>/dev/null; do sleep 2; done | |
| - name: Prepare files | |
| env: | |
| SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
| SSH_KEY_PASS: ${{ secrets.DEV_SSH_KEY_PASS }} | |
| SSH_PRIVATE_KEY: ${{ secrets.DEV_SSH_PRIVATE_KEY }} | |
| run: | | |
| ssh-agent -a $SSH_AUTH_SOCK > /dev/null | |
| echo 'echo $SSH_KEY_PASS' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass | |
| echo "$SSH_PRIVATE_KEY" | tr -d '\r' | DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add - > /dev/null | |
| echo "deployfile=deploy.${{ env.now }}.tar.gz" >> $GITHUB_ENV | |
| echo "${{ secrets.DEV_ENV }}" > ${{ env.local_path }}/.env | |
| mv "${{ env.local_path }}" "${{ env.remote_folder }}.${{ env.now }}" | |
| - name: Upload files | |
| env: | |
| SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
| run: | | |
| tar -czf "${{ env.deployfile }}" "${{ env.remote_folder }}.${{ env.now }}" | |
| scp -o StrictHostKeyChecking=no -P "$PORT" "${{ env.deployfile }}" "${{ secrets.DEV_SSH_USER }}@$HOST:${{ env.remote_path}}" | |
| - name: Move and extract files | |
| env: | |
| SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
| run: | | |
| ssh -tt -o StrictHostKeyChecking=no -p "$PORT" "${{ secrets.DEV_SSH_USER }}@$HOST" <<EOF | |
| set -e | |
| cd ${{ env.remote_path }} | |
| tar -xf ${{ env.deployfile }} | |
| chcon -t httpd_user_rw_content_t -R ${{ env.remote_folder}}.${{ env.now }} | |
| cd ${{ env.remote_folder}}.${{ env.now }} | |
| php81 composer.phar install --optimize-autoloader --no-dev | |
| php81 artisan optimize:clear | |
| php81 artisan config:cache | |
| php81 artisan route:cache | |
| php81 artisan view:cache | |
| php81 artisan migrate --force --no-interaction | |
| cd ${{ env.remote_path }} | |
| unlink ${{ env.remote_folder }} | |
| ln -s ${{ env.remote_folder }}.${{ env.now }} ${{ env.remote_folder }} | |
| rm ${{ env.deployfile }} | |
| exit | |
| EOF | |
| - name: Kill VPN connection | |
| if: always() | |
| run: | | |
| sudo wg-quick down ./wg0.conf |