|
| 1 | +name: Staging |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - staging |
| 7 | + |
| 8 | +jobs: |
| 9 | + stage: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: checkout |
| 13 | + uses: actions/checkout@master |
| 14 | + |
| 15 | + - name: build_image |
| 16 | + id: build_image |
| 17 | + uses: elgohr/Publish-Docker-Github-Action@master |
| 18 | + with: |
| 19 | + name: codebuddies/backend/cb-backend |
| 20 | + username: ${{ github.actor }} |
| 21 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + registry: docker.pkg.github.com |
| 23 | + dockerfile: Dockerfile |
| 24 | + workdir: project |
| 25 | + tag_names: true |
| 26 | + |
| 27 | + - name: start deployment |
| 28 | + uses: bobheadxi/deployments@master |
| 29 | + id: deployment |
| 30 | + with: |
| 31 | + step: start |
| 32 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + env: staging |
| 34 | + transient: true |
| 35 | + desc: Setting up staging deployment for ${{ steps.build_image.outputs.tag }} |
| 36 | + |
| 37 | + - name: copy files |
| 38 | + uses: appleboy/scp-action@master |
| 39 | + with: |
| 40 | + host: ${{ secrets.DO_STAGING_HOST }} |
| 41 | + key: ${{ secrets.DO_SSH_KEY }} |
| 42 | + passphrase: ${{ secrets.DO_SSH_PASSPHRASE }} |
| 43 | + port: ${{ secrets.DO_STAGING_SSH_PORT }} |
| 44 | + username: ${{ secrets.DO_SSH_USER }} |
| 45 | + source: "docker-compose-proxy.yaml,docker-compose-staging.yaml" |
| 46 | + target: "./" |
| 47 | + |
| 48 | + - name: run deployment |
| 49 | + uses: appleboy/ssh-action@master |
| 50 | + env: |
| 51 | + DO_STAGING_DB_URL: ${{ secrets.DO_STAGING_DB_URL }} |
| 52 | + CB_IMAGE_TAG: ${{ steps.build_image.outputs.tag }} |
| 53 | + GITHUB_ACTOR: $GITHUB_ACTOR |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + DJANGO_SECRET_KEY: ${{ secrets.STAGING_DJANGO_SECRET_KEY }} |
| 56 | + DJANGO_ALLOWED_HOSTS: "${{ secrets.STAGING_ALLOWED_HOSTS }}" |
| 57 | + with: |
| 58 | + host: ${{ secrets.DO_STAGING_HOST }} |
| 59 | + key: ${{ secrets.DO_SSH_KEY }} |
| 60 | + passphrase: ${{ secrets.DO_SSH_PASSPHRASE }} |
| 61 | + port: ${{ secrets.DO_STAGING_SSH_PORT }} |
| 62 | + username: ${{ secrets.DO_SSH_USER }} |
| 63 | + script_stop: true |
| 64 | + debug: true |
| 65 | + envs: DO_STAGING_DB_URL,CB_IMAGE_TAG,GITHUB_ACTOR,GITHUB_TOKEN,DJANGO_SECRET_KEY,DJANGO_ALLOWED_HOSTS |
| 66 | + script: | |
| 67 | + export DB_URL=$DO_STAGING_DB_URL |
| 68 | + export CB_IMAGE_TAG=$CB_IMAGE_TAG |
| 69 | + export DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY |
| 70 | + export DJANGO_ALLOWED_HOSTS=$DJANGO_ALLOWED_HOSTS |
| 71 | + docker login docker.pkg.github.com -u $GITHUB_ACTOR -p $GITHUB_TOKEN |
| 72 | + docker-compose --project-name=-stage -f docker-compose-staging.yaml rm -f |
| 73 | + docker-compose --project-name=-stage -f docker-compose-staging.yaml pull |
| 74 | + docker-compose --project-name=-stage -f docker-compose-staging.yaml up -d |
| 75 | + - name: finish deployment |
| 76 | + uses: bobheadxi/deployments@master |
| 77 | + if: always() |
| 78 | + with: |
| 79 | + step: finish |
| 80 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + status: ${{ job.status }} |
| 82 | + env: ${{ steps.deployment.outputs.env }} |
| 83 | + env_url: https://${{ secrets.DO_STAGING_HOST }} |
| 84 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
0 commit comments