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

---
 Dockerfile               | 68 ++++++++++++++++++++++------------------
 Makefile                 |  2 +-
 contrib/ci/test-minio.sh |  2 +-
 contrib/ci/test.sh       |  2 +-
 4 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index bf67369..f195699 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,36 +1,44 @@
-FROM docker.io/minio/mc:latest as mc
+FROM docker.io/drycc/base:bullseye
 
-
-FROM docker.io/library/golang:buster as builder
-ARG GOBIN=/usr/local/bin
-ARG WAL_G_VERSION=v1.1
-
-RUN apt-get update \
-  && apt-get install -y git gcc liblzo2-dev cmake \
-  && git clone --dept 1 -b $WAL_G_VERSION https://github.com/wal-g/wal-g $GOPATH/src/github.com/wal-g/wal-g \
-  && cd $GOPATH/src/github.com/wal-g/wal-g \
-  && make install \
-  && make deps \
-  && make pg_install
-
-
-FROM docker.io/library/postgres:14-bullseye
-
-COPY rootfs /
-COPY --from=mc /usr/bin/mc /bin/mc
-COPY --from=builder /usr/local/bin/wal-g  /bin/wal-g
-
-ENV PGDATA $PGDATA/$PG_MAJOR
+ENV PGDATA /opt/drycc/postgresql/14/data
 ENV WALG_ENVDIR /etc/wal-g.d/env
 
-RUN mkdir -p $WALG_ENVDIR \
-  && apt-get update \
-  && apt-get install -y --no-install-recommends \
-    jq \
-    python3 \
-    ca-certificates \
-    python3-pip \
-  && pip3 install envdir
+COPY rootfs/bin /bin/
+COPY rootfs/docker-entrypoint-initdb.d /docker-entrypoint-initdb.d/
+COPY rootfs/docker-entrypoint.sh /docker-entrypoint.sh
+ENV JQ_VERSION="1.6" \
+  GOSU_VERSION="1.14" \
+  MC_VERSION="2022.02.26.03.58.31" \
+  WAL_G_VERSION="1.1" \
+  PYTHON_VERSION="3.10.2" \
+  POSTGRESQL_VERSION="14.2"
 
+RUN mkdir -p $WALG_ENVDIR \
+  && install-stack jq $JQ_VERSION \
+  && install-stack gosu $GOSU_VERSION \
+  && install-stack mc $MC_VERSION \
+  && install-stack wal-g $WAL_G_VERSION \
+  && install-stack python $PYTHON_VERSION \
+  && install-stack postgresql $POSTGRESQL_VERSION && . init-stack \
+  && 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} \
+  && mkdir -p /run/postgresql $PGDATA \
+  && groupadd postgres && useradd -g postgres postgres \
+  && chown -R postgres:postgres /run/postgresql $PGDATA \
+  && set -eux; pip3 install --disable-pip-version-check --no-cache-dir envdir 2>/dev/null
+
+ENTRYPOINT ["init-stack"]
 CMD ["/docker-entrypoint.sh", "postgres"]
 EXPOSE 5432
diff --git a/Makefile b/Makefile
index 6c14bbb..df0529a 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ SHELL_SCRIPTS = $(wildcard _scripts/*.sh contrib/ci/*.sh rootfs/bin/*)
 # 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_CMD := docker run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
 DEV_ENV_CMD_INT := docker run -it --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
 
diff --git a/contrib/ci/test-minio.sh b/contrib/ci/test-minio.sh
index 1d071c5..c7d6120 100755
--- a/contrib/ci/test-minio.sh
+++ b/contrib/ci/test-minio.sh
@@ -26,7 +26,7 @@ echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/
 
 # boot minio
 mkdir -p "${CURRENT_DIR}"/tmp/bin
-echo "ls /data/*/*/basebackups_005" > "${CURRENT_DIR}"/tmp/bin/backups.sh
+echo "ls /data/*/basebackups_005" > "${CURRENT_DIR}"/tmp/bin/backups.sh
 MINIO_JOB=$(docker run -d \
   -v "${CURRENT_DIR}"/tmp/bin:/tmp/bin \
   -v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/drycc/objectstore/creds \
diff --git a/contrib/ci/test.sh b/contrib/ci/test.sh
index 963f1fb..5d124c8 100755
--- a/contrib/ci/test.sh
+++ b/contrib/ci/test.sh
@@ -41,5 +41,5 @@ check-postgres() {
 
   # check if postgres is running
   puts-step "checking if postgres is running"
-  docker exec "$1" is_running
+  docker exec "$1" init-stack is_running
 }
