From e99e6322d813dbdee71adcb0fb2ed37fdcb94fba Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Wed, 2 Mar 2022 14:35:21 +0800
Subject: [PATCH] chore(dockerfile): use drycc/base image

---
 Dockerfile                | 43 +++++++++++++++++++++++++++++++--------
 Makefile                  |  2 +-
 contrib/ci/test.sh        |  2 +-
 main.go                   |  2 +-
 rootfs/config-example.yml | 18 ++++++++++++++++
 5 files changed, 55 insertions(+), 12 deletions(-)
 create mode 100644 rootfs/config-example.yml

diff --git a/Dockerfile b/Dockerfile
index 7d18242..fc01ebd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,24 +1,49 @@
-FROM docker.io/minio/mc:latest as mc
-
-
 FROM docker.io/drycc/go-dev:latest AS build
 ARG LDFLAGS
 ADD . /app
 RUN export GO111MODULE=on \
   && cd /app \
-  && CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o /usr/local/bin/registry main.go \
+  && CGO_ENABLED=0 init-stack go build -ldflags "${LDFLAGS}" -o /usr/local/bin/registry main.go \
   && upx -9 --brute /usr/local/bin/registry
 
 
-FROM docker.io/library/registry:2.7
+FROM docker.io/drycc/base:bullseye
+
+RUN adduser --system \
+   --shell /bin/bash \
+   --disabled-password \
+   --home /var/lib/registry \
+   --group \
+   drycc
 
-COPY rootfs /
-COPY --from=mc /usr/bin/mc /bin/mc
+COPY rootfs/bin/ /bin/
+COPY rootfs/config-example.yml /etc/docker/registry/config.yml
 COPY --from=build /usr/local/bin/registry /opt/registry/sbin/registry
+ENV JQ_VERSION="1.6" \
+  MC_VERSION="2022.02.26.03.58.31" \
+  REGISTRY_VERSION="2.8.0"
 
-RUN apk add --no-cache jq bash \
-  && chmod +x /bin/create_bucket /bin/normalize_storage 
+RUN install-stack jq $JQ_VERSION \
+  && install-stack mc $MC_VERSION \
+  && install-stack registry $REGISTRY_VERSION \
+  && chmod +x /bin/create_bucket /bin/normalize_storage \
+  && rm -rf \
+      /usr/share/doc \
+      /usr/share/man \
+      /usr/share/info \
+      /usr/share/locale \
+      /var/lib/apt/lists/* \
+      /var/log/* \
+      /var/cache/debconf/* \
+      /etc/systemd \
+      /lib/lsb \
+      /lib/udev \
+      /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
+      /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
+  && mkdir -p /usr/share/man/man{1..8} \
+  && chown -R drycc:drycc /var/lib/registry
 
+USER drycc
 VOLUME ["/var/lib/registry"]
 CMD ["/opt/registry/sbin/registry"]
 EXPOSE 5000
diff --git a/Makefile b/Makefile
index 1dc469b..d75fcb0 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ SHELL_SCRIPTS = $(wildcard rootfs/bin/* _scripts/*.sh contrib/ci/*.sh)
 # The following variables describe the containerized development environment
 # and other build options
 DEV_ENV_IMAGE := ${DEV_REGISTRY}/drycc/go-dev
-DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}
+DEV_ENV_WORK_DIR := /opt/drycc/go/src/${REPO_PATH}
 DEV_ENV_PREFIX := docker run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR}
 DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
 LDFLAGS := "-s -w -X main.version=${VERSION}"
diff --git a/contrib/ci/test.sh b/contrib/ci/test.sh
index a0c143c..13cd969 100755
--- a/contrib/ci/test.sh
+++ b/contrib/ci/test.sh
@@ -12,7 +12,7 @@ echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/
 
 MINIO_JOB=$(docker run -d --name minio \
   -v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/drycc/objectstore/creds \
-  drycc/minio:canary server /home/minio/)
+  drycc/minio:canary server /data/minio/)
 
 sleep 5
 docker logs "${MINIO_JOB}"
diff --git a/main.go b/main.go
index 407a145..d0b23f0 100644
--- a/main.go
+++ b/main.go
@@ -9,7 +9,7 @@ import (
 )
 
 const (
-	registryBinary  = "/bin/registry"
+	registryBinary  = "/opt/drycc/registry/bin/registry"
 	registryConfig  = "/etc/docker/registry/config.yml"
 	minioHostEnvVar = "DRYCC_MINIO_SERVICE_HOST"
 	minioPortEnvVar = "DRYCC_MINIO_SERVICE_PORT"
diff --git a/rootfs/config-example.yml b/rootfs/config-example.yml
new file mode 100644
index 0000000..3277f9a
--- /dev/null
+++ b/rootfs/config-example.yml
@@ -0,0 +1,18 @@
+version: 0.1
+log:
+  fields:
+    service: registry
+storage:
+  cache:
+    blobdescriptor: inmemory
+  filesystem:
+    rootdirectory: /var/lib/registry
+http:
+  addr: :5000
+  headers:
+    X-Content-Type-Options: [nosniff]
+health:
+  storagedriver:
+    enabled: true
+    interval: 10s
+    threshold: 3
