forked from GoogleCloudPlatform/docker-registry-driver-gcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·60 lines (51 loc) · 1.89 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
GUNICORN_WORKERS=${GUNICORN_WORKERS:-1}
REGISTRY_PORT=${REGISTRY_PORT:-5000}
GUNICORN_GRACEFUL_TIMEOUT=${GUNICORN_GRACEFUL_TIMEOUT:-3600}
GUNICORN_SILENT_TIMEOUT=${GUNICORN_SILENT_TIMEOUT:-3600}
USAGE="docker run -e GCS_BUCKET=yet-another-docker-bucket \
[-e BOTO_PATH='/.config/gcloud/legacy_credentials/<YOUR_EMAIL>/.boto'] \
[-e GCP_OAUTH2_REFRESH_TOKEN=<refresh token>] \
-p 5000:5000 \
[--volumes-from gcloud-config] google/docker-registry"
if [[ -z "${GCS_BUCKET}" ]]; then
echo "GCS_BUCKET not defined"
echo
echo "$USAGE"
exit 1
fi
# If a refresh token is passed in directly, use that.
if [[ -n "$GCP_OAUTH2_REFRESH_TOKEN" ]]; then
cat >/etc/boto.cfg <<EOF
[Credentials]
gs_oauth2_refresh_token = $GCP_OAUTH2_REFRESH_TOKEN
EOF
BOTO_PATH=/etc/boto.cfg
echo "Using credentails specified in GCP_OAUTH2_REFRESH_TOKEN env variable"
fi
# Look to see if something is mounted under the /.config dir
if [[ -z "${BOTO_PATH}" ]]; then
BOTO_PATH=${BOTO_PATH:-$(find /.config | grep .boto | head -n 1)}
fi
if [[ -n "${BOTO_PATH}" ]]; then
echo "Using credentials in ${BOTO_PATH}"
else
wget -q --header='Metadata-Flavor: Google' \
http://metadata.google.internal./computeMetadata/v1/instance/service-accounts/default/scopes \
-O - | grep devstorage > /dev/null
GCE_SA=$?
if [[ $GCE_SA -eq 0 ]]; then
echo "Using credentials from GCE Service Account"
else
echo "Boto credentials not found. Either:"
echo " - Set GCP_OAUTH2_REFRESH_TOKEN"
echo " - Mount credentials under /.config in the container"
echo " - Run in GCE with a service account configured for access"
echo
echo "$USAGE"
exit 1
fi
fi
export GCS_BUCKET BOTO_PATH
cd "$(dirname $0)"
exec gunicorn --access-logfile - --debug --max-requests 100 --graceful-timeout $GUNICORN_GRACEFUL_TIMEOUT -t $GUNICORN_SILENT_TIMEOUT -k gevent -b 0.0.0.0:$REGISTRY_PORT -w $GUNICORN_WORKERS wsgi:application