|
| 1 | +name: Block ingestor proxy chain - Build and deploy |
| 2 | + |
| 3 | +on: |
| 4 | + |
| 5 | + workflow_dispatch: # Allows manual workflow trigger |
| 6 | + repository_dispatch: # Allows API workflow trigger |
| 7 | + types: [cdapp-block-ingestor-proxy-chain] |
| 8 | + |
| 9 | + # push: |
| 10 | + # branches: |
| 11 | + # - master # Automatically deploy on commits to master |
| 12 | + # paths-ignore: |
| 13 | + # - '.github/**' |
| 14 | + # - '**.md' |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: cdapp-block-ingestor-proxy-chain |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +# Set global env variables |
| 21 | +env: |
| 22 | + AWS_REGION: eu-west-2 |
| 23 | + ECR_REPOSITORY: ${{ secrets.AWS_ACCOUNT_ID_QA }}.dkr.ecr.eu-west-2.amazonaws.com/cdapp/block-ingestor-proxy-chain |
| 24 | + COMMIT_HASH: ${{ github.event.client_payload.COMMIT_HASH != null && github.event.client_payload.COMMIT_HASH || github.sha }} |
| 25 | + |
| 26 | +jobs: |
| 27 | + |
| 28 | + # Build cdapp block-ingestor and push to AWS ECR |
| 29 | + buildAndPush: |
| 30 | + |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + |
| 35 | + - name: Echo Env Vars through Context |
| 36 | + run: | |
| 37 | + echo "$GITHUB_CONTEXT" |
| 38 | +
|
| 39 | + - name: Configure AWS credentials |
| 40 | + uses: aws-actions/configure-aws-credentials@v2 |
| 41 | + with: |
| 42 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }} |
| 43 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }} |
| 44 | + aws-region: ${{ env.AWS_REGION }} |
| 45 | + |
| 46 | + - name: Login to Amazon ECR |
| 47 | + id: login-ecr |
| 48 | + uses: aws-actions/amazon-ecr-login@v1 |
| 49 | + |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@v2 |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Checkout relevant branch |
| 56 | + run: |
| 57 | + git checkout ${{ github.event.client_payload.COMMIT_HASH != null && github.event.client_payload.COMMIT_HASH || github.sha }} |
| 58 | + |
| 59 | + - name: Set up Docker Buildx |
| 60 | + uses: docker/setup-buildx-action@v2 |
| 61 | + |
| 62 | + - name: Build and push |
| 63 | + uses: docker/build-push-action@v3 |
| 64 | + with: |
| 65 | + context: ${{ github.workspace }} |
| 66 | + file: ./Dockerfile |
| 67 | + push: true |
| 68 | + build-args: | |
| 69 | + BUILD_TARGET=proxy-chain |
| 70 | + tags: | |
| 71 | + ${{ env.ECR_REPOSITORY }}:run-${{ github.run_number }} |
| 72 | + ${{ env.ECR_REPOSITORY }}:${{ env.COMMIT_HASH }} |
| 73 | + |
| 74 | + - uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383 |
| 75 | + if: always() |
| 76 | + with: |
| 77 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 78 | + title: "Build and push cdapp block-ingestor" |
| 79 | + |
| 80 | + # Deploy cdapp block-ingestor to QA environment |
| 81 | + deployQA: |
| 82 | + |
| 83 | + needs: buildAndPush |
| 84 | + |
| 85 | + runs-on: ubuntu-latest |
| 86 | + |
| 87 | + env: |
| 88 | + NAMESPACE: cdapp |
| 89 | + CLUSTER_NAME: qa-cluster |
| 90 | + ENVIRONMENT_TAG: qa |
| 91 | + REPOSITORY_NAME: cdapp/block-ingestor-proxy-chain |
| 92 | + |
| 93 | + steps: |
| 94 | + |
| 95 | + - name: Configure AWS credentials for ECR |
| 96 | + uses: aws-actions/configure-aws-credentials@v2 |
| 97 | + with: |
| 98 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }} |
| 99 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }} |
| 100 | + aws-region: ${{ env.AWS_REGION }} |
| 101 | + |
| 102 | + - name: Login to Amazon ECR |
| 103 | + id: login-ecr |
| 104 | + uses: aws-actions/amazon-ecr-login@v1 |
| 105 | + |
| 106 | + - name: Echo current image and tag new image |
| 107 | + run: | |
| 108 | + echo -e "Getting image info...\n" |
| 109 | +
|
| 110 | + echo -e "###### Current image being used ######\n" |
| 111 | + SHA256=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.ENVIRONMENT_TAG }} --output json | jq '.images[].imageId.imageDigest') |
| 112 | + aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageDigest=$SHA256 --output json | jq '.images[].imageId' |
| 113 | + |
| 114 | + echo -e "\n###### Tagging new image with environment tag ######" |
| 115 | + MANIFEST=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.COMMIT_HASH }} --output json | jq --raw-output --join-output '.images[0].imageManifest') |
| 116 | + aws ecr put-image --repository-name ${{ env.REPOSITORY_NAME }} --image-tag ${{ env.ENVIRONMENT_TAG }} --image-manifest "$MANIFEST" |
| 117 | + |
| 118 | + echo -e "\n###### New image being used ######\n" |
| 119 | + SHA256=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.ENVIRONMENT_TAG }} --output json | jq '.images[].imageId.imageDigest') |
| 120 | + aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageDigest=$SHA256 --output json | jq '.images[].imageId' |
| 121 | + |
| 122 | + - name: Configure AWS credentials for EKS |
| 123 | + uses: aws-actions/configure-aws-credentials@v2 |
| 124 | + with: |
| 125 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }} |
| 126 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }} |
| 127 | + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_QA }}:role/eks-admin |
| 128 | + role-session-name: github-cicd |
| 129 | + role-duration-seconds: 1200 |
| 130 | + aws-region: ${{ env.AWS_REGION }} |
| 131 | + |
| 132 | + - name: Configure AWS EKS |
| 133 | + run: | |
| 134 | + aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.CLUSTER_NAME }} |
| 135 | +
|
| 136 | + - name: Deploy to Kubernetes cluster |
| 137 | + run: | |
| 138 | + kubectl rollout restart deployment/cdapp-block-ingestor-${{ env.ENVIRONMENT_TAG }}-polygon-amoy -n ${{ env.NAMESPACE }} |
| 139 | +
|
| 140 | + - name: Validate Kubernetes deployment |
| 141 | + run: | |
| 142 | + kubectl rollout status deployment/cdapp-block-ingestor-${{ env.ENVIRONMENT_TAG }}-polygon-amoy -n ${{ env.NAMESPACE }} |
| 143 | + |
| 144 | + - uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383 |
| 145 | + if: always() |
| 146 | + with: |
| 147 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 148 | + title: "Deploy cdapp block-ingestor to ${{ env.ENVIRONMENT_TAG }}-polygon-amoy" |
| 149 | + |
| 150 | + # Deploy cdapp block-ingestor to Prod environment |
| 151 | + deployProd: |
| 152 | + |
| 153 | + needs: deployQA |
| 154 | + |
| 155 | + environment: prod |
| 156 | + |
| 157 | + runs-on: ubuntu-latest |
| 158 | + |
| 159 | + env: |
| 160 | + NAMESPACE: cdapp |
| 161 | + CLUSTER_NAME: prod-cluster |
| 162 | + ENVIRONMENT_TAG: prod |
| 163 | + REPOSITORY_NAME: cdapp/block-ingestor-proxy-chain |
| 164 | + |
| 165 | + steps: |
| 166 | + |
| 167 | + - name: Configure AWS credentials for ECR |
| 168 | + uses: aws-actions/configure-aws-credentials@v2 |
| 169 | + with: |
| 170 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }} |
| 171 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }} |
| 172 | + aws-region: ${{ env.AWS_REGION }} |
| 173 | + |
| 174 | + - name: Login to Amazon ECR |
| 175 | + id: login-ecr |
| 176 | + uses: aws-actions/amazon-ecr-login@v1 |
| 177 | + |
| 178 | + - name: Echo current image and tag new image |
| 179 | + run: | |
| 180 | + echo -e "Getting image info...\n" |
| 181 | +
|
| 182 | + echo -e "###### Current image being used ######\n" |
| 183 | + SHA256=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.ENVIRONMENT_TAG }} --output json | jq '.images[].imageId.imageDigest') |
| 184 | + aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageDigest=$SHA256 --output json | jq '.images[].imageId' |
| 185 | + |
| 186 | + echo -e "\n###### Tagging new image with environment tag ######" |
| 187 | + MANIFEST=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.COMMIT_HASH }} --output json | jq --raw-output --join-output '.images[0].imageManifest') |
| 188 | + aws ecr put-image --repository-name ${{ env.REPOSITORY_NAME }} --image-tag ${{ env.ENVIRONMENT_TAG }} --image-manifest "$MANIFEST" |
| 189 | + |
| 190 | + echo -e "\n###### New image being used ######\n" |
| 191 | + SHA256=$(aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageTag=${{ env.ENVIRONMENT_TAG }} --output json | jq '.images[].imageId.imageDigest') |
| 192 | + aws ecr batch-get-image --repository-name ${{ env.REPOSITORY_NAME }} --image-ids imageDigest=$SHA256 --output json | jq '.images[].imageId' |
| 193 | + |
| 194 | + - name: Configure AWS credentials for EKS |
| 195 | + uses: aws-actions/configure-aws-credentials@v2 |
| 196 | + with: |
| 197 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }} |
| 198 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} |
| 199 | + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_PROD }}:role/eks-admin |
| 200 | + role-session-name: github-cicd |
| 201 | + role-duration-seconds: 1200 |
| 202 | + aws-region: ${{ env.AWS_REGION }} |
| 203 | + |
| 204 | + - name: Configure AWS EKS |
| 205 | + run: | |
| 206 | + aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.CLUSTER_NAME }} |
| 207 | +
|
| 208 | + - name: Deploy to Kubernetes cluster |
| 209 | + run: | |
| 210 | + kubectl rollout restart deployment/cdapp-block-ingestor-${{ env.ENVIRONMENT_TAG }}-polygon-mainnet -n ${{ env.NAMESPACE }} |
| 211 | +
|
| 212 | + - name: Validate Kubernetes deployment |
| 213 | + run: | |
| 214 | + kubectl rollout status deployment/cdapp-block-ingestor-${{ env.ENVIRONMENT_TAG }}-polygon-mainnet -n ${{ env.NAMESPACE }} |
| 215 | + |
| 216 | + - uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383 |
| 217 | + if: always() |
| 218 | + with: |
| 219 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 220 | + title: "Deploy cdapp block-ingestor to ${{ env.ENVIRONMENT_TAG }}-polygon-mainnet" |
0 commit comments