diff --git a/.github/workflows/integration-tests-api.yml b/.github/workflows/integration-tests-api.yml index 43ed80a7df..e8d80ae579 100644 --- a/.github/workflows/integration-tests-api.yml +++ b/.github/workflows/integration-tests-api.yml @@ -3,13 +3,51 @@ name: Integration test - API on: pull_request jobs: - runTests: + build-docker-images: + name: Build docker images with cache + strategy: + matrix: + include: + - image: matterlabs/block-explorer-app:pr + dockerfile: ./packages/app/Dockerfile + name: docker-block-explorer-app + - image: matterlabs/block-explorer-worker:pr + dockerfile: ./packages/worker/Dockerfile + name: docker-block-explorer-worker + - image: matterlabs/block-explorer-data-fetcher:pr + dockerfile: ./packages/data-fetcher/Dockerfile + name: docker-block-explorer-data-fetcher + - image: matterlabs/block-explorer-api:pr + dockerfile: ./packages/api/Dockerfile + name: docker-block-explorer-api + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push block-explorer-app + uses: docker/build-push-action@v5 + with: + context: . + file: ${{ matrix.dockerfile }} + tags: ${{ matrix.image }} + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=docker,dest=/tmp/${{ matrix.name }}.tar + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: {{ matrix.name }} + path: /tmp/{{ matrix.name }}.tar + + run-tests: timeout-minutes: 30 runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - checks: write + needs: build-docker-images strategy: matrix: node-version: ['lts/*'] # 18.17.1 or lts/* @@ -25,42 +63,38 @@ jobs: # - transactions.test.ts name: 'API test set: ${{ matrix.test-pattern}} / Node: ${{ matrix.node-version}}' steps: - - name: Checkout with Submodule - uses: actions/checkout@v3 - with: - fetch-depth: 0 + - name: Checkout repo + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: npm - - name: Log in to Docker Hub - uses: docker/login-action@v2 + - name: Download prebuilt docker images + uses: actions/download-artifact@v4 with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - run: docker-compose pull + pattern: docker-* + path: /tmp - - uses: satackey/action-docker-layer-caching@v0.0.11 - - - name: Start docker containers + - name: Load image run: | - docker-compose -f "docker-compose.yaml" up -d --build + docker load --input /tmp/*.tar + docker image ls -a - - name: API tests run (parallel) - working-directory: packages/integration-tests - run: | - npm ci --no-audit - npx playwright install --with-deps chromium - - - name: API tests run (parallel) - working-directory: packages/integration-tests - run: | - npx jest - - name: Stop containers - if: always() - run: | - docker-compose -f "docker-compose.yaml" down +# - uses: isbang/compose-action@v1.5.1 +# with: +# compose-file: "./docker/docker-compose-prebuilt.yaml" +# down-flags: "--volumes" +# +# - name: API tests run (parallel) +# working-directory: packages/integration-tests +# run: | +# npm ci --no-audit +# npx playwright install --with-deps chromium +# +# - name: API tests run (parallel) +# working-directory: packages/integration-tests +# run: | +# npx jest --verbose --testPathPattern=${{ matrix.test-pattern }} diff --git a/docker-compose-prebuilt.yaml b/docker-compose-prebuilt.yaml new file mode 100644 index 0000000000..5284371a98 --- /dev/null +++ b/docker-compose-prebuilt.yaml @@ -0,0 +1,115 @@ +services: + app: + image: matterlabs/block-explorer-app:pr + ports: + - '3010:3010' + depends_on: + - api + restart: unless-stopped + + worker: + image: matterlabs/block-explorer-worker:pr + environment: + - PORT=3001 + - LOG_LEVEL=verbose + - DATABASE_HOST=postgres + - DATABASE_USER=postgres + - DATABASE_PASSWORD=postgres + - DATABASE_NAME=block-explorer + - BLOCKCHAIN_RPC_URL=http://zksync:3050 + - DATA_FETCHER_URL=http://data-fetcher:3040 + - BATCHES_PROCESSING_POLLING_INTERVAL=1000 + ports: + - '3001:3001' + depends_on: + zksync: + condition: service_healthy + restart: unless-stopped + + data-fetcher: + image: matterlabs/block-explorer-data-fetcher:pr + environment: + - PORT=3040 + - LOG_LEVEL=verbose + - BLOCKCHAIN_RPC_URL=http://zksync:3050 + ports: + - '3040:3040' + depends_on: + zksync: + condition: service_healthy + restart: unless-stopped + + api: + image: matterlabs/block-explorer-api:pr + environment: + - PORT=3020 + - METRICS_PORT=3005 + - LOG_LEVEL=verbose + - DATABASE_URL=postgres://postgres:postgres@postgres:5432/block-explorer + ports: + - '3020:3020' + - '3005:3005' + depends_on: + - worker + restart: unless-stopped + + postgres: + image: "postgres:14" + logging: + driver: none + volumes: + - postgres:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U postgres" ] + interval: 5s + timeout: 5s + retries: 5 + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=block-explorer + + geth: + image: "matterlabs/geth:latest" + logging: + driver: none + ports: + - "8545:8545" + - "8546:8546" + volumes: + - geth:/var/lib/geth/data + + zksync: + stdin_open: true + tty: true + image: matterlabs/local-node:latest2.0 + depends_on: + postgres: + condition: service_healthy + geth: + condition: service_started + ports: + - "3050:3050" # JSON RPC HTTP port + - "3051:3051" # JSON RPC WS port + volumes: + # Configs folder bind + - zksync-config:/etc/env/ + # Storage folder bind + - zksync-data:/var/lib/zksync/data + environment: + - DATABASE_URL=postgres://postgres:postgres@postgres:5432/zksync_local + - ETH_CLIENT_WEB3_URL=http://geth:8545 + healthcheck: + test: "curl -H \"Content-Type: application/json\" -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":67}' 127.0.0.1:3050 || exit 1" + interval: 5s + timeout: 5s + retries: 300 + restart: unless-stopped + +volumes: + geth: + postgres: + zksync-config: + zksync-data: