-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (48 loc) · 1.73 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.ONESHELL:
SHELL:=/bin/bash
IMAGE="ghcr.io/xenitab/github-actions/tools:2023.12.1"
TEMP_ENV_FILE:=$(shell mktemp)
AZURE_CONFIG_DIR := $(if $(AZURE_CONFIG_DIR),$(AZURE_CONFIG_DIR),"$${HOME}/.azure")
TTY_OPTIONS=$(shell [ -t 0 ] && echo '-it')
TEMP_ENV_FILE:=$(shell mktemp)
DOCKER_RUN:=docker run $(TTY_OPTIONS) --env-file $(TEMP_ENV_FILE) -v $(AZURE_CONFIG_DIR):/work/.azure -v $${PWD}:/tmp $(IMAGE) packer
CLEANUP_COMMAND:=$(MAKE) --no-print-directory teardown TEMP_ENV_FILE=$(TEMP_ENV_FILE)
.PHONY: check-env
.SILENT: check-env
check-env:
ifndef PKR_VAR_version
$(error PKR_VAR_version is undefined)
endif
.PHONY: setup
.SILENT: setup
setup: check-env
set -e
mkdir -p $(AZURE_CONFIG_DIR)
export AZURE_CONFIG_DIR="$(AZURE_CONFIG_DIR)"
env | grep PKR_VAR_ >> $(TEMP_ENV_FILE)
if [ -z "$${PKR_VAR_subscription_id}" ]; then
echo PKR_VAR_subscription_id=$$(az account show -o tsv --query 'id') >> $(TEMP_ENV_FILE)
fi
.PHONY: teardown
.SILENT: teardown
teardown:
-rm -f $(TEMP_ENV_FILE)
.PHONY: azdo-agent
azdo-agent: setup
trap '$(CLEANUP_COMMAND)' EXIT
echo PKR_VAR_image_name=azdo-agent >> $(TEMP_ENV_FILE)
$(DOCKER_RUN) build /tmp/packer/azure/template.pkr.hcl
.PHONY: github-runner
github-runner: setup
trap '$(CLEANUP_COMMAND)' EXIT
echo PKR_VAR_image_name=github-runner >> $(TEMP_ENV_FILE)
$(DOCKER_RUN) build /tmp/packer/azure/template.pkr.hcl
.PHONY: validate
validate:
trap '$(CLEANUP_COMMAND)' EXIT
echo PKR_VAR_version=1.0.0 >> $(TEMP_ENV_FILE)
echo PKR_VAR_resource_group=rg-dev-we-images >> $(TEMP_ENV_FILE)
echo PKR_VAR_gallery_name=xkf >> $(TEMP_ENV_FILE)
echo PKR_VAR_image_name=azdo-agent >> $(TEMP_ENV_FILE)
echo PKR_VAR_subscription_id=12345 >> $(TEMP_ENV_FILE)
$(DOCKER_RUN) validate /tmp/packer/azure/template.pkr.hcl