Skip to content

Commit 3af1129

Browse files
author
Matthew Fisher
committed
ref(Dockerfile): use upstream registry image
This commit removes the forked deis/distribution dependency now that the majority of patches have been applied upstream. The only thing missing was the bucket creation at boot, which has been replaced by the same `create-bucket` script used in deis/postgres.
1 parent 3e247fb commit 3af1129

4 files changed

Lines changed: 113 additions & 38 deletions

File tree

contrib/ci/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ JOB=$(docker run -d $1)
66
# let the registry run for a few seconds
77
sleep 5
88
# check that the registry is still up
9+
docker logs $JOB
910
docker ps -q --no-trunc=true | grep $JOB
1011
docker rm -f $JOB

main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,36 @@ func main() {
2929
log.Fatal(err)
3030
} else {
3131
os.Setenv("REGISTRY_STORAGE_GCS_BUCKET", string(bucket))
32+
os.Setenv("BUCKET_NAME", string(bucket))
3233
}
3334
} else if storageType == "s3" {
3435
log.Println("INFO: using s3 as the backend")
3536
if accesskey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/accesskey"); err != nil {
3637
log.Fatal(err)
3738
} else {
3839
os.Setenv("REGISTRY_STORAGE_S3_ACCESSKEY", string(accesskey))
40+
os.Setenv("AWS_ACCESS_KEY_ID", string(accesskey))
3941
}
4042

4143
if secretkey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/secretkey"); err != nil {
4244
log.Fatal(err)
4345
} else {
4446
os.Setenv("REGISTRY_STORAGE_S3_SECRETKEY", string(secretkey))
47+
os.Setenv("AWS_SECRET_ACCESS_KEY", string(secretkey))
4548
}
4649

4750
if region, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/region"); err != nil {
4851
log.Fatal(err)
4952
} else {
5053
os.Setenv("REGISTRY_STORAGE_S3_REGION", string(region))
54+
os.Setenv("AWS_REGION", string(region))
5155
}
5256

5357
if bucket, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/registry-bucket"); err != nil {
5458
log.Fatal(err)
5559
} else {
5660
os.Setenv("REGISTRY_STORAGE_S3_BUCKET", string(bucket))
61+
os.Setenv("BUCKET_NAME", string(bucket))
5762
}
5863
} else if storageType == "azure" {
5964
log.Println("INFO: using azure as the backend")
@@ -73,6 +78,7 @@ func main() {
7378
log.Fatal(err)
7479
} else {
7580
os.Setenv("REGISTRY_STORAGE_AZURE_CONTAINER", string(container))
81+
os.Setenv("BUCKET_NAME", string(container))
7682
}
7783

7884
} else if storageType == "minio" {
@@ -82,21 +88,29 @@ func main() {
8288
os.Setenv("REGISTRY_STORAGE", "s3")
8389
os.Setenv("REGISTRY_STORAGE_S3_BACKEND", "minio")
8490
os.Setenv("REGISTRY_STORAGE_S3_REGIONENDPOINT", fmt.Sprintf("http://%s:%s", mHost, mPort))
91+
// NOTE(bacongobbler): custom envvars used in /bin/create-bucket
92+
os.Setenv("S3_HOST", mHost)
93+
os.Setenv("S3_PORT", mPort)
94+
os.Setenv("S3_USE_SIGV4", "true")
8595

8696
if accesskey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/accesskey"); err != nil {
8797
log.Fatal(err)
8898
} else {
8999
os.Setenv("REGISTRY_STORAGE_S3_ACCESSKEY", string(accesskey))
100+
os.Setenv("AWS_ACCESS_KEY_ID", string(accesskey))
90101
}
91102

92103
if secretkey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/secretkey"); err != nil {
93104
log.Fatal(err)
94105
} else {
95106
os.Setenv("REGISTRY_STORAGE_S3_SECRETKEY", string(secretkey))
107+
os.Setenv("AWS_SECRET_ACCESS_KEY", string(secretkey))
96108
}
97109

