xref: /freebsd/release/Makefile.azure (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#
2#
3#
4# Makefile for uploading Microsoft Azure disk images.
5#
6
7AZURE_IMG?=		${.OBJDIR}/azure.vhdf
8AZURE_UPLOAD_TGTS=	azure-check-depends \
9			azure-do-upload
10CLEANFILES+=		${AZURE_UPLOAD_TGTS}
11
12.if defined(AZURE_UPLOAD_CONF) && !empty(AZURE_UPLOAD_CONF)
13. for VAR in _STORAGE _ACCOUNT _KEY
14AZURE${VAR}!=	grep -E '^AZURE${VAR}' ${AZURE_UPLOAD_CONF} | awk -F '	' '{print $$2}'
15. endfor
16.endif
17
18.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE"
19SNAPSHOT_DATE!=		date +-${BUILDDATE}
20.endif
21
22AZURE_TARGET:=		${OSRELEASE}${SNAPSHOT_DATE}
23
24START_DATE!=	date -v-1d -I -u
25EXPIRY_DATE!=	date -v+1m -I -u
26
27azure-upload:		${AZURE_UPLOAD_TGTS}
28
29azure-check-depends:
30.for VAR in _STORAGE _ACCOUNT _KEY
31. if !defined(AZURE${VAR}) || empty(AZURE${VAR})
32	@echo "Variable AZURE${VAR} cannot be empty."
33	@false
34. endif
35.endfor
36.if !exists(/usr/local/bin/az)
37. if !exists(${PORTSDIR}/sysutils/py-azure-cli/Makefile)
38.  if !exists(/usr/local/sbin/pkg-static)
39	env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
40.  endif
41	env ASSUME_ALWAYS_YES=yes pkg install -y py38-azure-cli
42. else
43	env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/sysutils/py-azure-cli BATCH=1 all install clean
44. endif
45.endif
46
47azure-do-upload:
48	/usr/local/bin/az storage blob upload \
49		--account-name ${AZURE_ACCOUNT} --account-key ${AZURE_KEY} \
50		--container-name ${AZURE_STORAGE} --type page \
51		--file ${AZURE_IMG} --name ${AZURE_TARGET}.vhd
52	@echo "The disk access URL with shared access signature is:"
53	@echo
54	@echo -n https://${AZURE_ACCOUNT}.blob.core.windows.net/${AZURE_STORAGE}/${AZURE_TARGET}.vhd?
55	@/usr/local/bin/az storage container generate-sas \
56		--account-name ${AZURE_ACCOUNT} --account-key ${AZURE_KEY} \
57		--name ${AZURE_STORAGE} \
58		--permissions lr \
59		--start ${START_DATE} \
60		--expiry ${EXPIRY_DATE} | cut -d '"' -f 2
61	@echo
62	@echo "Please go to Microsoft Partner Center to create a new offer and publish it:"
63	@echo
64	@echo "https://partner.microsoft.com/dashboard/commercial-marketplace/overview"
65	@echo
66	@echo "After the new offer status is live, you can delete the disk file with:"
67	@echo
68	@echo /usr/local/bin/az storage blob delete \
69		--account-name ${AZURE_ACCOUNT} --account-key ${AZURE_KEY} \
70		--container-name ${AZURE_STORAGE} --name ${AZURE_TARGET}.vhd
71	@echo
72