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