98110
os.Setenv("REGISTRY_STORAGE_S3_REGION", "us-east-1")
111+
os.Setenv("AWS_REGION", "us-east-1")
99112
os.Setenv("REGISTRY_STORAGE_S3_BUCKET", "registry")
113+
os.Setenv("BUCKET_NAME", "registry")
100114

101115
} else if storageType == "swift" {
102116
log.Println("INFO: using swift as the backend")
@@ -138,11 +152,19 @@ func main() {
138152

139153
}
140154

141-
cmd := exec.Command(registryBinary, command, registryConfig)
155+
// run /bin/create-bucket
156+
cmd := exec.Command("/bin/create-bucket")
142157
cmd.Stdout = os.Stdout
143158
cmd.Stderr = os.Stderr
144159
if err := cmd.Run(); err != nil {
145-
log.Fatal("Error starting the registry", err)
160+
log.Fatal("Error creating the registry bucket: ", err)
161+
}
162+
163+
cmd = exec.Command(registryBinary, command, registryConfig)
164+
cmd.Stdout = os.Stdout
165+
cmd.Stderr = os.Stderr
166+
if err := cmd.Run(); err != nil {
167+
log.Fatal("Error starting the registry: ", err)
146168
}
147169
log.Println("INFO: registry started.")
148170
}

rootfs/Dockerfile

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
1-
FROM quay.io/deis/base:v0.3.5
1+
FROM registry:2.5.1
22

3-
COPY . /
3+
RUN apk add --no-cache \
4+
python3 && \
5+
python3 -m ensurepip && \
6+
ln -sf /usr/bin/python3 /usr/bin/python && \
7+
ln -sf /usr/bin/pip3 /usr/bin/pip
8+
9+
RUN buildDeps='gcc git linux-headers musl-dev python3-dev' && \
10+
apk add --no-cache $buildDeps && \
11+
# "upgrade" boto to 2.43.0 + the patch to fix minio connections
12+
pip install --disable-pip-version-check --no-cache-dir --upgrade \
13+
git+https://github.com/deis/boto@88c980e56d1053892eb940d43a15a68af4ebb5e6 \
14+
azure==1.0.3 \
15+
gcloud==0.18.3 \
16+
python-swiftclient==3.1.0 \
17+
python-keystoneclient==3.1.0 && \
18+
# purge dev dependencies
19+
apk del $buildDeps
420

