name: Full sync test on: workflow_dispatch: inputs: network: default: 'Mainnet' pull_request: branches: - main paths: # code and tests (including full sync acceptance test changes) # TODO: ignore changes in test code that isn't used in the full sync test - '**/*.rs' # hard-coded checkpoints # TODO: ignore changes to proptest seed .txt files - '**/*.txt' # dependencies - '**/Cargo.toml' - '**/Cargo.lock' # workflow definitions - 'docker/**' - '.github/workflows/test-full-sync.yml' env: CARGO_INCREMENTAL: '1' ZEBRA_SKIP_IPV6_TESTS: "1" NETWORK: Mainnet PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} GAR_BASE: us-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/zebra GCR_BASE: gcr.io/${{ secrets.GCP_PROJECT_ID }} REGION: us-central1 ZONE: us-central1-a MACHINE_TYPE: c2d-standard-16 IMAGE_NAME: zebrad-test jobs: build: # only run on Mergify head branches: # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-workflow-based-on-the-head-or-base-branch-of-a-pull-request-1 if: startsWith(github.head_ref, 'mergify/merge-queue/') name: Build images timeout-minutes: 210 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.4.0 with: persist-credentials: false - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v4 # Automatic tag management and OCI Image Format Specification for labels - name: Docker meta id: meta uses: docker/metadata-action@v3.6.2 with: # list of Docker images to use as base name for tags images: | ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }} ${{ env.GCR_BASE }}/${{ env.GITHUB_REPOSITORY_SLUG_URL }}/${{ env.IMAGE_NAME }} # generate Docker tags based on the following events/attributes tags: | type=schedule type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha # Setup Docker Buildx to allow use of docker cache layers from GH - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - name: Login to Google Artifact Registry uses: docker/login-action@v1.14.1 with: registry: us-docker.pkg.dev username: _json_key password: ${{ secrets.GOOGLE_CREDENTIALS }} - name: Login to Google Container Registry uses: docker/login-action@v1.14.1 with: registry: gcr.io username: _json_key password: ${{ secrets.GOOGLE_CREDENTIALS }} # Build and push image to Google Artifact Registry - name: Build & push id: docker_build uses: docker/build-push-action@v2.8.0 with: target: tester context: . file: ./docker/Dockerfile tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | NETWORK=${{ github.event.inputs.network || env.NETWORK }} SHORT_SHA=${{ env.GITHUB_SHA_SHORT }} RUST_BACKTRACE=full ZEBRA_SKIP_NETWORK_TESTS="1" CHECKPOINT_SYNC=${{ github.event.inputs.checkpoint_sync || true }} RUST_LOG=debug SENTRY_DSN=${{ secrets.SENTRY_ENDPOINT }} push: true cache-from: type=gha cache-to: type=gha,mode=max # Test that Zebra can run a full mainnet sync after a PR is approved test-full-sync: name: Test full Mainnet sync runs-on: ubuntu-latest needs: [ build ] steps: - uses: actions/checkout@v2.4.0 with: persist-credentials: false - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v4 # Setup gcloud CLI - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v0.5.0 with: credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} # Creates Compute Engine virtual machine instance w/ disks - name: Create GCP compute instance id: create-instance run: | gcloud compute instances create-with-container "full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" \ --boot-disk-size 100GB \ --boot-disk-type pd-extreme \ --container-image ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} \ --container-restart-policy=never \ --container-stdin \ --container-tty \ --container-env=ZEBRA_SKIP_IPV6_TESTS=1,TEST_FULL_SYNC=1,ZEBRA_FORCE_USE_COLOR=1,FULL_SYNC_MAINNET_TIMEOUT_MINUTES=600 \ --machine-type ${{ env.MACHINE_TYPE }} \ --scopes cloud-platform \ --metadata=google-monitoring-enabled=true,google-logging-enabled=true \ --tags zebrad \ --zone "${{ env.ZONE }}" # TODO: this approach is very mesy, but getting the just created container name is very error prone and GCP doesn't have a workaround for this without requiring a TTY # This TODO relates to the following issues: # https://github.com/actions/runner/issues/241 # https://www.googlecloudcommunity.com/gc/Infrastructure-Compute-Storage/SSH-into-Compute-Container-not-easily-possible/td-p/170915 - name: Get container name from logs id: get-container-name if: steps.create-instance.outcome == 'success' run: | INSTANCE_ID=$(gcloud compute instances describe full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} --zone ${{ env.ZONE }} --format='value(id)') echo "Using instance: $INSTANCE_ID" while [[ ${CONTAINER_NAME} != *"full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}"* ]]; do CONTAINER_NAME=$(gcloud logging read 'log_name=projects/${{ env.PROJECT_ID }}/logs/cos_system AND jsonPayload.MESSAGE:full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}' --format='value(jsonPayload.MESSAGE)' --limit=1 | grep -o '...-full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-....' | tr -d "'.") echo "Using container: ${CONTAINER_NAME} from instance: ${INSTANCE_ID}" sleep 10 done CONTAINER_NAME=$(gcloud logging read 'log_name=projects/${{ env.PROJECT_ID }}/logs/cos_system AND jsonPayload.MESSAGE:full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}' --format='value(jsonPayload.MESSAGE)' --limit=1 | grep -o '...-full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}-....' | tr -d "'.") echo "::set-output name=zebra_container::$CONTAINER_NAME" - name: Full sync mainnet id: full-sync-mainnet run: | gcloud compute ssh \ full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \ --zone ${{ env.ZONE }} \ --quiet \ --ssh-flag="-o ServerAliveInterval=5" \ --command="docker logs --follow ${{ env.ZEBRA_CONTAINER }}" env: ZEBRA_CONTAINER: ${{ steps.get-container-name.outputs.zebra_container }} - name: Delete test instance # Do not delete the instance if the sync timeouts in GitHub if: ${{ steps.full-sync-mainnet.outcome == 'success' || steps.full-sync-mainnet.outcome == 'failure' }} continue-on-error: true run: | gcloud compute instances delete "full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }}" --delete-disks all --zone "${{ env.ZONE }}"