Skip to content

Instantly share code, notes, and snippets.

@prenaissance
Created February 17, 2025 16:00
Show Gist options
  • Select an option

  • Save prenaissance/f24155e6802418fe1baf537c06ec5de7 to your computer and use it in GitHub Desktop.

Select an option

Save prenaissance/f24155e6802418fe1baf537c06ec5de7 to your computer and use it in GitHub Desktop.
Spanner Emulator PG Adapter on M4 Macs

JVM containers are crashing on M4 Macbooks. This causes the PG Adapter for Cloud Spanner to crash and makes running the proxy impossible on ARM64. This gist explores how to overcome this by emulating x86 using Rosetta.

Pre-requisites:

  1. Enable Rosetta 2
softwareupdate --install-rosetta

The output logs should end with the line

Install of Rosetta 2 finished successfully

Docker Compose:

services:
  emulator:
    image: gcr.io/cloud-spanner-emulator/emulator
    restart: unless-stopped
    container_name: spanner-emulator
    ports:
      - '9010:9010' # gRPC
      - '9020:9020' # REST

  pgadapter:
    depends_on:
      emulator:
        condition: service_started
    # JVM crashes on M4 chips https://github.com/docker/for-mac/issues/7583
    platform: linux/amd64
    image: 'gcr.io/cloud-spanner-pg-adapter/pgadapter'
    restart: unless-stopped
    container_name: pgadapter-connected-to-emulator
    command:
      - '-p emulator-project'
      - '-i test-instance'
      - '-r autoConfigEmulator=true'
      - '-e emulator:9010'
      - '-c ""' # no credentials
      - '-x'
    ports:
      - '5433:5432' # pgwire

Run docker compose up -d then access the emulated spanner using any postgres client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment