Deploy 4e40c0f6d54dfe088c14ccbff5fe05873bae7079 #25
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 -H $SSH_HOST > ~/.ssh/known_hosts | |
| env: | |
| SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} | |
| SSH_HOST: ${{secrets.SSH_HOST}} | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Upload compose file | |
| run: | | |
| rsync -e "ssh -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}} | |
| - name: Connnect and deploy | |
| run: | | |
| ssh -i ~/.ssh/key $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}} |