7
7

More than 5 years have passed since last update.

Drone - サービスコンテナへのポートフォワーディングをどうしているのか読んでみた

Last updated at Posted at 2014-12-22

drone.io は以下のような設定を入れておくと、テスト実行コンテナとは別途サービス(多くの場合外部のDB)を立ち上げてくれる。

service:
  - mysql

これがどうなっているかと言うと、まず、登録されたサービスの情報をもとに proxy.sh と言うファイルを生成する。

そのあと、実際にテスト用のコンテナをビルドするタイミングでそのファイルを /etc/drone.d/ 以下に追加し、ログイン時に自動で起動するようにしている。

実際の proxy.sh の中身は以下のようになる。

proxy.sh
#!/bin/bash
[ -x /usr/bin/socat ] && socat TCP-LISTEN:3306,fork TCP:172.17.10.210:3306 &
[ -x /usr/bin/socat ] && socat TCP-LISTEN:11211,fork TCP:172.17.10.211:11211 &

このコマンド自体は、

build.go#L541-L543
for port := range container.NetworkSettings.Ports {
    proxyfile.Set(port.Port(), container.NetworkSettings.IPAddress)
}

となっているようにコンテナ自体の情報からマッピングを作成するので、EXPOSEしておけば公式イメージでも独自イメージでも変わりなく扱える模様。便利じゃん

以上です。

7
7
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
7
7