LoginSignup
35
32

More than 5 years have passed since last update.

CircleCIでプライベートなファイルを暗号化してレポジトリ管理する

Posted at

手順忘れるので忘備録。
CircleCIでビルド時に必要なキーなどを書いたプライベートなファイルを安全に管理したい時は、ファイルを暗号化してレポジトリに含むとよいです。

ファイルの暗号化

opensslを利用して暗号化します。暗号化方式は色々ありますが、TravisCIのドキュメントでも利用されている aes-256-cbc を利用します。

ここではdir配下にあるprivate_propertiesを暗号化します。

$ openssl aes-256-cbc -e -in dir/private_properties -out encryptedProperties

上記でやるとpassword入力を求められますが、macでは入力がうまくいかないことがあるようです(ありました)。その場合はpasswordを書いたファイル(ここではpassword.txt)を用意し、

$ openssl aes-256-cbc -e -in dir/private_properties -out encryptedProperties -pass file:./password.txt

と実行してあげればencryptedPropertiesという暗号化ファイルができます。
このファイルをレポジトリにcommitします。

CircleCI側で復号のためのキー設定

  • CircleCIのコンソールの右上にあるProject Settingsを押下します。

  • Environment variablesを押下して、復号するために必要なキー(先ほどpasswordで設定した値)をEnvironment variableとして入力してあげます。
    ここでは仮に NAMEをDECRYPT_KEYとします。
    Screen Shot 2015-11-12 at 14.44.42.png

circle.ymlに復号処理を設定

CircleCIでプライベートファイルが必要になる直前で復号してあげる処理を追加します。例えばtestでプライベートファイルが必要な場合、

circle.yml
test:
  pre:
    - openssl aes-256-cbc -k $DECRYPT_KEY -d -in encrypted.properties -out dir/private_properties

これでCircleCIにcommit, pushしてあげると、CircleCI上でプライベートファイルを使ってビルドができます。

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