Destroy Stack #5
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: Destroy Stack | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| confirm: | |
| description: 'Type "destroy" to confirm the complete removal of the project from the server.' | |
| required: true | |
| type: string | |
| jobs: | |
| destroy: | |
| name: Destroy Project on Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check confirmation | |
| run: | | |
| if [[ "${{ inputs.confirm }}" != "destroy" ]]; then | |
| echo "Confirmation failed. Aborting." | |
| exit 1 | |
| fi | |
| - name: Setup SSH | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| SSH_HOST: ${{ secrets.SSH_HOST }} | |
| SSH_PORT: ${{ secrets.SSH_PORT }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -p $SSH_PORT -H $SSH_HOST >> ~/.ssh/known_hosts | |
| - name: Destroy project on server | |
| env: | |
| SSH_USER: ${{ secrets.SSH_USER }} | |
| SSH_HOST: ${{ secrets.SSH_HOST }} | |
| SSH_PORT: ${{ secrets.SSH_PORT }} | |
| PROJECT_PATH: ${{ secrets.PROJECT_PATH }} | |
| run: | | |
| ssh $SSH_USER@$SSH_HOST -p $SSH_PORT " | |
| echo 'Stopping containers and removing volumes...' | |
| cd $PROJECT_PATH && docker compose down -v --rmi all --remove-orphans | |
| echo 'Removing project directory...' | |
| cd .. && rm -rf $PROJECT_PATH | |
| echo 'Project destroyed.' | |
| " |