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]
20 --json-file (required)
21 Path to the packer json file
22 --arvados-cluster-id (required)
23 The ID of the Arvados cluster, e.g. zzzzz
24 --aws-profile (default: false)
25 AWS profile to use (valid profile from ~/.aws/config
26 --aws-secrets-file (default: false, required if building for AWS)
27 AWS secrets file which will be sourced from this script
28 --aws-source-ami (default: false, required if building for AWS)
29 The AMI to use as base for building the images
30 --aws-region (default: us-east-1)
31 The AWS region to use for building the images
32 --aws-vpc-id (optional)
33 VPC id for AWS, otherwise packer will pick the default one
35 Subnet id for AWS otherwise packer will pick the default one for the VPC
36 --aws-ebs-autoscale (default: false)
37 Install the AWS EBS autoscaler daemon.
38 --gcp-project-id (default: false, required if building for GCP)
40 --gcp-account-file (default: false, required if building for GCP)
42 --gcp-zone (default: us-central1-f)
44 --azure-secrets-file (default: false, required if building for Azure)
45 Azure secrets file which will be sourced from this script
46 --azure-resource-group (default: false, required if building for Azure)
48 --azure-location (default: false, required if building for Azure)
49 Azure location, e.g. centralus, eastus, westeurope
50 --azure-sku (default: unset, required if building for Azure, e.g. 16.04-LTS)
51 Azure SKU image to use
52 --ssh_user (default: packer)
53 The user packer will use to log into the image
54 --resolver (default: host's network provided)
55 The dns resolver for the machine
56 --reposuffix (default: unset)
57 Set this to "-dev" to track the unstable/dev Arvados repositories
58 --public-key-file (required)
59 Path to the public key file that a-d-c will use to log into the compute node
60 --mksquashfs-mem (default: 256M)
61 Only relevant when using Singularity. This is the amount of memory mksquashfs is allowed to use.
63 Output debug information (default: false)
65 For more information, see the Arvados documentation at https://doc.arvados.org/install/crunch2-cloud/install-compute-node.html
83 AZURE_CLOUD_ENVIRONMENT=
86 AWS_DEFAULT_REGION=us-east-1
90 PARSEDOPTS=$(getopt --name "$0" --longoptions \
91 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,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:,debug \
97 eval set -- "$PARSEDOPTS"
98 while [ $# -gt 0 ]; do
101 echo >&2 "$helpmessage"
106 JSON_FILE="$2"; shift
108 --arvados-cluster-id)
109 ARVADOS_CLUSTER_ID="$2"; shift
112 AWS_SOURCE_AMI="$2"; shift
115 AWS_PROFILE="$2"; shift
118 AWS_SECRETS_FILE="$2"; shift
121 AWS_DEFAULT_REGION="$2"; shift
124 AWS_VPC_ID="$2"; shift
127 AWS_SUBNET_ID="$2"; shift
133 GCP_PROJECT_ID="$2"; shift
136 GCP_ACCOUNT_FILE="$2"; shift
141 --azure-secrets-file)
142 AZURE_SECRETS_FILE="$2"; shift
144 --azure-resource-group)
145 AZURE_RESOURCE_GROUP="$2"; shift
148 AZURE_LOCATION="$2"; shift
151 AZURE_SKU="$2"; shift
153 --azure-cloud-environment)
154 AZURE_CLOUD_ENVIRONMENT="$2"; shift
163 REPOSUFFIX="$2"; shift
166 PUBLIC_KEY_FILE="$2"; shift
169 MKSQUASHFS_MEM="$2"; shift
172 # If you want to debug a build issue, add the -debug flag to the build
173 # command in question.
174 # This will allow you to ssh in, if you use the .pem file that packer
175 # generates in this directory as the ssh key. The base image uses the admin
176 # user and ssh port 22.
180 if [ $# -gt 1 ]; then
181 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
190 if [[ -z "$JSON_FILE" ]] || [[ ! -f "$JSON_FILE" ]]; then
191 echo >&2 "$helpmessage"
193 echo >&2 "ERROR: packer json file not found"
198 if [[ -z "$ARVADOS_CLUSTER_ID" ]]; then
199 echo >&2 "$helpmessage"
201 echo >&2 "ERROR: arvados cluster id not specified"
206 if [[ -z "$PUBLIC_KEY_FILE" ]] || [[ ! -f "$PUBLIC_KEY_FILE" ]]; then
207 echo >&2 "$helpmessage"
209 echo >&2 "ERROR: public key file file not found"
214 if [[ ! -z "$AWS_SECRETS_FILE" ]]; then
215 source $AWS_SECRETS_FILE
218 if [[ ! -z "$AZURE_SECRETS_FILE" ]]; then
219 source $AZURE_SECRETS_FILE
225 if [[ -n "$AWS_SOURCE_AMI" ]]; then
226 EXTRA2+=" -var aws_source_ami=$AWS_SOURCE_AMI"
228 if [[ -n "$AWS_PROFILE" ]]; then
229 EXTRA2+=" -var aws_profile=$AWS_PROFILE"
231 if [[ -n "$AWS_VPC_ID" ]]; then
232 EXTRA2+=" -var vpc_id=$AWS_VPC_ID -var associate_public_ip_address=true "
234 if [[ -n "$AWS_SUBNET_ID" ]]; then
235 EXTRA2+=" -var subnet_id=$AWS_SUBNET_ID -var associate_public_ip_address=true "
237 if [[ -n "$AWS_DEFAULT_REGION" ]]; then
238 EXTRA2+=" -var aws_default_region=$AWS_DEFAULT_REGION"
240 if [[ -n "$AWS_EBS_AUTOSCALE" ]]; then
241 EXTRA2+=" -var aws_ebs_autoscale=$AWS_EBS_AUTOSCALE"
243 if [[ -n "$GCP_PROJECT_ID" ]]; then
244 EXTRA2+=" -var project_id=$GCP_PROJECT_ID"
246 if [[ -n "$GCP_ACCOUNT_FILE" ]]; then
247 EXTRA2+=" -var account_file=$GCP_ACCOUNT_FILE"
249 if [[ -n "$GCP_ZONE" ]]; then
250 EXTRA2+=" -var zone=$GCP_ZONE"
252 if [[ -n "$AZURE_RESOURCE_GROUP" ]]; then
253 EXTRA2+=" -var resource_group=$AZURE_RESOURCE_GROUP"
255 if [[ -n "$AZURE_LOCATION" ]]; then
256 EXTRA2+=" -var location=$AZURE_LOCATION"
258 if [[ -n "$AZURE_SKU" ]]; then
259 EXTRA2+=" -var image_sku=$AZURE_SKU"
261 if [[ -n "$AZURE_CLOUD_ENVIRONMENT" ]]; then
262 EXTRA2+=" -var cloud_environment_name=$AZURE_CLOUD_ENVIRONMENT"
264 if [[ -n "$SSH_USER" ]]; then
265 EXTRA2+=" -var ssh_user=$SSH_USER"
267 if [[ -n "$RESOLVER" ]]; then
268 EXTRA2+=" -var resolver=$RESOLVER"
270 if [[ -n "$REPOSUFFIX" ]]; then
271 EXTRA2+=" -var reposuffix=$REPOSUFFIX"
273 if [[ -n "$PUBLIC_KEY_FILE" ]]; then
274 EXTRA2+=" -var public_key_file=$PUBLIC_KEY_FILE"
276 if [[ -n "$MKSQUASHFS_MEM" ]]; then
277 EXTRA2+=" -var mksquashfs_mem=$MKSQUASHFS_MEM"
283 echo packer build$EXTRA -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE
284 packer build$EXTRA -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE