Help us understand the problem. What is going on with this article?

Packerで作ったAMIにServerspecを適用してちゃんとできたか確認する

More than 5 years have passed since last update.
  • shellなりcloud-initなりでプロビジョニング
  • ローカルにあるServerspecのテストケース一式をアップロード
  • ExecでServerspecを実行する

こんな手順。

なお、Packerはプロバイダに依存せずプロビジョニングができるので、AWSのAMIだけでなくOpenStackやら何やらにも使えるのでは。

設定.json

settei.json
{
...
  "provisioners": [
    {
      "type": "shell",
      "script": "provisioners/setup.sh",
      "execute_command": "{{ .Vars }} sudo -E sh '{{ .Path }}'"
    },
    {
      "type": "file",
      "source": "serverspec",
      "destination": "/tmp"
    },
    {
      "type": "shell",
      "script": "provisioners/run-serverspec.sh",
      "execute_command": "{{ .Vars }} sudo -E sh '{{ .Path }}'"
    }
  ]
}

sudo 云々は公式にある sudoさせる設定。

Serverspecする

プロジェクトの serverspec/ 以下に serverspec-init などで Exec 設定のプロジェクトを用意しておこう。

run-serverspec.sh はこんな感じで。

run-serverspec.sh
#!/bin/bash

yum -y -q install rubygem-bundler
cd /tmp/serverspec
bundle install --path vendor/bundle
bundle exec rake spec

rm -rf /tmp/serverspec
yum -y -q remove rubygem-bundler

スクリーンショット 2015-02-09 17.34.43.png

参考

udzura
投稿しているコードは、指定が無い限り MIT とします。
http://udzura.hatenablog.jp
pepabo
「いるだけで成長できる環境」を標榜し、エンジニアが楽しく開発できるWebサービス企業を目指しています。
https://pepabo.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした