diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh new file mode 100755 index 0000000000..1e614ba923 --- /dev/null +++ b/.github/scripts/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -ex + +cp coordinator/.env.example coordinator/.env + +sed -i "s|^\(COORDINATOR_RPC_URL=\).*|\1$1|" coordinator/.env +sed -i "s|^\(COORDINATOR_ADDRESS=\).*|\1$2|" coordinator/.env +sed -i "s|^\(COORDINATOR_ALLOWED_ORIGIN=\).*|\1$3|" coordinator/.env + +aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 490752553772.dkr.ecr.eu-central-1.amazonaws.com + +docker build -t maci-coordinator -f coordinator/apps/Dockerfile . +docker tag maci-coordinator:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/maci-coordinator:latest +docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/maci-coordinator:latest + +exit 0 diff --git a/.github/scripts/deploy.sh b/.github/scripts/deploy.sh new file mode 100755 index 0000000000..3d987b1420 --- /dev/null +++ b/.github/scripts/deploy.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex + +tasks="maci-coordinator" +for task in $tasks; do + maci_coordinator_revision=$(aws ecs describe-task-definition --task-definition $task --query "taskDefinition.revision") + aws ecs update-service --cluster maci-coordinator --service $task --force-new-deployment --task-definition $task:$maci_coordinator_revision +done + +for loop in {1..3}; do + [ "$loop" -eq 3 ] && exit 1 + aws ecs wait services-stable --cluster maci-coordinator --services $tasks && break || continue +done diff --git a/.github/workflows/coordinator-deploy.yml b/.github/workflows/coordinator-deploy.yml new file mode 100644 index 0000000000..33a8ec3a2b --- /dev/null +++ b/.github/workflows/coordinator-deploy.yml @@ -0,0 +1,37 @@ +name: CoordinatorDeploy +on: + push: + branches: + - dev + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + runs-on: ubuntu-22.04 + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::490752553772:role/maci-coordinator-ecs-deploy-slc + role-duration-seconds: 2700 + aws-region: eu-central-1 + + - name: Build and Push images to ECR + run: | + .github/scripts/build.sh ${{ secrets.COORDINATOR_RPC_URL }} ${{ secrets.COORDINATOR_ADDRESS }} ${{ secrets.COORDINATOR_ALLOWED_ORIGIN }} + + - name: Create Deployment + run: | + .github/scripts/deploy.sh diff --git a/circuits/package.json b/circuits/package.json index 5bffd903ef..412a56a42c 100644 --- a/circuits/package.json +++ b/circuits/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@zk-kit/circuits": "^0.4.0", - "circomkit": "^0.1.0", + "circomkit": "^0.2.1", "circomlib": "^2.0.5", "maci-core": "1.2.2", "maci-crypto": "1.2.2", diff --git a/circuits/ts/__tests__/MessageValidator.test.ts b/circuits/ts/__tests__/MessageValidator.test.ts index f56dd0d04e..97697ff3a2 100644 --- a/circuits/ts/__tests__/MessageValidator.test.ts +++ b/circuits/ts/__tests__/MessageValidator.test.ts @@ -1,6 +1,5 @@ import { expect } from "chai"; import { type WitnessTester } from "circomkit"; -import { SignalValueType } from "circomkit/dist/types/circuit"; import { genRandomSalt } from "maci-crypto"; import { PCommand, Keypair } from "maci-domainobjs"; @@ -58,7 +57,7 @@ describe("MessageValidator circuit", function test() { const signature = command.sign(privKey); circuitInputs = { - stateTreeIndex: 0n as SignalValueType, + stateTreeIndex: 0n, numSignUps: 1n, voteOptionIndex: 0n, maxVoteOptions: 1n, @@ -204,7 +203,7 @@ describe("MessageValidator circuit", function test() { const signature = command.sign(privKey); circuitInputs = { - stateTreeIndex: 0n as SignalValueType, + stateTreeIndex: 0n, numSignUps: 1n, voteOptionIndex: 0n, maxVoteOptions: 1n, diff --git a/circuits/ts/__tests__/utils/types.ts b/circuits/ts/__tests__/utils/types.ts index bacbeb6a55..934108a0e9 100644 --- a/circuits/ts/__tests__/utils/types.ts +++ b/circuits/ts/__tests__/utils/types.ts @@ -1,4 +1,8 @@ -import { type SignalValueType } from "circomkit/dist/types/circuit"; +/** An integer value is a numerical string, a number, or a bigint. */ +export type IntegerValueType = `${number}` | number | bigint; + +/** A signal value is a number, or an array of numbers (recursively). */ +export type SignalValueType = IntegerValueType | SignalValueType[]; /** * Circuit inputs for testing the MessageValidator circuit diff --git a/coordinator/apps/Dockerfile b/coordinator/apps/Dockerfile new file mode 100644 index 0000000000..3144d8e39a --- /dev/null +++ b/coordinator/apps/Dockerfile @@ -0,0 +1,33 @@ +# Copy source code and build the project +FROM node:20-alpine as builder + +WORKDIR /builder + +COPY . . + +RUN npm i -g pnpm@8 +RUN pnpm install --frozen-lockfile --prefer-offline +RUN pnpm run build + +# Create image by copying build artifacts +FROM node:20-alpine as runner +RUN npm i -g pnpm@8 + +RUN mkdir -p ~/rapidsnark/build; \ + wget -qO ~/rapidsnark/build/prover https://maci-devops-zkeys.s3.ap-northeast-2.amazonaws.com/rapidsnark-linux-amd64-1c137; \ + chmod +x ~/rapidsnark/build/prover +RUN wget -qO ~/circom https://github.com/iden3/circom/releases/download/v2.1.6/circom-linux-amd64; \ + chmod +x ~/circom; \ + mv ~/circom /bin + +USER node +ARG PORT=3000 + +WORKDIR ./maci +COPY --chown=node:node --from=builder /builder/ ./ +WORKDIR /maci/coordinator +RUN pnpm run download-zkeys:test +RUN pnpm run generate-keypair + +EXPOSE ${PORT} +CMD ["node", "build/ts/main.js"] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fef456e2c..bd1f444914 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,8 +96,8 @@ importers: specifier: ^0.4.0 version: 0.4.0 circomkit: - specifier: ^0.1.0 - version: 0.1.0 + specifier: ^0.2.1 + version: 0.2.1(@types/snarkjs@0.7.8)(snarkjs@0.7.4) circomlib: specifier: ^2.0.5 version: 2.0.5 @@ -6641,7 +6641,6 @@ packages: /@types/snarkjs@0.7.8: resolution: {integrity: sha512-x37Jsv1vx6I6RMJdfvYEmDUOLYgzYMecwlk13gniDOcN20xLVe9hy9DlQxWeCPirqpDY/jwugQSqCi2RxehU3g==} - dev: true /@types/sockjs@0.3.36: resolution: {integrity: sha512-MK9V6NzAS1+Ud7JV9lJLFqW85VbC9dq3LmwZCuBe4wBDgKC0Kj/jd8Xl+nSviU+Qc3+m7umHHyHg//2KSa0a0Q==} @@ -8282,13 +8281,17 @@ packages: util: 0.12.5 dev: false - /circomkit@0.1.0: - resolution: {integrity: sha512-Mnc9IuOoaN7FitfURvbg2Q5j62S7/zQl6l18u5dcIhZg3Ot9MZYLiGIotCaF1Gfp/vAUKnvO2lnS3Xc1TdTISA==} + /circomkit@0.2.1(@types/snarkjs@0.7.8)(snarkjs@0.7.4): + resolution: {integrity: sha512-7O8QsOLUq2QvwGMimvWxwdg7OgV33OT7ZBND+81dv3JrVp8ove93yV16jF3TW6XBncSY92/Aka8F4CAi/H9VQw==} engines: {node: '>=12.0.0'} hasBin: true + peerDependencies: + '@types/snarkjs': ^0.7.x + snarkjs: ^0.7.x dependencies: - chai: 4.4.1 + '@types/snarkjs': 0.7.8 circom_tester: 0.0.19 + commander: 12.1.0 loglevel: 1.9.1 snarkjs: 0.7.4 dev: false