Skip to content

Commit c5736ad

Browse files
author
Keerthan Mala
committed
ref(registry):Enable registry to use multiple object stores
1 parent 4d7dd05 commit c5736ad

8 files changed

Lines changed: 147 additions & 8 deletions

File tree

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ COPY rootfs/ /
2121
# define the execution environment
2222
VOLUME ["/var/lib/registry"]
2323
EXPOSE 5000
24-
ENTRYPOINT ["/bin/registry"]
25-
CMD ["/etc/docker/registry/config.yml"]
24+
CMD ["/opt/registry/sbin/registry"]

Makefile

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,60 @@ SHORT_NAME := registry
88

99
VERSION ?= git-$(shell git rev-parse --short HEAD)
1010

11+
# the filepath to this repository, relative to $GOPATH/src
12+
REPO_PATH = github.com/deis/registry
13+
14+
# The following variables describe the containerized development environment
15+
# and other build options
16+
DEV_ENV_IMAGE := quay.io/deis/go-dev:0.7.0
17+
DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}
18+
DEV_ENV_CMD := docker run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
19+
LDFLAGS := "-s -X main.version=${VERSION}"
20+
BINDIR := ./rootfs/opt/registry/sbin
21+
1122
# Legacy support for DEV_REGISTRY, plus new support for DEIS_REGISTRY.
1223
DEIS_REGISTRY ?= ${DEV_REGISTRY}
1324

1425
IMAGE_PREFIX ?= deis
1526

16-
# Kubernetes-specific information for RC, Service, and Image.
27+
28+
ifeq ($(STORAGE_TYPE),)
29+
STORAGE_TYPE = fs
30+
endif
31+
32+
# Kubernetes-specific information for Secret, RC, Service, and Image.
33+
SECRET := contrib/kubernetes/manifests/${SHORT_NAME}-${STORAGE_TYPE}-secret.yaml
1734
RC := contrib/kubernetes/manifests/${SHORT_NAME}-rc.yaml
1835
SVC := contrib/kubernetes/manifests/${SHORT_NAME}-service.yaml
1936
IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/${SHORT_NAME}:${VERSION}
2037

2138
all:
2239
@echo "Use a Makefile to control top-level building of the project."
2340

24-
build:
25-
@echo "Nothing to build. Use 'make docker-build' to build the image."
41+
build: check-docker
42+
mkdir -p ${BINDIR}
43+
${DEV_ENV_CMD} make build-binary
2644

2745
# For cases where we're building from local
2846
# We also alter the RC file to set the image name.
29-
docker-build: check-docker
47+
docker-build: check-docker build
3048
docker build --rm -t ${IMAGE} .
3149

3250
# Push to a registry that Kubernetes can access.
3351
docker-push: check-docker check-registry
3452
docker push ${IMAGE}
3553

54+
build-binary:
55+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags ${LDFLAGS} -o $(BINDIR)/${SHORT_NAME} main.go
56+
3657
# Deploy is a Kubernetes-oriented target
37-
deploy: kube-service kube-rc
58+
deploy: kube-secret kube-service kube-rc
59+
60+
kube-secret: check-kubectl
61+
kubectl create -f ${SECRET}
3862

