|
| 1 | +name: Deploy to Demo and Test |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + - develop |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v1 |
| 14 | + - name: Setup node |
| 15 | + uses: actions/setup-node@v1 |
| 16 | + with: |
| 17 | + node-version: "12.x" |
| 18 | + |
| 19 | + # Build for demo |
| 20 | + - name: Build and publish demo docker image |
| 21 | + if: github.ref == 'refs/heads/master' |
| 22 | + uses: elgohr/Publish-Docker-Github-Action@master |
| 23 | + with: |
| 24 | + name: demo-storefrontcloud-io/vue-storefront-api:${{ github.sha }} |
| 25 | + registry: registry.storefrontcloud.io |
| 26 | + username: ${{ secrets.CLOUD_USERNAME }} |
| 27 | + password: ${{ secrets.CLOUD_PASSWORD }} |
| 28 | + dockerfile: dev/docker/Dockerfile |
| 29 | + buildoptions: "--compress" |
| 30 | + |
| 31 | + # Build for test |
| 32 | + - name: Build and publish test docker image |
| 33 | + if: github.ref == 'refs/heads/develop' |
| 34 | + uses: elgohr/Publish-Docker-Github-Action@master |
| 35 | + with: |
| 36 | + name: test-storefrontcloud-io/vue-storefront-api:${{ github.sha }} |
| 37 | + registry: registry.storefrontcloud.io |
| 38 | + username: ${{ secrets.CLOUD_USERNAME }} |
| 39 | + password: ${{ secrets.CLOUD_PASSWORD }} |
| 40 | + dockerfile: dev/docker/Dockerfile |
| 41 | + buildoptions: "--compress" |
| 42 | + |
| 43 | + deploy-demo: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: build |
| 46 | + steps: |
| 47 | + - uses: chrnorm/deployment-action@releases/v1 |
| 48 | + if: github.ref == 'refs/heads/master' |
| 49 | + name: Create GitHub deployment for demo |
| 50 | + id: deployment |
| 51 | + with: |
| 52 | + token: "${{ github.token }}" |
| 53 | + target_url: https://demo.europe-west1.gcp.storefrontcloud.io/api/ |
| 54 | + environment: production |
| 55 | + initial_status: in_progress |
| 56 | + # Deploy on demo |
| 57 | + - name: Deploy on demo.europe-west1.gcp.storefrontcloud.io |
| 58 | + if: github.ref == 'refs/heads/master' |
| 59 | + run: | |
| 60 | + if curl -s -H 'X-User-Id: ${{ secrets.CLOUD_USERNAME }}' -H 'X-Api-Key: ${{ secrets.CLOUD_PASSWORD }}' -H 'Content-Type: application/json' -X POST -d ' |
| 61 | + { |
| 62 | + "code":"demo", |
| 63 | + "region":"europe-west1.gcp", |
| 64 | + "apiContainerVersion":"${{ github.sha }}" |
| 65 | + }' https://farmer.storefrontcloud.io/instances | grep -q '{"code":200,"result":"Instance updated!"}'; then |
| 66 | + echo "Instance updated" |
| 67 | + else |
| 68 | + echo "Something went wrong during the update process..." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + # Return status |
| 73 | + - name: Update deployment status (success) |
| 74 | + if: success() |
| 75 | + uses: chrnorm/deployment-status@releases/v1 |
| 76 | + with: |
| 77 | + token: "${{ github.token }}" |
| 78 | + target_url: https://demo.europe-west1.gcp.storefrontcloud.io |
| 79 | + state: "success" |
| 80 | + description: Congratulations! The deploy is done. |
| 81 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
| 82 | + |
| 83 | + - name: Update deployment status (failure) |
| 84 | + if: failure() |
| 85 | + uses: chrnorm/deployment-status@releases/v1 |
| 86 | + with: |
| 87 | + token: "${{ github.token }}" |
| 88 | + target_url: https://demo.europe-west1-southeast1.gcp.storefrontcloud.io |
| 89 | + description: Unfortunately, the instance hasn't been updated. |
| 90 | + state: "failure" |
| 91 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
| 92 | + |
| 93 | + deploy-test: |
| 94 | + runs-on: ubuntu-latest |
| 95 | + needs: build |
| 96 | + steps: |
| 97 | + - uses: chrnorm/deployment-action@releases/v1 |
| 98 | + if: github.ref == 'refs/heads/develop' |
| 99 | + name: Create GitHub deployment for test |
| 100 | + id: deployment |
| 101 | + with: |
| 102 | + token: "${{ github.token }}" |
| 103 | + target_url: https://test.europe-west1.gcp.storefrontcloud.io/api/ |
| 104 | + environment: demo |
| 105 | + initial_status: in_progress |
| 106 | + # Deploy on demo |
| 107 | + - name: Deploy on test.europe-west1.gcp.storefrontcloud.io |
| 108 | + if: github.ref == 'refs/heads/develop' |
| 109 | + run: | |
| 110 | + if curl -s -H 'X-User-Id: ${{ secrets.CLOUD_USERNAME }}' -H 'X-Api-Key: ${{ secrets.CLOUD_PASSWORD }}' -H 'Content-Type: application/json' -X POST -d ' |
| 111 | + { |
| 112 | + "code":"test", |
| 113 | + "region":"europe-west1.gcp", |
| 114 | + "apiContainerVersion":"${{ github.sha }}" |
| 115 | + }' https://farmer.storefrontcloud.io/instances | grep -q '{"code":200,"result":"Instance updated!"}'; then |
| 116 | + echo "Instance updated" |
| 117 | + else |
| 118 | + echo "Something went wrong during the update process..." |
| 119 | + exit 1 |
| 120 | + fi |
| 121 | +
|
| 122 | + # Return status |
| 123 | + - name: Update deployment status (success) |
| 124 | + if: success() |
| 125 | + uses: chrnorm/deployment-status@releases/v1 |
| 126 | + with: |
| 127 | + token: "${{ github.token }}" |
| 128 | + target_url: https://test.europe-west1.gcp.storefrontcloud.io |
| 129 | + state: "success" |
| 130 | + description: Congratulations! The deploy is done. |
| 131 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
| 132 | + |
| 133 | + - name: Update deployment status (failure) |
| 134 | + if: failure() |
| 135 | + uses: chrnorm/deployment-status@releases/v1 |
| 136 | + with: |
| 137 | + token: "${{ github.token }}" |
| 138 | + target_url: https://test.europe-west1-southeast1.gcp.storefrontcloud.io |
| 139 | + description: Unfortunately, the instance hasn't been updated. |
| 140 | + state: "failure" |
| 141 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
0 commit comments