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 --gcp-project-id (default: false, required if building for GCP)
38 --gcp-account-file (default: false, required if building for GCP)
40 --gcp-zone (default: us-central1-f)
42 --azure-secrets-file (default: false, required if building for Azure)
43 Azure secrets file which will be sourced from this script
44 --azure-resource-group (default: false, required if building for Azure)
46 --azure-location (default: false, required if building for Azure)
47 Azure location, e.g. centralus, eastus, westeurope
48 --azure-sku (default: unset, required if building for Azure, e.g. 16.04-LTS)
49 Azure SKU image to use
50 --ssh_user (default: packer)
51 The user packer will use to log into the image
52 --domain (default: arvadosapi.com)
53 The domain part of the FQDN for the cluster
54 --resolver (default: 8.8.8.8)
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
61 Output debug information (default: false)
78 AZURE_CLOUD_ENVIRONMENT=
81 DOMAIN="arvadosapi.com"
82 AWS_DEFAULT_REGION=us-east-1
85 PARSEDOPTS=$(getopt --name "$0" --longoptions \
86 help,json-file:,arvados-cluster-id:,aws-source-ami:,aws-profile:,aws-secrets-file:,aws-region:,aws-vpc-id:,aws-subnet-id:,gcp-project-id:,gcp-account-file:,gcp-zone:,azure-secrets-file:,azure-resource-group:,azure-location:,azure-sku:,azure-cloud-environment:,ssh_user:,domain:,resolver:,reposuffix:,public-key-file:,debug \
92 eval set -- "$PARSEDOPTS"
93 while [ $# -gt 0 ]; do
96 echo >&2 "$helpmessage"
101 JSON_FILE="$2"; shift
103 --arvados-cluster-id)
104 ARVADOS_CLUSTER_ID="$2"; shift
107 AWS_SOURCE_AMI="$2"; shift
110 AWS_PROFILE="$2"; shift
113 AWS_SECRETS_FILE="$2"; shift
116 AWS_DEFAULT_REGION="$2"; shift
119 AWS_VPC_ID="$2"; shift
122 AWS_SUBNET_ID="$2"; shift
125 GCP_PROJECT_ID="$2"; shift
128 GCP_ACCOUNT_FILE="$2"; shift
133 --azure-secrets-file)
134 AZURE_SECRETS_FILE="$2"; shift
136 --azure-resource-group)
137 AZURE_RESOURCE_GROUP="$2"; shift
140 AZURE_LOCATION="$2"; shift
143 AZURE_SKU="$2"; shift
145 --azure-cloud-environment)
146 AZURE_CLOUD_ENVIRONMENT="$2"; shift
158 REPOSUFFIX="$2"; shift
161 PUBLIC_KEY_FILE="$2"; shift
164 # If you want to debug a build issue, add the -debug flag to the build
165 # command in question.
166 # This will allow you to ssh in, if you use the .pem file that packer
167 # generates in this directory as the ssh key. The base image uses the admin
168 # user and ssh port 22.
172 if [ $# -gt 1 ]; then
173 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
182 if [[ "$JSON_FILE" == "" ]] || [[ ! -f "$JSON_FILE" ]]; then
183 echo >&2 "$helpmessage"
185 echo >&2 "ERROR: packer json file not found"
190 if [[ -z "$ARVADOS_CLUSTER_ID" ]]; then
191 echo >&2 "$helpmessage"
193 echo >&2 "ERROR: arvados cluster id not specified"
198 if [[ "$PUBLIC_KEY_FILE" == "" ]] || [[ ! -f "$PUBLIC_KEY_FILE" ]]; then
199 echo >&2 "$helpmessage"
201 echo >&2 "ERROR: public key file file not found"
206 if [[ ! -z "$AWS_SECRETS_FILE" ]]; then
207 source $AWS_SECRETS_FILE
210 if [[ ! -z "$AZURE_SECRETS_FILE" ]]; then
211 source $AZURE_SECRETS_FILE
214 FQDN=" -var fqdn=compute.$ARVADOS_CLUSTER_ID.$DOMAIN ";
218 if [[ "$AWS_SOURCE_AMI" != "" ]]; then
219 EXTRA2+=" -var aws_source_ami=$AWS_SOURCE_AMI"
221 if [[ "$AWS_PROFILE" != "" ]]; then
222 EXTRA2+=" -var aws_profile=$AWS_PROFILE"
224 if [[ "$AWS_VPC_ID" != "" ]]; then
225 EXTRA2+=" -var vpc_id=$AWS_VPC_ID -var associate_public_ip_address=true "
227 if [[ "$AWS_SUBNET_ID" != "" ]]; then
228 EXTRA2+=" -var subnet_id=$AWS_SUBNET_ID -var associate_public_ip_address=true "
230 if [[ "$AWS_DEFAULT_REGION" != "" ]]; then
231 EXTRA2+=" -var aws_default_region=$AWS_DEFAULT_REGION"
233 if [[ "$GCP_PROJECT_ID" != "" ]]; then
234 EXTRA2+=" -var project_id=$GCP_PROJECT_ID"
236 if [[ "$GCP_ACCOUNT_FILE" != "" ]]; then
237 EXTRA2+=" -var account_file=$GCP_ACCOUNT_FILE"
239 if [[ "$GCP_ZONE" != "" ]]; then
240 EXTRA2+=" -var zone=$GCP_ZONE"
242 if [[ "$AZURE_RESOURCE_GROUP" != "" ]]; then
243 EXTRA2+=" -var resource_group=$AZURE_RESOURCE_GROUP"
245 if [[ "$AZURE_LOCATION" != "" ]]; then
246 EXTRA2+=" -var location=$AZURE_LOCATION"
248 if [[ "$AZURE_SKU" != "" ]]; then
249 EXTRA2+=" -var image_sku=$AZURE_SKU"
251 if [[ "$AZURE_CLOUD_ENVIRONMENT" != "" ]]; then
252 EXTRA2+=" -var cloud_environment_name=$AZURE_CLOUD_ENVIRONMENT"
254 if [[ "$SSH_USER" != "" ]]; then
255 EXTRA2+=" -var ssh_user=$SSH_USER"
257 if [[ "$RESOLVER" != "" ]]; then
258 EXTRA2+=" -var resolver=$RESOLVER"
260 if [[ "$REPOSUFFIX" != "" ]]; then
261 EXTRA2+=" -var reposuffix=$REPOSUFFIX"
263 if [[ "$PUBLIC_KEY_FILE" != "" ]]; then
264 EXTRA2+=" -var public_key_file=$PUBLIC_KEY_FILE"
267 echo packer build$EXTRA$FQDN -var "role=$role" -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE
268 packer build$EXTRA$FQDN -var "role=$role" -var "arvados_cluster=$ARVADOS_CLUSTER_ID"$EXTRA2 $JSON_FILE