jpskill.com
🛠️ 開発・MCP コミュニティ

packer

HashiCorp Packerを活用し、HCLテンプレートとプロビジョナーを用いて、AMI、Dockerイメージ、GCPイメージといった一貫性があり再現可能なインフラストラクチャイメージを自動構築するSkill。

📜 元の英語説明(参考)

HashiCorp Packer for building automated machine images. Use when the user needs to create AMIs, Docker images, or GCP images using HCL templates with provisioners for consistent, reproducible infrastructure images.

🇯🇵 日本人クリエイター向け解説

一言でいうと

HashiCorp Packerを活用し、HCLテンプレートとプロビジョナーを用いて、AMI、Dockerイメージ、GCPイメージといった一貫性があり再現可能なインフラストラクチャイメージを自動構築するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o packer.zip https://jpskill.com/download/15225.zip && unzip -o packer.zip && rm packer.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15225.zip -OutFile "$d\packer.zip"; Expand-Archive "$d\packer.zip" -DestinationPath $d -Force; ri "$d\packer.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して packer.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → packer フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Packer

Packer は、単一のソース構成から複数のプラットフォーム向けのマシンイメージの作成を自動化します。

インストール

# Packer のインストール
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install packer

# 検証
packer version

AWS AMI Builder

# aws-ubuntu.pkr.hcl — Nginx を使用して Ubuntu AMI を構築
packer {
  required_plugins {
    amazon = {
      version = ">= 1.2.0"
      source  = "github.com/hashicorp/amazon"
    }
  }
}

variable "aws_region" {
  type    = string
  default = "us-east-1"
}

variable "app_version" {
  type = string
}

