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