0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure DevOps の Pipeline のDocker でPostgres+Neon Proxyのローカルサーバを動かしたメモ

Last updated at Posted at 2025-04-14

概要

前回はAzure DevOpsのパイプライン上で起動したDockerのPostgresqlにそのままバックエンドからアクセスした。
今回は、Neon Proxyを経由してのアクセスを行う。

この時点のソースコード

追加したパイプライン定義

packages/bdd-e2e-test/azure-pipeline.yml

      - script: |
          echo "127.0.0.1 db.localtest.me" | sudo tee -a /etc/hosts
        displayName: "Add db.localtest.me to /etc/hosts"

      - script: |
          echo "Waiting for PostgreSQL..."
          for i in {1..20}; do
            if PGPASSWORD=postgres psql -h db.localtest.me -U postgres -d main -c "SELECT 1" &>/dev/null; then
              echo "PostgreSQL is ready"
              break
            fi
            sleep 2
          done
        displayName: 'Wait for PostgreSQL server to start'

      # Neon Proxyはserviceとして起動すると postgresの起動を待たないので、docker runで起動する
      - script: |
          echo "Starting Neon Proxy..."
          # Docker内からホストのPostgreSQLに接続するための設定
          # --add-host=host.docker.internal:host-gateway は Linuxで host.docker.internal を使うためのオプション
          docker run -d --name neon-proxy \
            -e PG_CONNECTION_STRING=postgres://postgres:postgres@host.docker.internal:5432/main \
            -p 4444:4444 \
            --add-host=host.docker.internal:host-gateway \
            ghcr.io/timowilhelm/local-neon-http-proxy:main
        displayName: 'Start Neon Proxy'
        

Neon Proxyはpostgresの起動後に立ち上げないとエラーになるが、serviceで定義するとpostgresと同時に起動してしまう。
DevOpsでは docker-compose での depends_onが利用できないので、タスクとしてNeon Proxy のDockerを起動する。
このとき、serviceの外で定義するとネットワークが別になるため、service名で通信ができない。

そのため、ホストのアドレスhost.docker.internalとポートを利用している。

参考

Docker Engine(Linux)でコンテナからホスト側のサービスにアクセスする(host.docker.internal)
サービスコンテナ
Local Development with Neon
Neon(Postgres)のDockerをローカルで稼働させ、Drizzleを使ったマイグレーションとCloudflare Workersのローカル実行からの接続を行ったメモ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?