Deploy 4e40ae1e37a7dd858f099cd72f73bcaa7fa42768 #27
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 | |
| run-name: Deploy ${{github.sha}} | |
| on: | |
| workflow_run: | |
| workflows: [Lint] | |
| branches: [main] | |
| types: [completed] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Login to Docker Hub | |
| run: echo $DOCKER_TOKEN | docker login -u coder80 --password-stdin | |
| env: | |
| DOCKER_TOKEN: ${{secrets.DOCKER_TOKEN}} | |
| - name: Build container | |
| run: docker build -t coder80/usmile:latest . | |
| - name: Push to Docker Hub | |
| run: docker push coder80/usmile:latest | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/.ssh/key | |
| sudo chmod 600 ~/.ssh/key | |
| ssh-keyscan -p $SSH_PORT -H $SSH_HOST > ~/.ssh/known_hosts | |
| env: | |
| SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} | |
| SSH_HOST: ${{secrets.SSH_HOST}} | |
| SSH_PORT: ${{secrets.SSH_PORT}} | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Upload compose file | |
| run: | | |
| rsync -e "ssh -p $SSH_PORT -i ~/.ssh/key" compose.yml $SSH_USER@$SSH_HOST:/home/$SSH_USER/projects/usmile/compose.yml | |
| env: | |
| SSH_HOST: ${{secrets.SSH_HOST}} | |
| SSH_USER: ${{secrets.SSH_USER}} | |
| SSH_PORT: ${{secrets.SSH_PORT}} | |
| - name: Connnect and deploy | |
| run: | | |
| ssh -i ~/.ssh/key -p $SSH_PORT $SSH_USER@$SSH_HOST " | |
| cd /home/$SSH_USER/projects/usmile | |
| docker compose --profile prod pull | |
| docker compose --profile prod up -d | |
| docker system prune -f" | |
| env: | |
| SSH_HOST: ${{secrets.SSH_HOST}} | |
| SSH_USER: ${{secrets.SSH_USER}} | |
| SSH_PORT: ${{secrets.SSH_PORT}} |