3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: Apache-2.0
12 read -rd "\000" helpmessage <<EOF
13 $(basename $0): Build cloud images for arvados-dispatch-cloud
16 $(basename $0) [options]
21 Path to the packer json file (required)
22 --arvados-cluster-id <xxxxx>
23 The ID of the Arvados cluster, e.g. zzzzz(required)
24 --aws-profile <profile>
25 AWS profile to use (valid profile from ~/.aws/config (optional)
26 --aws-secrets-file <path>
27 AWS secrets file which will be sourced from this script (optional)
28 When building for AWS, either an AWS profile or an AWS secrets file
30 --aws-source-ami <ami-xxxxxxxxxxxxxxxxx>
31 The AMI to use as base for building the images (required if building for AWS)
32 --aws-region <region> (default: us-east-1)
33 The AWS region to use for building the images
35 VPC id for AWS, if not specified packer will derive from the subnet id or pick the default one.
36 --aws-subnet-id <subnet-xxxxxxxxxxxxxxxxx>
37 Subnet id for AWS, if not specified packer will pick the default one for the VPC.
39 Install the AWS EBS autoscaler daemon (default: do not install the AWS EBS autoscaler).
40 --aws-associate-public-ip <true|false>
41 Associate a public IP address with the node used for building the compute image.
42 Required when the machine running packer can not reach the node used for building
43 the compute image via its private IP. (default: true if building for AWS)
44 Note: if the subnet has "Auto-assign public IPv4 address" enabled, disabling this
45 flag will have no effect.
46 --aws-ena-support <true|false>
47 Enable enhanced networking (default: true if building for AWS)
48 --gcp-project-id <project-id>
49 GCP project id (required if building for GCP)
50 --gcp-account-file <path>
51 GCP account file (required if building for GCP)
52 --gcp-zone <zone> (default: us-central1-f)
54 --azure-secrets-file <patch>
55 Azure secrets file which will be sourced from this script (required if building for Azure)
56 --azure-resource-group <resouce-group>
57 Azure resource group (required if building for Azure)
58 --azure-location <location>
59 Azure location, e.g. centralus, eastus, westeurope (required if building for Azure)
60 --azure-sku <sku> (required if building for Azure, e.g. 16.04-LTS)
61 Azure SKU image to use
62 --ssh_user <user> (default: packer)
63 The user packer will use to log into the image
64 --resolver <resolver_IP>
65 The dns resolver for the machine (default: host's network provided)
67 Set this to "-dev" to track the unstable/dev Arvados repositories
68 --public-key-file <path>
69 Path to the public key file that a-d-c will use to log into the compute node (required)
70 --mksquashfs-mem (default: 256M)
71 Only relevant when using Singularity. This is the amount of memory mksquashfs is allowed to use.
73 Install all the necessary tooling for Nvidia GPU support (default: do not install Nvidia GPU support)
75 Output debug information (default: no debug output is printed)
77 For more information, see the Arvados documentation at https://doc.arvados.org/install/crunch2-cloud/install-compute-node.html
89 AWS_ASSOCIATE_PUBLIC_IP=true
97 AZURE_CLOUD_ENVIRONMENT=
100 AWS_DEFAULT_REGION=us-east-1
105 PARSEDOPTS=$(getopt --name "$0" --longoptions \
106 help,json-file:,arvados-cluster-id:,aws-source-ami:,aws-profile:,aws-secrets-file:,aws-region:,aws-vpc-id:,aws-subnet-id:,aws-ebs-autoscale,aws-associate-public-ip:,aws-ena-support:,gcp-project-id:,gcp-account-file:,gcp-zone:,azure-secrets-file:,azure-resource-group:,azure-location:,azure-sku:,azure-cloud-environment:,ssh_user:,resolver:,reposuffix:,public-key-file:,mksquashfs-mem:,nvidia-gpu-support,debug \
108 if [ $? -ne 0 ]; then
112 eval set -- "$PARSEDOPTS"
113 while [ $# -gt 0 ]; do
116 echo >&2 "$helpmessage"
121 JSON_FILE="$2"; shift
123 --arvados-cluster-id)
124 ARVADOS_CLUSTER_ID="$2"; shift
127 AWS_SOURCE_AMI="$2"; shift
130 AWS_PROFILE="$2"; shift
133 AWS_SECRETS_FILE="$2"; shift
136 AWS_DEFAULT_REGION="$2"; shift
139 AWS_VPC_ID="$2"; shift
142 AWS_SUBNET_ID="$2"; shift
147 --aws-associate-public-ip)
148 AWS_ASSOCIATE_PUBLIC_IP="$2"; shift
151 AWS_ENA_SUPPORT="$2"; shift
154 GCP_PROJECT_ID="$2"; shift
157 GCP_ACCOUNT_FILE="$2"; shift
162 --azure-secrets-file)
163 AZURE_SECRETS_FILE="$2"; shift
165 --azure-resource-group)
166 AZURE_RESOURCE_GROUP="$2"; shift
169 AZURE_LOCATION="$2"; shift
172 AZURE_SKU="$2"; shift
174 --azure-cloud-environment)
175 AZURE_CLOUD_ENVIRONMENT="$2"; shift
184 REPOSUFFIX="$2"; shift
187 PUBLIC_KEY_FILE="$2"; shift
190 MKSQUASHFS_MEM="$2"; shift
192 --nvidia-gpu-support)
196 # If you want to debug a build issue, add the -debug flag to the build
197 # command in question.
198 # This will allow you to ssh in, if you use the .pem file that packer
199 # generates in this directory as the ssh key. The base image uses the admin
200 # user and ssh port 22.
204 if [ $# -gt 1 ]; then
205 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
214 if [[ -z "$JSON_FILE" ]] || [[ ! -f "$JSON_FILE" ]]; then
215 echo >&2 "$helpmessage"
217 echo >&2 "ERROR: packer json file not found"
222 if [[ -z "$ARVADOS_CLUSTER_ID" ]]; then
223 echo >&2 "$helpmessage"
225 echo >&2 "ERROR: arvados cluster id not specified"
230 if [[ -z "$PUBLIC_KEY_FILE" ]] || [[ ! -f "$PUBLIC_KEY_FILE" ]]; then
231 echo >&2 "$helpmessage"
233 echo >&2 "ERROR: public key file file not found"
238 if [[ ! -z "$AWS_SECRETS_FILE" ]]; then
239 source $AWS_SECRETS_FILE
242 if [[ ! -z "$AZURE_SECRETS_FILE" ]]; then
243 source $AZURE_SECRETS_FILE
250 if [[ -n "$AWS_SOURCE_AMI" ]]; then
251 EXTRA2+=" -var aws_source_ami=$AWS_SOURCE_AMI"
254 if [[ -n "$AWS_PROFILE" ]]; then
255 EXTRA2+=" -var aws_profile=$AWS_PROFILE"
258 if [[ -n "$AWS_VPC_ID" ]]; then
259 EXTRA2+=" -var vpc_id=$AWS_VPC_ID"
262 if [[ -n "$AWS_SUBNET_ID" ]]; then
263 EXTRA2+=" -var subnet_id=$AWS_SUBNET_ID"
266 if [[ -n "$AWS_DEFAULT_REGION" ]]; then
267 EXTRA2+=" -var aws_default_region=$AWS_DEFAULT_REGION"
270 if [[ -n "$AWS_EBS_AUTOSCALE" ]]; then
271 EXTRA2+=" -var aws_ebs_autoscale=$AWS_EBS_AUTOSCALE"
274 if [[ $AWS -eq 1 ]]; then
275 EXTRA2+=" -var aws_associate_public_ip_address=$AWS_ASSOCIATE_PUBLIC_IP"
276 EXTRA2+=" -var aws_ena_support=$AWS_ENA_SUPPORT"
278 if [[ -n "$GCP_PROJECT_ID" ]]; then
279 EXTRA2+=" -var project_id=$GCP_PROJECT_ID"
281 if [[ -n "$GCP_ACCOUNT_FILE" ]]; then
282 EXTRA2+=" -var account_file=$GCP_ACCOUNT_FILE"
284 if [[ -n "$GCP_ZONE" ]]; then
285 EXTRA2+=" -var zone=$GCP_ZONE"
287 if [[ -n "$AZURE_RESOURCE_GROUP" ]]; then
288 EXTRA2+=" -var resource_group=$AZURE_RESOURCE_GROUP"
290 if [[ -n "$AZURE_LOCATION" ]]; then
291 EXTRA2+=" -var location=$AZURE_LOCATION"
293 if [[ -n "$AZURE_SKU" ]]; then
294 EXTRA2+=" -var image_sku=$AZURE_SKU"
296 if [[ -n "$AZURE_CLOUD_ENVIRONMENT" ]]; then
297 EXTRA2+=" -var cloud_environment_name=$AZURE_CLOUD_ENVIRONMENT"
299 if [[ -n "$SSH_USER" ]]; then
300 EXTRA2+=" -var ssh_user=$SSH_USER"
302 if [[ -n "$RESOLVER" ]]; then
303 EXTRA2+=" -var resolver=$RESOLVER"
305 if [[ -n "$REPOSUFFIX" ]]; then
306 EXTRA2+=" -var reposuffix=$REPOSUFFIX"
308 if [[ -n "$PUBLIC_KEY_FILE" ]]; then
309 EXTRA2+=" -var public_key_file=$PUBLIC_KEY_FILE"
311 if [[ -n "$MKSQUASHFS_MEM" ]]; then
312 EXTRA2+=" -var mksquashfs_mem=$MKSQUASHFS_MEM"
314 if [[ -n "$NVIDIA_GPU_SUPPORT" ]]; then
315 EXTRA2+=" -var nvidia_gpu_support=$NVIDIA_GPU_SUPPORT"
318 GOVERSION=$(grep 'const goversion =' ../../lib/install/deps.go |awk -F'"' '{print $2}')
319 EXTRA2+=" -var goversion=$GOVERSION"
321 logfile=packer-$(date -Iseconds).log
326 echo packer build$EXTRA -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE | tee -a $logfile
327 packer build$EXTRA -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE 2>&1 | tee -a $logfile