diff --git a/.gitignore b/.gitignore index 31246ce8e..6ab3cdfb9 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ packer-test*.log .idea/ *.iml Thumbs.db +/packer.exe \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e49f90b7a..ff531e890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,75 @@ -## UNRELEASED +## (UNRELEASED) + +### IMRPOVEMENTS: + +* post-processor/docker-push: Add `aws_profile` option to control the aws profile for ECR. [GH-5470] +* builder/docker: Add `aws_profile` option to control the aws profile for ECR. [GH-5470] +* post-processor/vsphere: Properly capture `ovftool` output. [GH-5499] +* builder/hyper-v: Also disable automatic checkpoints for gen 2 VMs. [GH-5517] +* builder/hyper-v: Add `disk_additional_size` option to allow for up to 64 additional disks. [GH-5491] +* builder/amazon: correctly deregister AMIs when `force_deregister` is set. [GH-5525] +* builder/digitalocean: Add `ipv6` option to enable on droplet. [GH-5534] +* builder/triton: Add `source_machine_image_filter` option to select an image ID based on a variety of parameters. [GH-5538] +* communicator/ssh: Add socks 5 proxy support. [GH-5439] +* builder/lxc: Add new `publish_properties` field to set image properties. [GH-5475] +* builder/virtualbox-ovf: Retry while removing VM to solve for transient errors. [GH-5512] ### BUG FIXES: -* builder/puppet-masterless: Make sure directories created with sudo are writable by the packer user. [GH-5351] +* builder/docker: Remove `login_email`, which no longer exists in the docker client. [GH-5511] +* builder/triton: Fix a bug where partially created images can be reported as complete. [GH-5566] +* builder/amazon: region is set from profile, if profile is set, rather than being overridden by metadata [GH-5562] + +## 1.1.1 (October 13, 2017) + +### IMPROVEMENTS: + +* **New builder:** `hyperv-vmcx` for building images from existing VMs. + [GH-4944] [GH-5444] +* builder/amazon-instance: Add `.Token` as a variable in the + `BundleUploadCommand` template. [GH-5288] +* builder/amazon: Add `temporary_security_group_source_cidr` option to control + ingress to source instances. [GH-5384] +* builder/amazon: Output AMI Name during prevalidation. [GH-5389] +* builder/amazon: Support template functions in tag keys. [GH-5381] +* builder/amazon: Tag volumes on creation instead of as a separate step. + [GH-5417] +* builder/docker: Add option to set `--user` flag when running `exec`. + [GH-5406] +* builder/docker: Set file owner to container user when uploading. Can be + disabled by setting `fix_upload_owner` to `false`. [GH-5422] +* builder/googlecompute: Support setting labels on the resulting image. + [GH-5356] +* builder/hyper-v: Add `vhd_temp_path` option to control where the VHD resides + while it's being provisioned. [GH-5206] +* builder/hyper-v: Allow vhd or vhdx source images instead of just ISO. + [GH-4944] [GH-5444] +* builder/hyper-v: Disable automatic checkpoints. [GH-5374] +* builder/virtualbox-ovf: Add `keep_registered` option. [GH-5336] +* builder/vmware: Add `disable_vnc` option to prevent VNC connections from + being made. [GH-5436] +* core: Releases will now be built for ppc64le. +* post-processor/vagrant: When building from a builder/hyper-v artifact, link + instead of copy when available. [GH-5207] + + +### BUG FIXES: + +* builder/cloudstack: Fix panic if build is aborted. [GH-5388] +* builder/hyper-v: Respect `enable_dynamic_memory` flag. [GH-5363] +* builder/puppet-masterless: Make sure directories created with sudo are + writable by the packer user. [GH-5351] +* provisioner/chef-solo: Fix issue installing chef-solo on Windows. [GH-5357] +* provisioner/powershell: Fix issue setting environment variables by writing + them to a file, instead of the command line. [GH-5345] +* provisioner/powershell: Fix issue where powershell scripts could hang. + [GH-5082] +* provisioner/powershell: Fix Powershell progress stream leak to stderr for + normal and elevated commands. [GH-5365] +* provisioner/puppet-masterless: Fix bug where `puppet_bin_dir` wasn't being + respected. [GH-5340] +* provisioner/puppet: Fix setting facter vars on Windows. [GH-5341] + ## 1.1.0 (September 12, 2017) diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..c037a38d4 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,26 @@ +* @hashicorp/packer + +# builders + +/builder/alicloud/ dongxiao.zzh@alibaba-inc.com +/builder/amazon/ebssurrogate/ @jen20 +/builder/amazon/ebsvolume/ @jen20 +/builder/azure/ @boumenot +/builder/hyperv/ @taliesins +/builder/lxc/ @ChrisLundquist +/builder/lxd/ @ChrisLundquist +/builder/oneandone/ @jasmingacic +/builder/oracle/ @prydie @owainlewis +/builder/profitbricks/ @jasmingacic +/builder/triton/ @jen20 @sean- + +# provisioners + +/provisioner/ansible/ @bhcleek +/provisioner/converge/ @stevendborrelli + +# post-processors +/post-processor/alicloud-import/ dongxiao.zzh@alibaba-inc.com +/post-processor/checksum/ v.tolstov@selfip.ru +/post-processor/googlecompute-export/ crunkleton@google.com +/post-processor/vsphere-template/ nelson@bennu.cl diff --git a/Makefile b/Makefile index d7f3578ec..3a68f0ba5 100644 --- a/Makefile +++ b/Makefile @@ -51,8 +51,9 @@ dev: deps ## Build and install a development build exit 1; \ fi @mkdir -p pkg/$(GOOS)_$(GOARCH) + @mkdir -p bin @go install -ldflags '$(GOLDFLAGS)' - @cp $(GOPATH)/bin/packer bin + @cp $(GOPATH)/bin/packer bin/packer @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) fmt: ## Format Go code diff --git a/README.md b/README.md index 8dac199dc..5249f515e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ comes out of the box with support for the following platforms: * Hyper-V * 1&1 * OpenStack -* Oracle Bare Metal Cloud Services +* Oracle Cloud Infrastructure * Parallels * ProfitBricks * QEMU. Both KVM and Xen images. diff --git a/Vagrantfile b/Vagrantfile index b61b3d209..30b0437ba 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,50 +1,89 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -$script = <` tags to enclose any commands +that you would normally run in a Command Prompt window. See +[Running Commands on Your Windows Instance at Launch]( +http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html) +for more info about what's going on behind the scenes here. + +```powershell + +# Set administrator password +net user Administrator SuperS3cr3t! +wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE + +# First, make sure WinRM can't be connected to +netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" new enable=yes action=block + +# Delete any existing WinRM listeners +winrm delete winrm/config/listener?Address=*+Transport=HTTP 2>$Null +winrm delete winrm/config/listener?Address=*+Transport=HTTPS 2>$Null + +# Create a new WinRM listener and configure +winrm create winrm/config/listener?Address=*+Transport=HTTP +winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="0"}' +winrm set winrm/config '@{MaxTimeoutms="7200000"}' +winrm set winrm/config/service '@{AllowUnencrypted="true"}' +winrm set winrm/config/service '@{MaxConcurrentOperationsPerUser="12000"}' +winrm set winrm/config/service/auth '@{Basic="true"}' +winrm set winrm/config/client/auth '@{Basic="true"}' + +# Configure UAC to allow privilege elevation in remote shells +$Key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' +$Setting = 'LocalAccountTokenFilterPolicy' +Set-ItemProperty -Path $Key -Name $Setting -Value 1 -Force + +# Configure and restart the WinRM Service; Enable the required firewall exception +Stop-Service -Name WinRM +Set-Service -Name WinRM -StartupType Automatic +netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" new action=allow localip=any remoteip=any +Start-Service -Name WinRM + +``` + +Save the above code in a file named `bootstrap_win.txt`. + +-> **A quick aside/warning:**
+Windows administrators in the know might be wondering why we haven't simply +used a `winrm quickconfig -q` command in the script above, as this would +*automatically* set up all of the required elements necessary for connecting +over WinRM. Why all the extra effort to configure things manually?
+Well, long and short, use of the `winrm quickconfig -q` command can sometimes +cause the Packer build to fail shortly after the WinRM connection is +established. How?
+1. Among other things, as well as setting up the listener for WinRM, the +quickconfig command also configures the firewall to allow management messages +to be sent over HTTP.
+2. This undoes the previous command in the script that configured the +firewall to prevent this access.
+3. The upshot is that the system is configured and ready to accept WinRM +connections earlier than intended.
+4. If Packer establishes its WinRM connection immediately after execution of +the 'winrm quickconfig -q' command, the later commands within the script that +restart the WinRM service will unceremoniously pull the rug out from under +the connection.
+5. While Packer does *a lot* to ensure the stability of its connection in to +your instance, this sort of abuse can prove to be too much and *may* cause +your Packer build to stall irrecoverably or fail! + +Now we've got the business of getting Packer connected to our instance +taken care of, let's get on with the *real* reason we're doing all this, +which is actually configuring and customizing the instance. Again, we do this +with [Provisioners](/docs/provisioners/index.html). + +The example config below shows the two different ways of using the [PowerShell +provisioner](/docs/provisioners/powershell.html): `inline` and `script`. +The first example, `inline`, allows you to provide short snippets of code, and +will create the script file for you. The second example allows you to run more +complex code by providing the path to a script to run on the guest VM. + +Here's an example of a `sample_script.ps1` that will work with the environment +variables we will set in our build template; copy the contents into your own +`sample_script.ps1` and provide the path to it in your build template: + +```powershell +Write-Host "PACKER_BUILD_NAME is automatically set for you, " -NoNewline +Write-Host "or you can set it in your builder variables; " -NoNewline +Write-Host "The default for this builder is:" $Env:PACKER_BUILD_NAME + +Write-Host "Use backticks as the escape character when required in powershell:" +Write-Host "For example, VAR1 from our config is:" $Env:VAR1 +Write-Host "Likewise, VAR2 is:" $Env:VAR2 +Write-Host "Finally, VAR3 is:" $Env:VAR3 +``` + +Finally, we need to create the actual [build template]( +/docs/templates/index.html). +Remember, this template is the core configuration file that Packer uses to +understand what you want to build, and how you want to build it. + +As mentioned earlier, the specific builder we are using in this example +is the [Amazon EBS builder](/docs/builders/amazon-ebs.html). +The template below demonstrates use of the [`source_ami_filter`]( +/docs/builders/amazon-ebs.html#source_ami_filter) configuration option +available within the builder for automatically selecting the *latest* +suitable source Windows AMI provided by Amazon. +We also use the `user_data_file` configuration option provided by the builder +to reference the bootstrap file we created earlier. As you will recall, our +bootstrap file contained all the commands we needed to supply in advance of +actually spinning up the instance, so that later on, our instance is +configured to allow Packer to connect in to it. + +The `"provisioners"` section of the template demonstrates use of the +[powershell](/docs/provisioners/powershell.html) and +[windows-restart](/docs/provisioners/windows-restart.html) provisioners to +customize and control the build process: + +```json +{ + "variables": { + "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", + "region": "us-east-1" + }, + "builders": [ + { + "type": "amazon-ebs", + "access_key": "{{ user `aws_access_key` }}", + "secret_key": "{{ user `aws_secret_key` }}", + "region": "{{ user `region` }}", + "instance_type": "t2.micro", + "source_ami_filter": { + "filters": { + "virtualization-type": "hvm", + "name": "*Windows_Server-2012-R2*English-64Bit-Base*", + "root-device-type": "ebs" + }, + "most_recent": true, + "owners": "amazon" + }, + "ami_name": "packer-demo-{{timestamp}}", + "user_data_file": "./bootstrap_win.txt", + "communicator": "winrm", + "winrm_username": "Administrator", + "winrm_password": "SuperS3cr3t!" + } + ], + "provisioners": [ + { + "type": "powershell", + "environment_vars": ["DEVOPS_LIFE_IMPROVER=PACKER"], + "inline": "Write-Host \"HELLO NEW USER; WELCOME TO $Env:DEVOPS_LIFE_IMPROVER\"" + }, + { + "type": "windows-restart" + }, + { + "script": "./sample_script.ps1", + "type": "powershell", + "environment_vars": [ + "VAR1=A`$Dollar", + "VAR2=A``Backtick", + "VAR3=A`'SingleQuote" + ] + } + ] +} +``` + +Save the build template as `firstrun.json`. + +Next we need to set things up so that Packer is able to access and use our +AWS account. Set your access key and id as environment variables, so we +don't need to pass them in through the command line: + +``` +export AWS_ACCESS_KEY_ID=MYACCESSKEYID +export AWS_SECRET_ACCESS_KEY=MYSECRETACCESSKEY +``` + +Finally, we can create our new AMI by running `packer build firstrun.json` + +You should see output like this: + +``` +amazon-ebs output will be in this color. + +==> amazon-ebs: Prevalidating AMI Name: packer-demo-1507933843 + amazon-ebs: Found Image ID: ami-23d93c59 +==> amazon-ebs: Creating temporary keypair: packer_59e13e94-203a-1bca-5327-bebf0d5ad15a +==> amazon-ebs: Creating temporary security group for this instance: packer_59e13ea9-3220-8dab-29c0-ed7f71e221a1 +==> amazon-ebs: Authorizing access to port 5985 from 0.0.0.0/0 in the temporary security group... +==> amazon-ebs: Launching a source AWS instance... +==> amazon-ebs: Adding tags to source instance + amazon-ebs: Adding tag: "Name": "Packer Builder" + amazon-ebs: Instance ID: i-0349406ac85f02166 +==> amazon-ebs: Waiting for instance (i-0349406ac85f02166) to become ready... +==> amazon-ebs: Skipping waiting for password since WinRM password set... +==> amazon-ebs: Waiting for WinRM to become available... + amazon-ebs: WinRM connected. +==> amazon-ebs: Connected to WinRM! +==> amazon-ebs: Provisioning with Powershell... +==> amazon-ebs: Provisioning with powershell script: /var/folders/15/d0f7gdg13rnd1cxp7tgmr55c0000gn/T/packer-powershell-provisioner175214995 + amazon-ebs: HELLO NEW USER; WELCOME TO PACKER +==> amazon-ebs: Restarting Machine +==> amazon-ebs: Waiting for machine to restart... + amazon-ebs: WIN-TEM0TDL751M restarted. +==> amazon-ebs: Machine successfully restarted, moving on +==> amazon-ebs: Provisioning with Powershell... +==> amazon-ebs: Provisioning with powershell script: ./sample_script.ps1 + amazon-ebs: PACKER_BUILD_NAME is automatically set for you, or you can set it in your builder variables; The default for this builder is: amazon-ebs + amazon-ebs: Use backticks as the escape character when required in powershell: + amazon-ebs: For example, VAR1 from our config is: A$Dollar + amazon-ebs: Likewise, VAR2 is: A`Backtick + amazon-ebs: Finally, VAR3 is: A'SingleQuote +==> amazon-ebs: Stopping the source instance... + amazon-ebs: Stopping instance, attempt 1 +==> amazon-ebs: Waiting for the instance to stop... +==> amazon-ebs: Creating the AMI: packer-demo-1507933843 + amazon-ebs: AMI: ami-100fc56a +==> amazon-ebs: Waiting for AMI to become ready... +==> amazon-ebs: Terminating the source AWS instance... +==> amazon-ebs: Cleaning up any extra volumes... +==> amazon-ebs: No volumes to clean up, skipping +==> amazon-ebs: Deleting temporary security group... +==> amazon-ebs: Deleting temporary keypair... +Build 'amazon-ebs' finished. + +==> Builds finished. The artifacts of successful builds are: +--> amazon-ebs: AMIs were created: +us-east-1: ami-100fc56a +``` + +And if you navigate to your EC2 dashboard you should see your shiny new AMI +listed in the main window of the Images -> AMIs section. + +Why stop there though? + +As you'll see, with one simple change to the template above, it's +just as easy to create your own Windows 2008 or Windows 2016 AMIs. Just +set the value for the name field within `source_ami_filter` as required: + +For Windows 2008 SP2: + +``` + "name": "*Windows_Server-2008-SP2*English-64Bit-Base*", +``` + +For Windows 2016: + +``` + "name": "*Windows_Server-2016-English-Full-Base*", +``` + +The bootstrapping and sample provisioning should work the same across all +Windows server versions. + [platforms]: /docs/builders/index.html diff --git a/website/source/layouts/community.erb b/website/source/layouts/community.erb new file mode 100644 index 000000000..a5ab417c3 --- /dev/null +++ b/website/source/layouts/community.erb @@ -0,0 +1,19 @@ +<% wrap_layout :inner do %> + <% content_for :sidebar do %> + + <% end %> + + <%= yield %> +<% end %> diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index 1ceb2a276..9aa17ccc4 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -111,6 +111,9 @@ > ISO + > + VMCX + > @@ -199,9 +202,6 @@ > File - > - LXD - > PowerShell diff --git a/website/source/layouts/downloads.erb b/website/source/layouts/downloads.erb index 9e9a79632..e6a328f41 100644 --- a/website/source/layouts/downloads.erb +++ b/website/source/layouts/downloads.erb @@ -6,10 +6,6 @@ Download Packer - > - Community Tools - -
  • Build from Source