github.com/cptmikhailov/conmon@v2.0.20+incompatible/contrib/cirrus/packer/Makefile (about)

     1  
     2  PACKER_VER ?= 1.3.5
     3  PACKER_DIST_FILENAME := packer_${PACKER_VER}_linux_amd64.zip
     4  
     5  # Only needed for conmon_base_images target
     6  TIMESTAMP := $(shell date +%s)
     7  SRC ?= $(shell realpath "./../../../")
     8  PACKER_BASE ?= ./contrib/cirrus/packer
     9  SCRIPT_BASE ?= ./contrib/cirrus
    10  
    11  # For debugging nested-virt, use
    12  #TTYDEV := $(shell tty)
    13  TTYDEV := /dev/null
    14  
    15  .PHONY: all
    16  all: conmon_images
    17  
    18  %.json: %.yml
    19  	@python3 -c 'import json,yaml; json.dump( yaml.load(open("$<").read()), open("$@","w"), indent=2);'
    20  
    21  ${PACKER_DIST_FILENAME}:
    22  	@curl -L --silent --show-error \
    23  		-O https://releases.hashicorp.com/packer/${PACKER_VER}/${PACKER_DIST_FILENAME}
    24  
    25  packer: ${PACKER_DIST_FILENAME}
    26  	@curl -L --silent --show-error \
    27  		https://releases.hashicorp.com/packer/${PACKER_VER}/packer_${PACKER_VER}_SHA256SUMS \
    28  		| grep 'linux_amd64' > /tmp/packer_sha256sums
    29  	@sha256sum --check /tmp/packer_sha256sums
    30  	@unzip -o ${PACKER_DIST_FILENAME}
    31  	@touch --reference=Makefile ${PACKER_DIST_FILENAME}
    32  
    33  .PHONY: test
    34  test: conmon_base_images.json conmon_images.json packer
    35  	./packer inspect conmon_base_images.json > /dev/null
    36  	./packer inspect conmon_images.json > /dev/null
    37  	@echo "All good"
    38  
    39  .PHONY: check_common_env
    40  check_common_env:
    41  ifndef SRC
    42  	$(error SRC is undefined, expected complete path to repository source directory.)
    43  endif
    44  ifndef SCRIPT_BASE
    45  	$(error SCRIPT_BASE is undefined, expected relative path to cirrus scripts directory.)
    46  endif
    47  ifndef PACKER_BASE
    48  	$(error PACKER_BASE is undefined, expected relative path to packer directory.)
    49  endif
    50  ifndef PACKER_VER
    51  	$(error PACKER_VER is undefined, expected string version number of packer to use.)
    52  endif
    53  ifndef PACKER_BUILDS
    54  	$(error PACKER_BUILDS is undefined, expected CSV of builders to utilize.)
    55  endif
    56  ifndef GCP_PROJECT_ID
    57  	$(error GCP_PROJECT_ID is undefined, expected complete GCP project ID string e.g. foobar-12345.)
    58  endif
    59  
    60  .PHONY: cache_image_checkenv
    61  cache_image_checkenv: check_common_env
    62  ifndef GCE_SSH_USERNAME
    63  	$(error GCE_SSH_USERNAME is undefined, expected user with ssh access to base-image.)
    64  endif
    65  ifndef SERVICE_ACCOUNT
    66  	$(error SERVICE_ACCOUNT is undefined, expected GCE service account name for managing VMs.)
    67  endif
    68  ifndef BUILT_IMAGE_SUFFIX
    69  	$(error BUILT_IMAGE_SUFFIX is undefined, expected suffix string to make produced image names unique.)
    70  endif
    71  ifndef CRIO_REPO
    72  	$(error CRIO_REPO is undefined, expected URL to CRI-O repository to use)
    73  endif
    74  ifndef CRIO_SLUG
    75  	$(error CRIO_SLUG is undefined, expected GOPATH/src/ subdirectory to use for CRI-O.)
    76  endif
    77  ifndef FEDORA_BASE_IMAGE
    78  	$(error FEDORA_BASE_IMAGE is undefined, expected name of existing base-image.)
    79  endif
    80  
    81  .PHONY: base_image_checkenv
    82  base_image_checkenv: check_common_env
    83  ifndef TIMESTAMP
    84  	$(error TIMESTAMP is undefined, expected unix epoch.)
    85  endif
    86  ifndef GOOGLE_APPLICATION_CREDENTIALS
    87  	$(error GOOGLE_APPLICATION_CREDENTIALS is undefined, expected path to JSON file.  See https://cloud.google.com/docs/authentication/end-user#creating_your_client_credentials)
    88  endif
    89  
    90  .PHONY: conmon_images
    91  conmon_images: cache_image_checkenv conmon_images.json packer
    92  	@GCE_SSH_USERNAME=${GCE_SSH_USERNAME} \
    93  	GCP_PROJECT_ID=${GCP_PROJECT_ID} \
    94  	SERVICE_ACCOUNT="${SERVICE_ACCOUNT}" \
    95  	./packer build -only=${PACKER_BUILDS} \
    96  		-var SRC=${SRC} \
    97  		-var SCRIPT_BASE=${SCRIPT_BASE} \
    98  		-var PACKER_BASE=${PACKER_BASE} \
    99  		-var BUILT_IMAGE_SUFFIX=${BUILT_IMAGE_SUFFIX} \
   100  		-var CRIO_REPO=${CRIO_REPO} \
   101  		-var CRIO_SLUG=${CRIO_SLUG} \
   102  		-var FEDORA_BASE_IMAGE=${FEDORA_BASE_IMAGE} \
   103  		conmon_images.json
   104  	@echo ""
   105  	@echo "Finished.  The images mentioned above, and in packer-manifest.json"
   106  	@echo "can be used in .cirrus.yml as values for the 'image_name' keys"
   107  	@echo ""
   108  
   109  
   110  
   111  cidata.ssh:
   112  	ssh-keygen -f $@ -P "" -q
   113  
   114  cidata.ssh.pub: cidata.ssh
   115  	touch $@
   116  
   117  meta-data:
   118  	echo "local-hostname: localhost.localdomain" > $@
   119  
   120  user-data: cidata.ssh.pub
   121  	bash make-user-data.sh
   122  
   123  cidata.iso: user-data meta-data
   124  	genisoimage -output cidata.iso -volid cidata -input-charset utf-8 -joliet -rock user-data meta-data
   125  
   126  # This is intended to be run by a human, with admin access to the conmon GCE project.
   127  .PHONY: conmon_base_images
   128  conmon_base_images: base_image_checkenv conmon_base_images.json cidata.iso cidata.ssh packer
   129  	@PACKER_CACHE_DIR=/tmp \
   130  	GOOGLE_APPLICATION_CREDENTIALS="${GOOGLE_APPLICATION_CREDENTIALS}" \
   131  	GCP_PROJECT_ID=${GCP_PROJECT_ID} \
   132  		./packer build \
   133  			-var TIMESTAMP=${TIMESTAMP} \
   134  			-var TTYDEV=${TTYDEV} \
   135  			-var SRC=${SRC} \
   136  			-var PACKER_BASE=${PACKER_BASE} \
   137  			-var SCRIPT_BASE=${SCRIPT_BASE} \
   138  			-only ${PACKER_BUILDS} \
   139  			conmon_base_images.json
   140  	@echo ""
   141  	@echo "Finished.  The images mentioned above, and in packer-manifest.json"
   142  	@echo "can be used in .cirrus.yml as values for the *_BASE_IMAGE keys."
   143  	@echo ""