Skip to content

Commit

Permalink
update packer conf to HCL from JSON and update bazel version used in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
thundergolfer-two committed May 30, 2021
1 parent e0ef252 commit b997e12
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 44 deletions.
1 change: 1 addition & 0 deletions .bazelversion
@@ -0,0 +1 @@
4.1.0
23 changes: 0 additions & 23 deletions infrastructure/aws/ami/continuous_integration/packer-conf.json

This file was deleted.

63 changes: 63 additions & 0 deletions infrastructure/aws/ami/continuous_integration/packer-conf.pkr.hcl
@@ -0,0 +1,63 @@
# This file was autogenerated by the 'packer hcl2_upgrade' command. We
# recommend double checking that everything is correct before going forward. We
# also recommend treating this file as disposable. The HCL2 blocks in this
# file can be moved to other files. For example, the variable blocks could be
# moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
# suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
# once they also need to be in the same folder. 'packer inspect folder/'
# will describe to you what is in that folder.

# Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
# and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
# executed together and the outcome will be unknown.

# All generated input variables will be of 'string' type as this is how Packer JSON
# views them; you can change their type later on. Read the variables type
# constraints documentation
# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info.
variable "aws_access_key" {
type = string
}

variable "aws_secret_key" {
type = string
}

variable "bazel_version" {
type = string
}

variable "region" {
type = string
default = "us-east-2"
}

# "timestamp" template function replacement
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source. Read the documentation for source blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "amazon-ebs" "autogenerated_1" {
access_key = "${var.aws_access_key}"
ami_name = "continuous-integration ${local.timestamp}"
instance_type = "t2.small"
region = "us-east-2"
secret_key = "${var.aws_secret_key}"
source_ami = "ami-05512b79a46f1fabb"
ssh_username = "ec2-user"
}

# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
sources = ["source.amazon-ebs.autogenerated_1"]

provisioner "shell" {
environment_vars = [format("BAZEL_VERSION=%s", var.bazel_version)]
script = "./prepare.sh"
}

}
42 changes: 23 additions & 19 deletions infrastructure/aws/ami/continuous_integration/prepare.sh
Expand Up @@ -2,27 +2,31 @@

set -o errexit
set -o pipefail
set -o nounset

BAZEL_VERSION="3.3.0"
## Install Bazel and the other project's dependencies
main() {
local bazel_version
bazel_version="${BAZEL_VERSION}"

## Install Bazel's and Project's dependencies
# NOTE: Amazon Linux 2 uses 'yum' not 'apt-get'
sudo yum groupinstall -y "Development Tools"
sudo yum install -y zip unzip
# Copied from https://github.com/buildkite/elastic-ci-stack-for-aws/pull/583/files
sudo yum install -y python3-pip python3 python3-setuptools
sudo yum install -y java-1.8.0-openjdk-devel

# NOTE: Amazon Linux 2 uses 'yum' not 'apt-get'
sudo yum groupinstall -y "Development Tools"
sudo yum install -y zip unzip
# Copied from https://github.com/buildkite/elastic-ci-stack-for-aws/pull/583/files
sudo yum install -y python3-pip python3 python3-setuptools
sudo yum install -y java-1.8.0-openjdk-devel
# Install Node
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh" | bash
# shellcheck disable=SC1090
. ~/.nvm/nvm.sh
nvm install node

# Node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# shellcheck disable=SC1090
. ~/.nvm/nvm.sh
nvm install node
## Install Bazel from source
curl -sSL -O \
"https://github.com/bazelbuild/bazel/releases/download/${bazel_version}/bazel-${bazel_version}-installer-linux-x86_64.sh"
chmod +x "bazel-${bazel_version}-installer-linux-x86_64.sh"
sudo "./bazel-${bazel_version}-installer-linux-x86_64.sh"
}

## Install Bazel from source

curl -sSL -O \
"https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"
chmod +x "bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"
sudo "./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"
main "$@"
20 changes: 18 additions & 2 deletions infrastructure/aws/ami/continuous_integration/rebuild.sh
Expand Up @@ -4,7 +4,23 @@ set -o errexit
set -o nounset
set -o pipefail

packer build \
REPO_ROOT="$(git rev-parse --show-toplevel)"

main() {
local bazel_version
local bazelversion_dotfile_path

bazelversion_dotfile_path="${REPO_ROOT}/.bazelversion"
bazel_version="$(tr -d '\n' < "${bazelversion_dotfile_path}")"

cd "${REPO_ROOT}/infrastructure/aws/ami/continuous_integration/"

packer build \
-var "aws_access_key=${AWS_ACCESS_KEY_ID}" \
-var "aws_secret_key=${AWS_SECRET_ACCESS_KEY}" \
"packer-conf.json"
-var "bazel_version=${bazel_version}" \
"./packer-conf.pkr.hcl"
}


main "$@"

0 comments on commit b997e12

Please sign in to comment.