리셋 되지 말자

[Packer] 이미시 생성 후, 결과를 파일로 저장 본문

Infra

[Packer] 이미시 생성 후, 결과를 파일로 저장

kyeongjun-dev 2021. 8. 9. 15:23

참고

공식 문서 : https://www.packer.io/docs/post-processors/manifest

 

사용법 example

{
  "post-processors": [
    {
      "type": "manifest",
      "output": "manifest.json",
      "strip_path": true,
      "custom_data": {
        "my_custom_data": "example"
      }
    }
  ]
}

 

실제 적용 example (docker가 설치된 aws 이미지 생성)

{
    "variables": {
        "name": "ubuntu-docker-ce-base",
        "aws-region": "ap-northeast-2",
        "ami-name": "packer_ubuntu_18.04 {{timestamp}}",
        "ec2-instance-type": "t2.micro",
        "aws-ssh-username": "ubuntu"
    },
    "builders": [
        {
            "name": "ubuntu-docker-ce",
            "type": "amazon-ebs",
            "region": "{{user `aws-region`}}",
            "instance_type": "{{user `ec2-instance-type`}}",
            "source_ami": "ami-0ba5cd124d7a79612",
            "ssh_username": "{{user `aws-ssh-username`}}",
            "ssh_timeout": "60m",
            "ami_name": "{{user `ami-name`}}"
        }
    ],
    "post-processors": [
        {
          "type": "manifest",
          "output": "manifest.json",
          "strip_path": true
        }
    ],
    "provisioners": [
        {
            "type": "shell",
            "inline": [
                "mkdir /home/$USER/.docker"
            ]
        },
        {
            "type": "file",
            "source": "/root/.docker/config.json",
            "destination": "/home/$USER/.docker/config.json"
        },
        {
            "type": "file",
            "source": "docker.sh",
            "destination": "./docker.sh"
        },
        {
            "type": "shell",
            "inline": [
                "chmod +x docker.sh",
                "./docker.sh",
                "sleep 5",
                "rm docker.sh"
            ]
        }
    ]
}
Comments