source "amazon-ebs" "ubuntu" {
  ami_name      = "app-{{timestamp}}"
  instance_type = "t3.medium"
  region        = var.aws_region

  source_ami_filter {
    filters = {
      name                = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }

  ssh_username = "ubuntu"

  tags = {
    Name        = "app-${var.app_version}"
    Environment = "production"
    Builder     = "packer"
  }
}

build {
  sources = ["source.amazon-ebs.ubuntu"]

  provisioner "shell" {
    inline = [
      "sudo apt-get update",
      "sudo apt-get install -y nginx curl jq",
      "sudo systemctl enable nginx"
    ]
  }

  provisioner "file" {
    source      = "files/nginx.conf"
    destination = "/tmp/nginx.conf"
  }

  provisioner "shell" {
    inline = [
      "sudo mv /tmp/nginx.conf /etc/nginx/sites-available/default",
      "sudo nginx -t"
    ]
  }

  provisioner "shell" {
    inline = ["sudo apt-get clean", "sudo rm -rf /var/lib/apt/lists/*"]
  }

  post-processor "manifest" {
    output     = "manifest.json"
    strip_path = true
  }
}

Docker Builder

# docker-app.pkr.hcl — Packer で Docker イメージを構築
source "docker" "app" {
  image  = "python:3.12-slim"
  commit = true

  changes = [
    "EXPOSE 8080",
    "WORKDIR /app",
    "CMD [\"python\", \"app.py\"]"
  ]
}

build {
  sources = ["source.docker.app"]

  provisioner "shell" {
    inline = [
      "pip install --no-cache-dir flask gunicorn",
      "mkdir -p /app"
    ]
  }

  provisioner "file" {
    source      = "app/"
    destination = "/app/"
  }

  post-processor "docker-tag" {
    repository = "myregistry.com/myapp"
    tags       = ["latest", var.app_version]
  }

  post-processor "docker-push" {
    login          = true
    login_server   = "myregistry.com"
    login_username = var.registry_user
    login_password = var.registry_pass
  }
}

GCP Image Builder

# gcp-image.pkr.hcl — GCP Compute Engine イメージを構築
source "googlecompute" "ubuntu" {
  project_id   = var.gcp_project
  source_image = "ubuntu-2204-jammy-v20240101"
  zone         = "us-central1-a"
  machine_type = "e2-medium"
  ssh_username = "packer"
  image_name   = "app-{{timestamp}}"

  image_labels = {
    environment = "production"
    builder     = "packer"
  }
}

build {
  sources = ["source.googlecompute.ubuntu"]

  provisioner "shell" {
    scripts = [
      "scripts/base-setup.sh",
      "scripts/install-app.sh"
    ]
    environment_vars = [
      "APP_VERSION=${var.app_version}"
    ]
  }

  provisioner "ansible" {
    playbook_file = "ansible/configure.yml"
  }
}

Multi-Builder Template

# multi-platform.pkr.hcl — AWS と GCP 向けに同時に構築
variable "app_version" {
  type    = string
  default = "1.0.0"
}

source "amazon-ebs" "base" {
  ami_name      = "app-${var.app_version}-{{timestamp}}"
  instance_type = "t3.medium"
  region        = "us-east-1"
  source_ami_filter {
    filters = { name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" }
    most_recent = true
    owners      = ["099720109477"]
  }
  ssh_username = "ubuntu"
}

source "googlecompute" "base" {
  project_id   = var.gcp_project
  source_image = "ubuntu-2204-jammy-v20240101"
  zone         = "us-central1-a"
  ssh_username = "packer"
  image_name   = "app-${var.app_version}-{{timestamp}}"
}

build {
  sources = [
    "source.amazon-ebs.base",
    "source.googlecompute.base"
  ]

  provisioner "shell" {
    script = "scripts/setup.sh"
  }
}

共通コマンド

# テンプレートの検証
packer validate .

# イメージの構築
packer build .
packer build -var "app_version=2.0.0" aws-ubuntu.pkr.hcl

# 特定のソースのみを構築
packer build -only="amazon-ebs.ubuntu" .

# プラグインの初期化
packer init .

# HCL ファイルのフォーマット
packer fmt .

# テンプレートの検査
packer inspect .

# デバッグモード
PACKER_LOG=1 packer build .
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Packer

Packer automates the creation of machine images for multiple platforms from a single source configuration.

Installation

# Install Packer
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install packer

# Verify
packer version

AWS AMI Builder

# aws-ubuntu.pkr.hcl — Build Ubuntu AMI with Nginx
packer {
  required_plugins {
    amazon = {
      version = ">= 1.2.0"
      source  = "github.com/hashicorp/amazon"
    }
  }
}

variable "aws_region" {
  type    = string
  default = "us-east-1"
}

variable "app_version" {
  type = string
}

source "amazon-ebs" "ubuntu" {
  ami_name      = "app-{{timestamp}}"
  instance_type = "t3.medium"
  region        = var.aws_region

  source_ami_filter {
    filters = {
      name                = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }

  ssh_username = "ubuntu"

  tags = {
    Name        = "app-${var.app_version}"
    Environment = "production"
    Builder     = "packer"
  }
}

build {
  sources = ["source.amazon-ebs.ubuntu"]

  provisioner "shell" {
    inline = [
      "sudo apt-get update",
      "sudo apt-get install -y nginx curl jq",
      "sudo systemctl enable nginx"
    ]
  }

  provisioner "file" {
    source      = "files/nginx.conf"
    destination = "/tmp/nginx.conf"
  }

  provisioner "shell" {
    inline = [
      "sudo mv /tmp/nginx.conf /etc/nginx/sites-available/default",
      "sudo nginx -t"
    ]
  }

  provisioner "shell" {
    inline = ["sudo apt-get clean", "sudo rm -rf /var/lib/apt/lists/*"]
  }

  post-processor "manifest" {
    output     = "manifest.json"
    strip_path = true
  }
}

Docker Builder

# docker-app.pkr.hcl — Build Docker image with Packer
source "docker" "app" {
  image  = "python:3.12-slim"
  commit = true

  changes = [
    "EXPOSE 8080",
    "WORKDIR /app",
    "CMD [\"python\", \"app.py\"]"
  ]
}

build {
  sources = ["source.docker.app"]

  provisioner "shell" {
    inline = [
      "pip install --no-cache-dir flask gunicorn",
      "mkdir -p /app"
    ]
  }

  provisioner "file" {
    source      = "app/"
    destination = "/app/"
  }

  post-processor "docker-tag" {
    repository = "myregistry.com/myapp"
    tags       = ["latest", var.app_version]
  }

  post-processor "docker-push" {
    login          = true
    login_server   = "myregistry.com"
    login_username = var.registry_user
    login_password = var.registry_pass
  }
}

GCP Image Builder

# gcp-image.pkr.hcl — Build GCP Compute Engine image
source "googlecompute" "ubuntu" {
  project_id   = var.gcp_project
  source_image = "ubuntu-2204-jammy-v20240101"
  zone         = "us-central1-a"
  machine_type = "e2-medium"
  ssh_username = "packer"
  image_name   = "app-{{timestamp}}"

  image_labels = {
    environment = "production"
    builder     = "packer"
  }
}

build {
  sources = ["source.googlecompute.ubuntu"]

  provisioner "shell" {
    scripts = [
      "scripts/base-setup.sh",
      "scripts/install-app.sh"
    ]
    environment_vars = [
      "APP_VERSION=${var.app_version}"
    ]
  }

  provisioner "ansible" {
    playbook_file = "ansible/configure.yml"
  }
}

Multi-Builder Template

# multi-platform.pkr.hcl — Build for AWS and GCP simultaneously
variable "app_version" {
  type    = string
  default = "1.0.0"
}

source "amazon-ebs" "base" {
  ami_name      = "app-${var.app_version}-{{timestamp}}"
  instance_type = "t3.medium"
  region        = "us-east-1"
  source_ami_filter {
    filters = { name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" }
    most_recent = true
    owners      = ["099720109477"]
  }
  ssh_username = "ubuntu"
}

source "googlecompute" "base" {
  project_id   = var.gcp_project
  source_image = "ubuntu-2204-jammy-v20240101"
  zone         = "us-central1-a"
  ssh_username = "packer"
  image_name   = "app-${var.app_version}-{{timestamp}}"
}

build {
  sources = [
    "source.amazon-ebs.base",
    "source.googlecompute.base"
  ]

  provisioner "shell" {
    script = "scripts/setup.sh"
  }
}

Common Commands

# Validate template
packer validate .

# Build image
packer build .
packer build -var "app_version=2.0.0" aws-ubuntu.pkr.hcl

# Build specific source only
packer build -only="amazon-ebs.ubuntu" .

# Initialize plugins
packer init .

# Format HCL files
packer fmt .

# Inspect template
packer inspect .

# Debug mode
PACKER_LOG=1 packer build .