経緯

  • CodeDeploy で利用するコンテナ内で MySQL 5.7.x を動かしたかった
  • buildspec.yml の install フェーズあたりに指定するといい感じ
  • たまたま選んだコンテナのベースイメージが Debian Jessie だった

メモ

以下のような感じで MySQL が起動するところまでは確認した。

apt-get update
apt-get install -y gnupg procps
export DEBIAN_FRONTEND=noninteractive
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 5072E1F5
echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7" | tee -a /etc/apt/sources.list.d/mysql.list
apt-get update
MYSQL_PASSWORD="your_password"
echo "mysql-community-server mysql-community-server/root-pass password ${MYSQL_PASSWORD}" | debconf-set-selections
echo "mysql-community-server mysql-community-server/re-root-pass password ${MYSQL_PASSWORD}" | debconf-set-selections
apt-get install -y mysql-community-server
service mysql start

buildspec.yml に落とし込むと以下のような感じになると思う。(ちゃんと試せてないけど)

version: 0.2
env:
  variables:
    MYSQL_PASSEORD: "your_password"
phases:
  install:
    commands:
      - apt-get update
      - apt-get install -y gnupg procps
      - export DEBIAN_FRONTEND=noninteractive
      - apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 5072E1F5
      - echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7" | tee -a /etc/apt/sources.list.d/mysql.list
      - apt-get update
      - echo "mysql-community-server mysql-community-server/root-pass password ${MYSQL_PASSWORD}" | debconf-set-selections
      - echo "mysql-community-server mysql-community-server/re-root-pass password ${MYSQL_PASSWORD}" | debconf-set-selections
      - apt-get install -y mysql-community-server
      - service mysql start
  build:
    commands:
      - your_commnd...
artifacts:
  files:
    - your_file

以上

メモでした。時代は Non Interactive だと思う。

元記事はこちら

Non Interactive に MySQL 5.7.x をインストールする手順メモ(Debian 又は Ubuntu 環境版)