はじめに
Image Builder試してみたけど、インストールしたいパッケージのComponentsがない。
このためにドキュメント調べるのか。。メンドイ
ってなった事はないだろうか?私はある。
AWSのComponentsをベースに作る
AWSで用意してあるComponentsをベースに、ちょっと変えるだけ。
単純にインストールするだけなら難しくない。
1. ベースのComponentsをコピペ
Componentsにpython-3-linux
という物があるので、それを使うといい。
name: Python 3
description: Install the latest version of Python 3.
schemaVersion: 1.0
phases:
- name: build
steps:
- name: InstallPython3
action: ExecuteBash
inputs:
commands:
- sudo yum install python3 -y
- name: validate
steps:
- name: ValidatePython3
action: ExecuteBash
inputs:
commands:
- |
if type -P python3 &>/dev/null; then
echo "The python3 command exists."
else
echo "The python3 command does not exist. Failing."
exit 1
fi
python3 --version
if [[ $? == 0 ]]; then
echo "python3 was successfully invoked."
else
echo "python3 could not be invoked. Failing."
exit 1
fi
2. インストールしたいものに合わせる
Gitをyumでインストールしてみる。
# Python 3となっている箇所を変える
name: Git
description: Install the latest version of Git.
schemaVersion: 1.0
phases:
- name: build
steps:
# Python3となっている箇所を変える
- name: InstallGit
action: ExecuteBash
inputs:
commands:
# インストールコマンドを入れる
- sudo yum install git -y
- name: validate
steps:
- name: ValidateGit
action: ExecuteBash
inputs:
commands:
# python3となっている箇所を変える
- |
if type -P git &>/dev/null; then
echo "The git command exists."
else
echo "The git command does not exist. Failing."
exit 1
fi
git --version
if [[ $? == 0 ]]; then
echo "git was successfully invoked."
else
echo "git could not be invoked. Failing."
exit 1
fi
これだけ!
あとはコンポーネントに反映して、パイプライン作ってテストすれば良い。
補足
python-3-linux
は、単に最新バージョンをインストールして確認するだけだが、他にも処理を入れるなら以下あたりが参考になりそう。
- バージョン判定を行う
php-7_3-linux - systemctl enableする
docker-ce-linux
EC2 Image Builderとは(一応説明)
AMI作成を自動化してくれるツール(パッケージインストール等をやってくれる)。
Developers.IO:EC2のイメージ作成を劇的に効率化するEC2 Image Builderが発表されました! #reinvent
Qiita:EC2 Image Builder を触ってみました。