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