]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/Makefile.gce
MFV: less v643.
[FreeBSD/FreeBSD.git] / release / Makefile.gce
1 #
2 # $FreeBSD$
3 #
4 #
5 # Makefile for uploading Google Compute Engine disk images.
6 #
7
8 GCE_IMG?=               ${.OBJDIR}/gce.raw
9 GCE_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)
15 GCE_UPLOAD_TGTS=        gce-do-login
16 .endif
17 CLEANFILES+=            ${GCE_UPLOAD_TGTS}
18
19 GCE_BUCKET?=
20 GCE_LICENSE?=
21
22 .if !defined(GCE_FAMILY) || empty(GCE_FAMILY)
23 GCE_FAMILY=             ${TYPE:tl}-${REVISION:S,.,-,}
24 .endif
25
26 .if ${BRANCH} == "STABLE" || ${BRANCH} == "CURRENT" || ${BRANCH} == "PRERELEASE"
27 SNAPSHOT_DATE=          -v${BUILDDATE}
28 GCE_FAMILY_SUFX=        -snap
29 .endif
30
31 # Really?  Uppercase characters are not allowed?  Sigh...
32 # And don't even get me started on the '.'.
33 GCE_TARGET:=            ${OSRELEASE:S,.raw,,:tl:S,.,-,g}${SNAPSHOT_DATE}
34
35 gce-upload:             ${GCE_UPLOAD_TGTS}
36
37 gce-check-depends:
38 .for VAR in _BUCKET
39 . if !defined(GCE${VAR}) || empty(GCE${VAR})
40         @echo "Variable GCE${VAR} cannot be empty."
41         @false
42 . endif
43 .endfor
44 .if !exists(/usr/local/bin/gcloud)
45 . if !exists(${PORTSDIR}/net/google-cloud-sdk/Makefile)
46 .  if !exists(/usr/local/sbin/pkg-static)
47         env ASSUME_ALWAYS_YES=yes pkg bootstrap -yf
48 .  endif
49         env ASSUME_ALWAYS_YES=yes pkg install -y net/google-cloud-sdk \
50                 lang/python
51 . else
52         env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/net/google-cloud-sdk BATCH=1 all install clean
53         env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/lang/python BATCH=1 all install clean
54 . endif
55 .endif
56
57 gce-do-package:
58         @# Yes, really...  Sigh.
59         cd ${.OBJDIR} && mv gce.raw disk.raw
60         cd ${.OBJDIR} && tar --format=gnutar -zcf \
61                 ${GCE_TARGET:S,${.OBJDIR}/,,}.tar.gz disk.raw
62         cd ${.OBJDIR} && mv disk.raw gce.raw
63         touch ${.OBJDIR}/${.TARGET}
64
65 gce-do-login:
66         @echo "This requires human interaction, which is not yet supported."
67         @true
68
69 gce-do-upload:
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}.tar.gz \
73                 gs://${GCE_BUCKET}/
74         /usr/local/bin/gcloud compute images create ${GCE_TARGET} \
75                 --family=${GCE_FAMILY}${GCE_FAMILY_SUFX} ${GCE_LICENSE} \
76                 --source-uri gs://${GCE_BUCKET}/${GCE_TARGET}.tar.gz
77         touch ${.OBJDIR}/${.TARGET}
78