From 2c67885d2d8519149547c1bd168e24ed0233b346 Mon Sep 17 00:00:00 2001 From: stranger80 Date: Mon, 27 Nov 2023 17:23:08 +0100 Subject: [PATCH] Devnet CI/CD workflows --- .github/workflows/devnet-deploy.yml | 30 ------- .github/workflows/devnet-prod-deploy.yml | 102 +++++++++++++++++++++++ 2 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/devnet-prod-deploy.yml diff --git a/.github/workflows/devnet-deploy.yml b/.github/workflows/devnet-deploy.yml index c7f3a86c..f259ee17 100644 --- a/.github/workflows/devnet-deploy.yml +++ b/.github/workflows/devnet-deploy.yml @@ -100,33 +100,3 @@ jobs: service: ${{ env.DEV_SERVICE_NAME }} cluster: ${{ env.DEV_CLUSTER }} wait-for-service-stability: true - Deploy_Prod: - runs-on: ubuntu-latest - needs: Build - steps: - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-region: us-east-2 - role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-ZKSync-Production - role-session-name: GHZKSync - - - name: Download task definition - run: | - aws ecs describe-task-definition --task-definition zksync-remix-production-devnet --query taskDefinition > task-definition.json - - - name: Update the task definition to use the image from Docker Hub - id: task-def - uses: aws-actions/amazon-ecs-render-task-definition@v1 - with: - task-definition: task-definition.json - container-name: "devnet" - image: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:devnet-${{ needs.Build.outputs.image-version }} - - name: Deploy Amazon ECS task definition - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 - with: - task-definition: ${{ steps.task-def.outputs.task-definition }} - service: ${{ env.PROD_SERVICE_NAME }} - cluster: ${{ env.PROD_CLUSTER }} - wait-for-service-stability: true diff --git a/.github/workflows/devnet-prod-deploy.yml b/.github/workflows/devnet-prod-deploy.yml new file mode 100644 index 00000000..e1b5b08b --- /dev/null +++ b/.github/workflows/devnet-prod-deploy.yml @@ -0,0 +1,102 @@ +name: (prod) Manual devnet deploy +on: + workflow_dispatch: + inputs: + version: + description: 'Devnet version tag' + required: true + type: string + default: 'v0.1.0-alpha.10' + +permissions: + id-token: write + contents: read + +env: + REGISTRY: "599564732950.dkr.ecr.us-east-2.amazonaws.com" + REPOSITORY: "zksync-remix-plugin" + DEV_CLUSTER: "zksync-remix-plugin-ecs-cluster" + DEV_SERVICE_NAME: "devnet-development-svc" + PROD_CLUSTER: "zksync-remix-plugin-production-ecs-cluster" + PROD_SERVICE_NAME: "devnet-production-svc" +jobs: + + Build: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Determine version numbers + id: determine-version + uses: paulhatch/semantic-version@v5.2.1 + with: + tag_prefix: "v" + major_pattern: "(MAJOR)" + major_regexp_flags: "" + minor_pattern: "(MINOR)" + minor_regexp_flags: "" + version_format: "${major}.${minor}.${patch}-dev${increment}" + bump_each_commit: false + bump_each_commit_patch_pattern: "" + search_commit_body: false + user_format_type: "csv" + enable_prerelease_mode: true + debug: false + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-east-2 + role-to-assume: arn:aws:iam::599564732950:role/Aws-GH-Action-Assume-Role-ZKSync + role-session-name: GHZKSync + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + with: + mask-password: 'true' + + - name: Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: ${{ env.REPOSITORY }} + IMAGE_TAG: ${{ steps.determine-version.outputs.version }} # ${{ github.run_number }} + LATEST_RELEASE: ${{ inputs.version }} + run: | + docker build --build-arg LATEST_RELEASE=$LATEST_RELEASE -t $REGISTRY/$REPOSITORY:devnet-$IMAGE_TAG -f ./DockerfileDevnet . + docker push $REGISTRY/$REPOSITORY:devnet-$IMAGE_TAG + outputs: + image-version: ${{ steps.determine-version.outputs.version }} + Deploy_Prod: + runs-on: ubuntu-latest + needs: Build + steps: + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-east-2 + role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-ZKSync-Production + role-session-name: GHZKSync + + - name: Download task definition + run: | + aws ecs describe-task-definition --task-definition zksync-remix-production-devnet --query taskDefinition > task-definition.json + + - name: Update the task definition to use the image from Docker Hub + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: task-definition.json + container-name: "devnet" + image: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:devnet-${{ needs.Build.outputs.image-version }} + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.PROD_SERVICE_NAME }} + cluster: ${{ env.PROD_CLUSTER }} + wait-for-service-stability: true