deploy.yml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Deploy short URL service to a server
  2. #
  3. # nginx-proxy should be deployed first: https://github.com/recipeer/nginx-proxy
  4. name: Deploy
  5. on:
  6. workflow_dispatch:
  7. inputs:
  8. environment:
  9. description: 'Environment'
  10. required: true
  11. type: environment
  12. tag:
  13. description: 'Image tag'
  14. required: true
  15. default: develop
  16. env:
  17. SERVICE_IMAGE: ghcr.io/recipeer/short-url-service:${{ inputs.tag }}
  18. TARGET_START_SH: /tmp/short-url-service.start-${{ github.run_number }}.sh
  19. jobs:
  20. deploy:
  21. name: Deploy
  22. runs-on: ubuntu-latest
  23. environment: ${{ inputs.environment }}
  24. steps:
  25. - name: Checkout repository
  26. uses: actions/checkout@v4
  27. - name: Prepare id_rsa
  28. run: echo "${{ secrets.DEPLOY_KEY }}" > id_rsa && chmod 600 id_rsa
  29. - name: Prepare deployment script
  30. run: |
  31. export CSV="${{ vars.CSV }}"
  32. export NETWORK=${{ vars.NETWORK }}
  33. export SERVICE_CONTAINER=${{ vars.SERVICE_CONTAINER }}
  34. export SERVICE_HOST=${{ vars.SERVICE_HOST }}
  35. export SERVICE_IMAGE=${{ env.SERVICE_IMAGE }}
  36. export SERVICE_NETWORK_ACCESS=${{ vars.SERVICE_NETWORK_ACCESS }}
  37. envsubst < .deploy/start.sh.template | sed 's/£/$/g' > .deploy/start.sh
  38. - name: Import target SSH public key
  39. run: |
  40. TARGET=$(echo "${{ vars.SSH_TARGET }}" | awk -F@ '{ print $2 }')
  41. mkdir -p ~/.ssh && ssh-keyscan ${TARGET} >> ~/.ssh/known_hosts
  42. - name: Copy deployment script to server
  43. run: scp -vi id_rsa .deploy/start.sh ${{ vars.SSH_TARGET }}:${{ env.TARGET_START_SH }}
  44. - name: Run deployment script
  45. run: ssh -i id_rsa ${{ vars.SSH_TARGET }} bash ${{ env.TARGET_START_SH }}
  46. - name: Cleanup deployment script
  47. run: ssh -i id_rsa ${{ vars.SSH_TARGET }} rm ${{ env.TARGET_START_SH }}
  48. # https://github.com/recipeer/docs/blob/develop/workflows/discord-notifications.md
  49. notify:
  50. name: Discord notification
  51. uses: recipeer/docs/.github/workflows/discord.yml@develop
  52. needs: deploy
  53. secrets: inherit
  54. if: ${{ always() }}
  55. with:
  56. repository: ${{ github.repository }}
  57. result: ${{ needs.deploy.result }}
  58. run_id: ${{ github.run_id }}
  59. run_number: ${{ github.run_number }}
  60. workflow: ${{ github.workflow }}