|
| 1 | +name: Deploy to Amazon ECS |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v1 |
| 16 | + |
| 17 | + - name: Configure AWS credentials |
| 18 | + uses: aws-actions/configure-aws-credentials@v1 |
| 19 | + with: |
| 20 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 21 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 22 | + aws-region: eu-central-1 |
| 23 | + |
| 24 | + - name: Login to Amazon ECR |
| 25 | + id: login-ecr |
| 26 | + uses: aws-actions/amazon-ecr-login@v1 |
| 27 | + |
| 28 | + - name: Build, tag, and push image to Amazon ECR |
| 29 | + id: build-image |
| 30 | + env: |
| 31 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 32 | + ECR_REPOSITORY: kilt/prototype-chain |
| 33 | + CACHE_IMAGE_TAG: latest-develop |
| 34 | + CACHE_IMAGE_BUILDER_TAG: latest-develop-builder |
| 35 | + run: | |
| 36 | + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_BUILDER_TAG || true |
| 37 | + docker build \ |
| 38 | + --target builder \ |
| 39 | + --cache-from $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_BUILDER_TAG \ |
| 40 | + -t $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_BUILDER_TAG \ |
| 41 | + . |
| 42 | + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_TAG || true |
| 43 | + docker build \ |
| 44 | + --cache-from $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_BUILDER_TAG \ |
| 45 | + --cache-from $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_TAG \ |
| 46 | + -t $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_TAG \ |
| 47 | + . |
| 48 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_BUILDER_TAG |
| 49 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_TAG |
| 50 | + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$CACHE_IMAGE_TAG" |
| 51 | +
|
| 52 | + - name: (Alice) Fill in the new image ID in the Amazon ECS task definition |
| 53 | + id: task-def-alice |
| 54 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 55 | + with: |
| 56 | + task-definition: task-definition-alice.json |
| 57 | + container-name: devnet-node |
| 58 | + image: ${{ steps.build-image.outputs.image }} |
| 59 | + |
| 60 | + - name: (Alice) Deploy Amazon ECS task definition |
| 61 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 62 | + with: |
| 63 | + task-definition: ${{ steps.task-def-alice.outputs.task-definition }} |
| 64 | + service: bootnode-alice |
| 65 | + cluster: kilt-devnet |
| 66 | + wait-for-service-stability: true |
| 67 | + |
| 68 | + - name: (Bob) Fill in the new image ID in the Amazon ECS task definition |
| 69 | + id: task-def-bob |
| 70 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 71 | + with: |
| 72 | + task-definition: task-definition-bob.json |
| 73 | + container-name: devnet-node |
| 74 | + image: ${{ steps.build-image.outputs.image }} |
| 75 | + |
| 76 | + - name: (Bob) Deploy Amazon ECS task definition |
| 77 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 78 | + with: |
| 79 | + task-definition: ${{ steps.task-def-bob.outputs.task-definition }} |
| 80 | + service: bootnode-bob |
| 81 | + cluster: kilt-devnet |
| 82 | + wait-for-service-stability: true |
| 83 | + |
| 84 | + - name: (Charlie) Fill in the new image ID in the Amazon ECS task definition |
| 85 | + id: task-def-charlie |
| 86 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 87 | + with: |
| 88 | + task-definition: task-definition-charlie.json |
| 89 | + container-name: devnet-charlie |
| 90 | + image: ${{ steps.build-image.outputs.image }} |
| 91 | + |
| 92 | + - name: (Charlie) Deploy Amazon ECS task definition |
| 93 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 94 | + with: |
| 95 | + task-definition: ${{ steps.task-def-charlie.outputs.task-definition }} |
| 96 | + service: bootnode-charlie |
| 97 | + cluster: kilt-devnet |
| 98 | + wait-for-service-stability: true |
| 99 | + |
| 100 | + - name: (Full) Fill in the new image ID in the Amazon ECS task definition |
| 101 | + id: task-def-full |
| 102 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 103 | + with: |
| 104 | + task-definition: task-definition-full.json |
| 105 | + container-name: devnet-node |
| 106 | + image: ${{ steps.build-image.outputs.image }} |
| 107 | + |
| 108 | + - name: (Full) Deploy Amazon ECS task definition |
| 109 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 110 | + with: |
| 111 | + task-definition: ${{ steps.task-def-full.outputs.task-definition }} |
| 112 | + service: full-nodes |
| 113 | + cluster: kilt-devnet |
| 114 | + wait-for-service-stability: true |
| 115 | + |
| 116 | + - name: Purge data in demo services |
| 117 | + env: |
| 118 | + SERVICES_SECRET: ${{ secrets.SERVICES_SECRET }} |
| 119 | + run: | |
| 120 | + curl -X DELETE -H "Authorization: ${SERVICES_SECRET}" https://services.devnet.kilt.io/ctype |
| 121 | + curl -X DELETE -H "Authorization: ${SERVICES_SECRET}" https://services.devnet.kilt.io/messaging |
| 122 | + curl -X DELETE -H "Authorization: ${SERVICES_SECRET}" https://services.devnet.kilt.io/contacts |
0 commit comments