Skip to content

Commit

Permalink
Merge pull request #628 from danbarr/update-packer
Browse files Browse the repository at this point in the history
Add init to Packer builder and bump versions
  • Loading branch information
haroonc authored Jul 17, 2023
2 parents 9f2a755 + 016b9d9 commit eb8cdb2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.14 AS build
FROM alpine:3.18 AS build

ARG PACKER_VERSION
ARG PACKER_VERSION_SHA256SUM
Expand Down
15 changes: 8 additions & 7 deletions packer/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Packer
# HashiCorp Packer

This build step invokes `packer` commands in [Google Cloud Build][cloud-build].
This build step invokes [HashiCorp Packer][packer] in [Google Cloud Build][cloud-build].

Arguments passed to this builder will be passed to [`packer`][packer] directly, allowing callers to
Arguments passed to this builder will be passed to `packer` directly, allowing callers to
run [any Packer command][packer-commands].

[cloud-build]: https://cloud.google.com/cloud-build

[packer]: https://www.packer.io

[packer-commands]: https://www.packer.io/docs/commands
[packer-commands]: https://developer.hashicorp.com/packer/docs/commands

## Building this Builder

Expand All @@ -20,10 +20,11 @@ your project. Run the following command in this directory:
gcloud builds submit .
```

> **Advanced builder building:** To specify a particular version of packer, provide the packer version
> number, and the checksum of that version's zip archive, as Cloud Build [substitutions][substitutions]:
> **Advanced builder building:** To specify a particular version of Packer, provide the Packer version
> number and the checksum of that version's linux/amd64 zip archive as Cloud Build
> [substitutions][substitutions]:
> ```
> gcloud builds submit --substitutions=_PACKER_VERSION=1.7.8,_PACKER_VERSION_SHA256SUM=8a94b84542d21b8785847f4cccc8a6da4c7be5e16d4b1a2d0a5f7ec5532faec0 .
> gcloud builds submit --substitutions=_PACKER_VERSION=1.9.1,_PACKER_VERSION_SHA256SUM=793ed62255b9e572eda0c77d2a770f5fde501314b7598320786f1e51feb260d6 .
> ```
[substitutions]: https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_user-defined_substitutions
Expand Down
6 changes: 3 additions & 3 deletions packer/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# In this directory, run the following command to build this builder.
# $ gcloud builds submit . --config=cloudbuild.yaml

# See docs at https://www.packer.io/docs/install/index.html
# See docs at https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli
steps:
- name: 'gcr.io/cloud-builders/wget'
args: ["https://releases.hashicorp.com/packer/${_PACKER_VERSION}/packer_${_PACKER_VERSION}_linux_amd64.zip"]
Expand All @@ -12,8 +12,8 @@ steps:
'--build-arg', 'PACKER_VERSION_SHA256SUM=${_PACKER_VERSION_SHA256SUM}',
'.']
substitutions:
_PACKER_VERSION: 1.7.8
_PACKER_VERSION_SHA256SUM: 8a94b84542d21b8785847f4cccc8a6da4c7be5e16d4b1a2d0a5f7ec5532faec0
_PACKER_VERSION: 1.9.1
_PACKER_VERSION_SHA256SUM: 793ed62255b9e572eda0c77d2a770f5fde501314b7598320786f1e51feb260d6

images:
- 'gcr.io/$PROJECT_ID/packer:latest'
Expand Down
4 changes: 2 additions & 2 deletions packer/examples/gce/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Packer GCE build

This directory contains an example that creates a GCE image using `packer`.
This directory contains an example that creates a GCE image using HashiCorp Packer.

Example Packer build is using [HCL2 syntax](https://www.packer.io/guides/hcl) and creates
Example Packer build is using [HCL2 syntax](https://developer.hashicorp.com/packer/guides/hcl) and creates
GCE image basing on Ubuntu Linux.

**Note**: This example assumes that you have built the `packer` build step and pushed it to
Expand Down
13 changes: 11 additions & 2 deletions packer/examples/gce/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
packer {
required_plugins {
googlecompute = {
version = ">= 1.1.1"
source = "github.com/hashicorp/googlecompute"
}
}
}

variable "project_id" {
type = string
}
Expand All @@ -12,9 +21,9 @@ variable "builder_sa" {

source "googlecompute" "test-image" {
project_id = var.project_id
source_image_family = "ubuntu-2104"
source_image_family = "ubuntu-2204-lts"
zone = var.zone
image_description = "Created with Packer from Cloudbuild"
image_description = "Created with HashiCorp Packer from Cloudbuild"
ssh_username = "root"
tags = ["packer"]
impersonate_service_account = var.builder_sa
Expand Down
5 changes: 5 additions & 0 deletions packer/examples/gce/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#
# See README.md for invocation instructions.
steps:
- name: 'gcr.io/$PROJECT_ID/packer'
args:
- init
- -var-file=variables.pkrvars.hcl
- build.pkr.hcl
- name: 'gcr.io/$PROJECT_ID/packer'
args:
- build
Expand Down

0 comments on commit eb8cdb2

Please sign in to comment.