5-
RUN buildDeps='git golang make'; \
6-
apt-get update && \
7-
apt-get install -y --no-install-recommends \
8-
$buildDeps && \
9-
export DOCKER_REGISTRY_TAG=deis \
10-
DOCKER_REGISTRY_REPO=https://github.com/deis/distribution.git \
11-
DISTRIBUTION_DIR=/go/src/github.com/docker/distribution && \
12-
export GOPATH=/go:$DISTRIBUTION_DIR/Godeps/_workspace && \
13-
git clone -b $DOCKER_REGISTRY_TAG --single-branch $DOCKER_REGISTRY_REPO $DISTRIBUTION_DIR && \
14-
cd $DISTRIBUTION_DIR && \
15-
make binaries && \
16-
cp bin/* /bin/ && \
17-
rm -rf /go && \
18-
# cleanup
19-
apt-get purge -y --auto-remove $buildDeps && \
20-
apt-get autoremove -y && \
21-
apt-get clean -y && \
22-
# package up license files if any by appending to existing tar
23-
COPYRIGHT_TAR='/usr/share/copyrights.tar'; \
24-
gunzip $COPYRIGHT_TAR.gz; tar -rf $COPYRIGHT_TAR /usr/share/doc/*/copyright; gzip $COPYRIGHT_TAR && \
25-
rm -rf \
26-
/usr/share/doc \
27-
/usr/share/man \
28-
/usr/share/info \
29-
/usr/share/locale \
30-
/var/lib/apt/lists/* \
31-
/var/log/* \
32-
/var/cache/debconf/* \
33-
/etc/systemd \
34-
/lib/lsb \
35-
/lib/udev \
36-
/usr/lib/x86_64-linux-gnu/gconv/IBM* \
37-
/usr/lib/x86_64-linux-gnu/gconv/EBC* && \
38-
bash -c "mkdir -p /usr/share/man/man{1..8}"
21+
COPY . /
3922

4023
VOLUME ["/var/lib/registry"]
4124
CMD ["/opt/registry/sbin/registry"]

rootfs/bin/create-bucket

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
5+
import boto
6+
import json
7+
import swiftclient
8+
from boto import config as botoconfig
9+
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
10+
from oauth2client.service_account import ServiceAccountCredentials
11+
from gcloud.storage.client import Client
12+
from gcloud import exceptions
13+
from azure.storage.blob import BlobService
14+
15+
def bucket_exists(conn, name):
16+
bucket = conn.lookup(name)
17+
if not bucket:
18+
return False
19+
return True
20+
21+
bucket_name = os.getenv('BUCKET_NAME')
22+
23+
if os.getenv('REGISTRY_STORAGE') == "s3" and os.getenv('REGISTRY_STORAGE_S3_BACKEND') != 'minio':
24+
conn = boto.connect_s3()
25+
26+
if not bucket_exists(conn, bucket_name):
27+
conn.create_bucket(bucket_name)
28+
29+
elif os.getenv('REGISTRY_STORAGE') == "gcs":
30+
scopes = ['https://www.googleapis.com/auth/devstorage.full_control']
31+
credentials = ServiceAccountCredentials.from_json_keyfile_name(os.getenv('REGISTRY_STORAGE_GCS_KEYFILE'), scopes=scopes)
32+
with open(os.getenv('REGISTRY_STORAGE_GCS_KEYFILE')) as data_file:
33+
data = json.load(data_file)
34+
conn = Client(credentials=credentials, project=data['project_id'])
35+
try:
36+
conn.get_bucket(bucket_name)
37+
except exceptions.NotFound:
38+
conn.create_bucket(bucket_name)
39+
40+
elif os.getenv('REGISTRY_STORAGE') == "azure":
41+
conn = BlobService(account_name=os.getenv('REGISTRY_STORAGE_AZURE_ACCOUNTNAME'), account_key=os.getenv('REGISTRY_STORAGE_AZURE_ACCOUNTKEY'))
42+
# Azure doesn't throw an exception if the container exists by default
43+
# https://github.com/Azure/azure-storage-python/blob/master/azure/storage/blob/baseblobservice.py#L504
44+
conn.create_container(bucket_name)
45+
46+
elif os.getenv('REGISTRY_STORAGE') == "swift":
47+
conn = swiftclient.Connection(
48+
user=os.getenv('REGISTRY_STORAGE_SWIFT_USERNAME'),
49+
key=os.getenv('REGISTRY_STORAGE_SWIFT_PASSWORD'),
50+
authurl=os.getenv('REGISTRY_STORAGE_SWIFT_AUTHURL'),
51+
auth_version=os.getenv('REGISTRY_STORAGE_SWIFT_AUTHVERSION'),
52+
tenant_name=os.getenv('REGISTRY_STORAGE_SWIFT_TENANT')
53+
)
54+
# swift also does not throw exception if container already exists.
55+
conn.put_container(os.getenv('BUCKET_NAME'))
56+
57+
elif os.getenv('REGISTRY_STORAGE') == "s3" and os.getenv('REGISTRY_STORAGE_S3_BACKEND') == 'minio':
58+
botoconfig.add_section('s3')
59+
botoconfig.set('s3', 'use-sigv4', 'True')
60+
botoconfig.add_section('Boto')
61+
botoconfig.set('Boto', 'is_secure', 'False')
62+
conn = S3Connection(
63+
host=os.getenv('S3_HOST'),
64+
port=int(os.getenv('S3_PORT')),
65+
calling_format=OrdinaryCallingFormat())
66+
# HACK(bacongobbler): allow boto to connect to minio by changing the region name for s3v4 auth
67+
conn.auth_region_name = os.getenv('REGISTRY_STORAGE_S3_REGION')
68+
if not bucket_exists(conn, bucket_name):
69+
conn.create_bucket(bucket_name)

0 commit comments

Comments
 (0)