38 lines
1.6 KiB
Cheetah
38 lines
1.6 KiB
Cheetah
{{- if false -}}
|
|
#!/usr/bin/env bash
|
|
# @file Google Cloud Platform
|
|
# @brief Ensures S3 buckets are created
|
|
# @description
|
|
# This script ensures that the S3 buckets are created on Google Cloud Platform. It creates
|
|
# the following buckets:
|
|
#
|
|
# - gs://docker.s3.{{ .host.domain }}
|
|
# - gs://private.s3.{{ .host.domain }}
|
|
# - gs://public.s3.{{ .host.domain }}
|
|
# - gs://system.s3.{{ .host.domain }}
|
|
# - gs://user.s3.{{ .host.domain }}
|
|
|
|
if command -v gcloud > /dev/null; then
|
|
if [ -f "${$XDG_CONFIG_HOME:-$HOME/.config}/gcloud/s3-client-secret.json" ]; then
|
|
gum log -sl info 'Authenticating with gcloud S3 service account'
|
|
echo Y | gcloud auth login --cred-file=s3-gcp.json
|
|
if gcloud config get-value account > /dev/null && gum log -sl info 'gcloud is authenticated'; then
|
|
gum log -sl info 'Disabling usage reporting' && gcloud config set disable_usage_reporting true
|
|
BUCKETS="$(gcloud storage buckets list | grep 'storage_url:')"
|
|
for BUCKET in "docker" "private" "public" "system" "user"; do
|
|
if gum log -sl info "Checking for $BUCKET S3 presence on GCP" && ! echo "$BUCKETS" | grep "gs://${BUCKET}.s3.{{ .host.domain }}" > /dev/null; then
|
|
gum log -sl info "Creating gs://${BUCKET}.s3.{{ .host.domain }}" && gcloud storage buckets create "gs://${BUCKET}.s3.{{ .host.domain }}"
|
|
fi
|
|
done
|
|
gum log -sl info 'Finished ensuring S3 buckets on gcloud are created'
|
|
else
|
|
gum log -sl error 'gcloud is not authenticated'
|
|
fi
|
|
else
|
|
gum log -sl info 'No client secret available for gcloud S3 service account'
|
|
fi
|
|
else
|
|
gum log -sl error 'The gcloud executable is not available'
|
|
fi
|
|
|
|
{{ end -}}
|