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 \ 47 BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 48 all install clean 49 env UNAME_r=${UNAME_r} make -C ${PORTSDIR}/lang/python \ 50 BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \ 51 all install clean 52. endif 53.endif 54 55gce-do-login: 56 @echo "This requires human interaction, which is not yet supported." 57 @true 58 59.for _FS in ${GCE_FSLIST} 60GCE_IMG_${_FS}= ${.OBJDIR}/gce.${_FS}.raw 61# Really? Uppercase characters are not allowed? Sigh... 62# And don't even get me started on the '.'. 63GCE_TARGET_${_FS}= ${OSRELEASE:S,.raw,,:tl:S,.,-,g}-${_FS}${SNAPSHOT_DATE} 64 65gce-do-package-${_FS}: 66 @# Yes, really... Sigh. 67 cd ${.OBJDIR} && mv ${GCE_IMG_${_FS}} disk.raw 68 cd ${.OBJDIR} && tar --format=gnutar -zcf \ 69 ${GCE_TARGET_${_FS}:S,${.OBJDIR}/,,}.tar.gz disk.raw 70 cd ${.OBJDIR} && mv disk.raw ${GCE_IMG_${_FS}} 71 touch ${.OBJDIR}/${.TARGET} 72 73gce-do-upload-${_FS}: 74 @# Fallthrough in case the bucket already exists. 75 /usr/local/bin/gsutil mb gs://${GCE_BUCKET} || true 76 /usr/local/bin/gsutil cp ${.OBJDIR}/${GCE_TARGET_${_FS}}.tar.gz \ 77 gs://${GCE_BUCKET}/ 78 /usr/local/bin/gcloud compute images create ${GCE_TARGET_${_FS}} \ 79 --family=${GCE_FAMILY}${GCE_FAMILY_SUFX} ${GCE_LICENSE} \ 80 --guest-os-features=GVNIC,UEFI_COMPATIBLE \ 81 --source-uri gs://${GCE_BUCKET}/${GCE_TARGET_${_FS}}.tar.gz 82 touch ${.OBJDIR}/${.TARGET} 83.endfor 84 85gce-do-package: gce-do-package-${VMFS} 86gce-do-upload: gce-do-upload-${VMFS} 87