use a vcs project that will work
This commit is contained in:
parent
97bacf6790
commit
532c4a4973
|
@ -6,15 +6,32 @@ page_title: Build a VirtualBox Image with Packer in TeamCity
|
|||
|
||||
# Build a VirtualBox Image with Packer in TeamCity
|
||||
|
||||
This guide walks through the process of building a VirtualBox image using Packer on a new TeamCity Agent. Before getting started you should have access to a TeamCity Server.
|
||||
This guide walks through the process of building a VirtualBox image using
|
||||
Packer on a new TeamCity Agent. Before getting started you should have access
|
||||
to a TeamCity Server.
|
||||
|
||||
The Packer VirtualBox builder requires access to VirtualBox, which needs to run on a bare-metal machine as virtualization is generally not supported on cloud instances. This is also true for the [VMWare](/docs/builders/vmware.html) and the [QEMU](/docs/builders/qemu.html) Packer builders.
|
||||
The Packer VirtualBox builder requires access to VirtualBox, which needs to run
|
||||
on a bare-metal machine, as virtualization is generally not supported on cloud
|
||||
instances. This is also true for the [VMWare](/docs/builders/vmware.html) and
|
||||
the [QEMU](/docs/builders/qemu.html) Packer builders.
|
||||
|
||||
We will use Chef's [Bento boxes](https://github.com/chef/bento) to provision an
|
||||
Ubuntu image on VirtualBox. We will use a fork of this repository as the
|
||||
project we will build.
|
||||
|
||||
## 1. Provision a Bare-metal Machine
|
||||
|
||||
The Packer VirtualBox builder requires running on bare-metal (hardware). If you do not have access to a bare-metal machine, we recommend using [Packet.net](https://www.packet.net/) to obtain a new machine. If you are a first time user of Packet.net, the Packet.net team has provided HashiCorp the coupon code `hash25` which you can use for $25 off to test out this guide. You can use a `baremetal_0` for testing, but for regular use the `baremetal_1` instance may be a better option.
|
||||
The Packer VirtualBox builder requires running on bare-metal (hardware). If you
|
||||
do not have access to a bare-metal machine, we recommend using
|
||||
[Packet.net](https://www.packet.net/) to obtain a new machine. If you are
|
||||
a first time user of Packet.net, the Packet.net team has provided HashiCorp the
|
||||
coupon code `hash25` which you can use for $25 off to test out this guide. You
|
||||
can use a `baremetal_0` server type for testing, but for regular use, the
|
||||
`baremetal_1` instance may be a better option.
|
||||
|
||||
There is also a [Packet Provider](https://www.terraform.io/docs/providers/packet/index.html) in Terraform you can use to provision the project and instance.
|
||||
There is also a [Packet
|
||||
Provider](https://www.terraform.io/docs/providers/packet/index.html) in
|
||||
Terraform you can use to provision the project and instance.
|
||||
|
||||
```hcl
|
||||
provider "packet" { }
|
||||
|
@ -35,7 +52,9 @@ resource "packet_device" "agent" {
|
|||
|
||||
## 2. Install VirtualBox and TeamCity dependencies
|
||||
|
||||
VirtualBox must be installed on the new instance, and TeamCity requires the JDK prior to installation. This guide uses Ubuntu as the Linux distribution, so you may need to adjust these commands for your distribution of choice.
|
||||
VirtualBox must be installed on the new instance, and TeamCity requires the JDK
|
||||
prior to installation. This guide uses Ubuntu as the Linux distribution, so you
|
||||
may need to adjust these commands for your distribution of choice.
|
||||
|
||||
**Install Teamcity Dependencies**
|
||||
|
||||
|
@ -51,28 +70,41 @@ curl -OL "http://download.virtualbox.org/virtualbox/5.2.2/virtualbox-5.2_5.2.2-1
|
|||
dpkg -i virtualbox-5.2_5.2.2-119230~Ubuntu~xenial_amd64.deb
|
||||
```
|
||||
|
||||
You can also use the [`remote-exec` provisioner](https://www.terraform.io/docs/provisioners/remote-exec.html) in your Terraform configuration to automatically run these commands when provisioning the new instance.
|
||||
You can also use the [`remote-exec`
|
||||
provisioner](https://www.terraform.io/docs/provisioners/remote-exec.html) in
|
||||
your Terraform configuration to automatically run these commands when
|
||||
provisioning the new instance.
|
||||
|
||||
## 3. Install Packer
|
||||
|
||||
The TeamCity Agent machine will also need Packer Installed. You can find the latest download link from the [Packer Download](https://www.packer.io/downloads.html) page.
|
||||
The TeamCity Agent machine will also need Packer Installed. You can find the
|
||||
latest download link from the [Packer
|
||||
Download](https://www.packer.io/downloads.html) page.
|
||||
|
||||
```shell
|
||||
curl -OL "https://releases.hashicorp.com/packer/1.1.2/packer_1.1.2_linux_amd64.zip"
|
||||
unzip ./packer_1.1.2_linux_amd64.zip
|
||||
```
|
||||
|
||||
Packer is installed at the `/root/packer` path which is used in subsequent steps. If it is installed elsewhere, take note of the path.
|
||||
Packer is installed at the `/root/packer` path which is used in subsequent
|
||||
steps. If it is installed elsewhere, take note of the path.
|
||||
|
||||
## 4. Install TeamCity Agent
|
||||
|
||||
This guide assume you already have a running instance of TeamCity Server. The new TeamCity Agent can be installed by [downloading a zip file and installing manually](https://confluence.jetbrains.com/display/TCD10//Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-InstallingAdditionalBuildAgents), or using [Agent Push](https://confluence.jetbrains.com/display/TCD10//Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-InstallingviaAgentPush). Once it is installed it should appear in TeamCity as a new Agent.
|
||||
This guide assume you already have a running instance of TeamCity Server. The
|
||||
new TeamCity Agent can be installed by [downloading a zip file and installing
|
||||
manually](https://confluence.jetbrains.com/display/TCD10//Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-InstallingAdditionalBuildAgents),
|
||||
or using [Agent
|
||||
Push](https://confluence.jetbrains.com/display/TCD10//Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-InstallingviaAgentPush).
|
||||
Once it is installed it should appear in TeamCity as a new Agent.
|
||||
|
||||
Create a new Agent Pool for agents responsible for VirtualBox Packer builds and assign the new Agent to it.
|
||||
Create a new Agent Pool for agents responsible for VirtualBox Packer builds and
|
||||
assign the new Agent to it.
|
||||
|
||||
## 5. Create a New Build in TeamCity
|
||||
|
||||
In TeamCity Server create a new build and configure the Version Control Settings to download the Packer build configuration from the VCS repository.
|
||||
In TeamCity Server, create a new build, and configure the Version Control
|
||||
Settings to download the Packer build configuration from the VCS repository.
|
||||
|
||||
Add one **Build Step: Command Line** to the build.
|
||||
|
||||
|
@ -82,14 +114,24 @@ In the **Script content** field add the following:
|
|||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
/root/packer build -only=virtualbox-iso -var "headless=true" ./packer.json
|
||||
/root/packer build -only=virtualbox-iso -var "headless=true" ubuntu/ubuntu-16.04-amd64.json
|
||||
```
|
||||
|
||||
This will use the `build` command in Packer to build the image defined in `./packer.json`. It assumes that `packer.json` is the Packer build configuration file in the root path of the VCS repository. Packer defaults to building VirtualBox virtual machines by launching a GUI that shows the console, since this will run in CI/CD, the the [`headless` variable](/docs/builders/virtualbox-iso.html#headless) instructs Packer to start the machine without the console. Packer can build multiple image types, so the [`-only=virtualbox-iso` option](/docs/commands/build.html#only-foo-bar-baz) instructs Packer to only build the builds with the name `virtualbox-iso`.
|
||||
This will use the `build` command in Packer to build the image defined in
|
||||
`ubuntu/ubuntu-16.04-amd64.json`. It assumes that the VCS repository you're
|
||||
using is a fork of [Chef/Bento](https://github.com/chef/bento). Packer defaults
|
||||
to building VirtualBox machines by launching a GUI that shows the console.
|
||||
Since this will run in CI/CD, use the [`headless`
|
||||
variable](/docs/builders/virtualbox-iso.html#headless) to instruct Packer to
|
||||
start the machine without the console. Packer can build multiple image types,
|
||||
so the [`-only=virtualbox-iso`
|
||||
option](/docs/commands/build.html#only-foo-bar-baz) instructs Packer to only
|
||||
build the builds with the name `virtualbox-iso`.
|
||||
|
||||
## 6. Run a build in TeamCity
|
||||
|
||||
The entire configuration is ready for a new build. Start a new run in TeamCity by pressing “Run”.
|
||||
The entire configuration is ready for a new build. Start a new run in TeamCity
|
||||
by pressing “Run”.
|
||||
|
||||
The new run should be triggered and the virtual box image will be built.
|
||||
|
||||
|
|
Loading…
Reference in New Issue