xref: /freebsd/release/Makefile.gce (revision 6f1af0d7d2af54b339b5212434cd6d4fda628d80)
1#
2#
3#
4# Makefile for uploading Google Compute Engine disk images.
5#
6
7GCE_UPLOAD_TGTS=	gce-check-depends \
8			gce-do-package \
9			gce-do-upload
10# I do not yet have a better way to deal with the "must be run interactively"
11# thing, so this is a fail-safe "do not do anything."
12.if !defined(GCE_LOGIN_SKIP) || empty(GCE_LOGIN_SKIP)
13GCE_UPLOAD_TGTS=	gce-do-login
14.endif
15CLEANFILES+=		${GCE_UPLOAD_TGTS}
16
17GCE_BUCKET?=
18GCE_LICENSE?=
19
20.if !defined(GCE_FAMILY) || empty(GCE_FAMILY)
21GCE_FAMILY=		${TYPE:tl}-${REVISION:S,.,-,}
22.endif
23
24.if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE"
25SNAPSHOT_DATE=		-v${BUILDDATE}
26GCE_FAMILY_SUFX=	-snap
27.endif
28
29gce-upload:		${GCE_UPLOAD_TGTS}
30
31gce-check-depends:
32.for VAR in _BUCKET
33. if !defined(GCE${VAR}) || empty(GCE${VAR})
34	@echo "Variable GCE${VAR} cannot be empty."
35	@false
36. endif
37.endfor
38.if !exists(/usr/local/bin/gcloud)
39. if !exists(${PORTSDIR}/net/google-cloud-sdk/Makefile)
40.  if !exists(/usr/local/sbin/pkg-static)
41	env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
42.  endif
43	env ASSUME_ALWAYS_YES=yes pkg install -y net/google-cloud-sdk \
44		lang/python
45. else
46	env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/net/google-cloud-sdk BATCH=1 all install clean
47	env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/lang/python BATCH=1 all install clean
48. endif
49.endif
50
51gce-do-login:
52	@echo "This requires human interaction, which is not yet supported."
53	@true
54
55.for _FS in ${GCE_FSLIST}
56GCE_IMG_${FS}=		${.OBJDIR}/gce.${_FS}.raw
57# Really?  Uppercase characters are not allowed?  Sigh...
58# And don't even get me started on the '.'.
59GCE_TARGET_${_FS}=	${OSRELEASE:S,.raw,,:tl:S,.,-,g}-${_FS}${SNAPSHOT_DATE}
60
61gce-do-package-${_FS}:
62	@# Yes, really...  Sigh.
63	cd ${.OBJDIR} && mv ${GCE_IMG_${_FS}} disk.raw
64	cd ${.OBJDIR} && tar --format=gnutar -zcf \
65		${GCE_TARGET_${_FS}:S,${.OBJDIR}/,,}.tar.gz disk.raw
66	cd ${.OBJDIR} && mv disk.raw ${GCE_IMG_${_FS}}
67	touch ${.OBJDIR}/${.TARGET}
68
69gce-do-upload-${_FS}:
70	@# Fallthrough in case the bucket already exists.
71	/usr/local/bin/gsutil mb gs://${GCE_BUCKET} || true
72	/usr/local/bin/gsutil cp ${.OBJDIR}/${GCE_TARGET_${_FS}}.tar.gz \
73		gs://${GCE_BUCKET}/
74	/usr/local/bin/gcloud compute images create ${GCE_TARGET_${_FS}} \
75		--family=${GCE_FAMILY}${GCE_FAMILY_SUFX} ${GCE_LICENSE} \
76		--source-uri gs://${GCE_BUCKET}/${GCE_TARGET_${_FS}}.tar.gz
77	touch ${.OBJDIR}/${.TARGET}
78.endfor
79
80gce-do-package: gce-do-package-${VMFS}
81gce-do-upload: gce-do-upload-${VMFS}
82