3963
# Some things, like services, have to be deployed before pods. This is an
40-
# example target. Others could perhaps include kube-secret, kube-volume, etc.
64+
# example target. Others could perhaps include kube-volume, etc.
4165
kube-service: check-kubectl
4266
kubectl create -f ${SVC}
4367

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ Before deploying your custom image you must update the container image specifica
4444
value: "true"
4545
```
4646
47+
By default registry uses the filesystem as the storage medium. To use a custom object store like s3 or gcs:
48+
- First provide the details required for authenticating to object store in base64 format by updating the secret file which can be found at `contrib/kubernetes/manifests/registry-{STORAGE_TYPE}-secret.yaml`.
49+
- Set the STORAGE_TYPE environment variable.
50+
```
51+
$ export STORAGE_TYPE = {s3/gcs}
52+
```
53+
- Update the secret to be used in the pod manifest. This file is found at `contrib/kubernetes/manifests/registry-rc.yaml`:
54+
```yaml
55+
- name: registry-creds
56+
secret:
57+
secretName: fs-keyfile
58+
```
59+
60+
4761
Once updated, deploy the registry to your kubernetes cluster with:
4862

4963
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: fs-keyfile
5+
type: Opaque
6+
data:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: gcs-keyfile
5+
type: Opaque
6+
data:
7+
key.json: {base64-encoded service account JSON file data}
8+
bucket: {base64-encoded bucket name}

contrib/kubernetes/manifests/registry-rc.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ spec:
1919
value: "true"
2020
- name: REGISTRY_LOG_LEVEL
2121
value: info
22+
- name: REGISTRY_STORAGE
23+
value: filesystem
2224
ports:
2325
- containerPort: 5000
2426
volumeMounts:
2527
- name: registry-storage
2628
mountPath: /var/lib/registry
29+
- name: registry-creds
30+
mountPath: /var/run/secrets/deis/registry/creds
2731
volumes:
2832
- name: registry-storage
2933
emptyDir: {}
34+
- name: registry-creds
35+
secret:
36+
secretName: fs-keyfile
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: s3-keyfile
5+
type: Opaque
6+
data:
7+
accesskey: {base64-encoded access key}
8+
secretkey: {base64-encoded secret key}
9+
region: {base64-encoded region name}
10+
bucket: {base64-encoded bucket name}

main.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"log"
6+
"os"
7+
"os/exec"
8+
)
9+
10+
const (
11+
registryBinary = "/bin/registry"
12+
registryConfig = "/etc/docker/registry/config.yml"
13+
)
14+
15+
func main() {
16+
log.Println("INFO: Starting registry...")
17+
storageType := getenv("REGISTRY_STORAGE", "filesystem")
18+
if storageType == "gcs" {
19+
if _, err := os.Stat("/var/run/secrets/deis/registry/creds/key.json"); err != nil {
20+
log.Fatal("Service account not given")
21+
}
22+
os.Setenv("REGISTRY_STORAGE_GCS_KEYFILE", "/var/run/secrets/deis/registry/creds/key.json")
23+
if bucket, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/bucket"); err != nil {
24+
log.Fatal(err)
25+
} else {
26+
os.Setenv("REGISTRY_STORAGE_GCS_BUCKET", string(bucket))
27+
}
28+
} else if storageType == "s3" {
29+
if accesskey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/accesskey"); err != nil {
30+
log.Fatal(err)
31+
} else {
32+
os.Setenv("REGISTRY_STORAGE_S3_ACCESSKEY", string(accesskey))
33+
}
34+
35+
if secretkey, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/secretkey"); err != nil {
36+
log.Fatal(err)
37+
} else {
38+
os.Setenv("REGISTRY_STORAGE_S3_SECRETKEY", string(secretkey))
39+
}
40+
41+
if region, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/region"); err != nil {
42+
log.Fatal(err)
43+
} else {
44+
os.Setenv("REGISTRY_STORAGE_S3_REGION", string(region))
45+
}
46+
47+
if bucket, err := ioutil.ReadFile("/var/run/secrets/deis/registry/creds/bucket"); err != nil {
48+
log.Fatal(err)
49+
} else {
50+
os.Setenv("REGISTRY_STORAGE_S3_BUCKET", string(bucket))
51+
}
52+
}
53+
54+
cmd := exec.Command(registryBinary, registryConfig)
55+
cmd.Stdout = os.Stdout
56+
cmd.Stderr = os.Stderr
57+
if err := cmd.Start(); err != nil {
58+
log.Fatal("Error starting the registry", err)
59+
}
60+
log.Println("INFO: registry started.")
61+
for {
62+
}
63+
}
64+
65+
func getenv(name, dfault string) string {
66+
value := os.Getenv(name)
67+
if value == "" {
68+
value = dfault
69+
}
70+
return value
71+
}

0 commit comments

Comments
 (0)