· 8 years ago · Jan 12, 2018, 03:24 PM
1{
2 "variables": {
3 "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
4 "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
5 "ssh_username": "ec2-user",
6 "git_commit": "",
7 "ami_name": "helloworld-example",
8 "envName": ""
9 },
10 "builders": [
11 {
12 "type": "amazon-ebs",
13 "access_key": "{{user `aws_access_key`}}",
14 "secret_key": "{{user `aws_secret_key` }}",
15 "region": "us-west-2",
16 "source_ami_filter": {
17 "filters": {
18 "architecture": "x86_64",
19 "virtualization-type": "hvm",
20 "name": "CENTOS-7-HVM-EBS-BASE-OATH-*",
21 "root-device-type": "ebs"
22 },
23 "owners": ["062522161164"],
24 "most_recent": true
25 },
26 "instance_type": "t2.micro",
27 "ssh_username": "{{user `ssh_username`}}",
28 "ami_name": "{{ user `ami_name` }}-{{ user `git_commit` }}-{{ timestamp }}",
29 "ami_description": "Hello World example using Oath Foundation Image (CentOS)",
30 "tags": {
31 "Name": "Helloworld-Example",
32 "OS": "CentOS"
33 },
34 "associate_public_ip_address": false,
35 "encrypt_boot": true
36 }
37 ],
38 "provisioners": [
39 {
40 "type": "file",
41 "source": "yjava_jdk-1.8.0_131.267.tgz",
42 "destination": "/home/ec2-user/"
43 },
44 {
45 "type": "shell",
46 "scripts": [
47 "packer/scripts/setup.sh"
48 ],
49 "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E '{{ .Path }}'"
50 },
51 {
52 "type": "file",
53 "source": "packer/ssh_keys",
54 "destination": "/opt"
55 },
56 {
57 "type": "shell",
58 "execute_command": "echo {{user `ssh_username`}} | {{ .Vars }} sudo -E -S sh '{{ .Path }}'",
59 "inline": [
60 "cat /opt/ssh_keys/* >> /home/ec2-user/.ssh/authorized_keys"
61 ]
62 },
63 {
64 "type": "file",
65 "source": "build/libs/example-helloworld.jar",
66 "destination": "/opt/example/"
67 }
68 ]
69}