Skip to content

Commit 16d6eac

Browse files
committed
first commit
0 parents  commit 16d6eac

38 files changed

+5756
-0
lines changed

Makefile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile for multi-platform-postgresql
4+
#
5+
# auther:
6+
7+
#
8+
# Date:
9+
# 2022.06
10+
#
11+
#-------------------------------------------------------------------------
12+
FILEDESC = "multi platform for appcenter/kubernetes postgresql"
13+
14+
#docker_version ?= ""
15+
export platform=amd64# make platform=arm64 build arm
16+
export pgversion=all# make pgversion=12 only build postgresql 12 that in versions.json field.
17+
export forcebuildimage=0# make forcebuildimage=1 even though the image exists, it also compiles.
18+
19+
k8s: download postgres-image operator-yaml operator-image
20+
all: k8s
21+
22+
download:
23+
source_code/download.sh ${PWD}/source_code
24+
postgres-image: download
25+
cp pgversions.json image/postgresql/versions.json
26+
cp jq-template.awk image/postgresql/jq-template.awk
27+
cd image/postgresql; ./generate_image.sh
28+
operator-image:
29+
cp operatorversions.json image/postgres-operator/versions.json
30+
cd image/postgres-operator; ./generate_image.sh
31+
operator-yaml: operator-image
32+
cp operatorversions.json platforms/kubernetes/postgres-operator/deploy/versions.json
33+
cp jq-template.awk platforms/kubernetes/postgres-operator/deploy/jq-template.awk
34+
cd platforms/kubernetes/postgres-operator/deploy/; awk -f jq-template.awk postgres-operator.yaml.template > postgres-operator.yaml
35+
36+
format:
37+
find ./ -path "./platforms/appcenter/*.py" -o -path "./platforms/kubernetes/postgres-operator/postgres/*.py" | xargs yapf -i -vv
38+
39+
depends:
40+
sudo pip install yapf paramiko kubernetes kopf
41+
docker run --privileged --rm tonistiigi/binfmt --install all
42+
echo "TODO ubuntu: apt install jq"

README.md

Whitespace-only changes.

image/postgres-operator/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions.json
2+
jq-template.awk
3+
postgres

image/postgres-operator/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Build container
2+
FROM python:3.10-slim
3+
4+
RUN mkdir -pv /src
5+
6+
WORKDIR /src
7+
8+
COPY postgres /src
9+
10+
RUN python -m pip install --trusted-host mirrors.aliyun.com --upgrade pip \
11+
-i http://mirrors.aliyun.com/pypi/simple/
12+
RUN python -m pip install --trusted-host mirrors.aliyun.com --no-cache-dir \
13+
Kubernetes kopf wrapt paramiko \
14+
-i http://mirrors.aliyun.com/pypi/simple/
15+
16+
ENTRYPOINT ["kopf", "run", "--standalone", "-A"]
17+
CMD ["postgres.py"]
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -Eeo pipefail
3+
4+
build_image()
5+
{
6+
image=$1
7+
platform=$2
8+
9+
image_exists=$( docker image ls --format "{{.Repository}}:{{.Tag}}" | awk -v aaa=$image '{print $0} END{print aaa}' | grep -c $image )
10+
if [ "$image_exists" -ne 1 ]; then
11+
if [ "$forcebuildimage" = 1 ]; then
12+
echo "docker image $image exists, rebuilding the image ..."
13+
else
14+
echo "docker image $image exists, skiping ..."
15+
return
16+
fi
17+
fi
18+
19+
echo "copy code ..."
20+
cp -r ../../platforms/kubernetes/postgres-operator/postgres .
21+
22+
echo "build docker image $image ..."
23+
docker buildx build --no-cache -t $image --platform $platform .
24+
}
25+
26+
image=$(jq -r '.image' versions.json)
27+
if [ "$platform" = arm64 ]; then
28+
image=${image}-arm64
29+
fi
30+
31+
build_image $image "linux/${platform}"

image/postgresql/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
12
2+
13
3+
14
4+
15
5+
16
6+
17
7+
versions.json
8+
jq-template.awk

image/postgresql/Dockerfile.template

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# multi-stage builder
2+
FROM debian:{{ .debian }} AS builder
3+
4+
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
5+
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
6+
apt update; \
7+
mkdir -p /usr/src/postgresql
8+
9+
ADD postgresql /usr/src/postgresql/
10+
11+
RUN apt install -y --no-install-recommends \
12+
git \
13+
pax-utils \
14+
gosu \
15+
bison \
16+
flex \
17+
gcc \
18+
g++ \
19+
llvm-dev \
20+
clang \
21+
libicu-dev \
22+
dpkg \
23+
dpkg-dev \
24+
pkg-config \
25+
python3-dev \
26+
libreadline-dev \
27+
libldap2-dev \
28+
libxml2-dev \
29+
libgss-dev \
30+
openssl \
31+
libssl-dev \
32+
libxslt-dev \
33+
uuid-dev \
34+
tcl-dev \
35+
{{ if .major >= 14 then ( -}}
36+
liblz4-dev \
37+
{{ ) else "" end -}}
38+
libperl-dev \
39+
libkrb5-dev
40+
#{{ if env.arch == "aarch64" then ( -}}
41+
# ""
42+
#{{ ) else "" end -}}
43+
44+
RUN cd /usr/src/postgresql; \
45+
# git reset --hard; \
46+
git checkout {{ .tag }}; \
47+
# git clean -fqdx; \
48+
awk '$1 == "#define" && $2 == "DEFAULT_PGSOCKET_DIR" && $3 == "\"/tmp\"" { $3 = "\"/var/run/postgresql\""; print; next } { print }' src/include/pg_config_manual.h > src/include/pg_config_manual.h.new; \
49+
grep '/var/run/postgresql' src/include/pg_config_manual.h.new; \
50+
mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h; \
51+
./configure \
52+
--prefix=/var/lib/postgresql/ \
53+
--with-icu \
54+
--with-tcl \
55+
--with-perl \
56+
--with-python \
57+
--with-gssapi \
58+
--with-ldap \
59+
--with-openssl \
60+
--with-libxml \
61+
--with-libxslt \
62+
--with-readline \
63+
--with-uuid=e2fs \
64+
--with-llvm \
65+
--with-libraries=/usr/local/lib \
66+
--with-krb5 \
67+
{{ if .major >= 14 then ( -}}
68+
--with-lz4 \
69+
{{ ) else "" end -}}
70+
>/dev/null; \
71+
make -j `expr $(nproc) - 2` >/dev/null; \
72+
make install; \
73+
make -C contrib install;
74+
75+
ADD pg_auto_failover /usr/src/pg_auto_failover
76+
RUN cd /usr/src/pg_auto_failover; \
77+
git checkout {{ .failover }}; \
78+
make PG_CONFIG=/var/lib/postgresql/bin/pg_config -j `expr $(nproc) - 2` >/dev/null; \
79+
make install PG_CONFIG=/var/lib/postgresql/bin/pg_config;
80+
81+
RUN cd /var/lib/postgresql; \
82+
tar czhvf lib.tar.gz `find . -type f | xargs ldd 2>/dev/null | grep "=>" | cut -d ">" -f 2 | cut -d "(" -f 1 | sort -u`
83+
84+
# real image
85+
FROM debian:{{ .debian }}
86+
87+
ENV LANG en_US.utf8
88+
ENV DATA /var/lib/postgresql/data
89+
ENV XDG_CONFIG_HOME /var/lib/postgresql/data/auto_failover
90+
ENV XDG_DATA_HOME /var/lib/postgresql/data/auto_failover
91+
ENV ASSIST /var/lib/postgresql/data/assist
92+
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/postgresql/bin
93+
ENV PGHOME /var/lib/postgresql
94+
VOLUME /var/lib/postgresql/data
95+
96+
COPY --from=builder /var/lib/postgresql/ /var/lib/postgresql
97+
COPY docker-entrypoint.sh /usr/local/bin/
98+
COPY pgtools /usr/local/bin/
99+
100+
RUN set -eux; \
101+
groupadd -r postgres --gid=999; \
102+
useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres; \
103+
echo 'export PATH=$PATH:/var/lib/postgresql/bin' >> /etc/profile; \
104+
tar --skip-old-files -xzf /var/lib/postgresql/lib.tar.gz -C /; \
105+
rm -rf /var/lib/postgresql/lib.tar.gz; \
106+
mkdir -p "$DATA" && mkdir -p "$ASSIST" && chown -R postgres:postgres /var/lib/postgresql && chmod 777 "$DATA"; \
107+
mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 775 /var/run/postgresql ; \
108+
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
109+
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
110+
apt update; \
111+
apt install -y --no-install-recommends vim sysstat inetutils-ping procps net-tools ssh sshpass ; \
112+
apt install -y --no-install-recommends gosu locales ; \
113+
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ; \
114+
apt-get clean; \
115+
rm -rf /var/lib/apt/lists/*; \
116+
apt-get purge -y --auto-remove ; \
117+
echo "* soft nofile 1024000" >> /etc/security/limits.conf; \
118+
echo "* hard nofile 1024000" >> /etc/security/limits.conf; \
119+
echo "* soft nproc unlimited" >> /etc/security/limits.conf; \
120+
echo "* hard nproc unlimited" >> /etc/security/limits.conf; \
121+
echo "* soft core unlimited" >> /etc/security/limits.conf; \
122+
echo "* hard core unlimited" >> /etc/security/limits.conf; \
123+
echo "* soft memlock unlimited" >> /etc/security/limits.conf; \
124+
echo "* hard memlock unlimited" >> /etc/security/limits.conf; \
125+
/var/lib/postgresql/bin/postgres --version
126+
127+
ENTRYPOINT ["docker-entrypoint.sh"]
128+
STOPSIGNAL SIGINT
129+
EXPOSE 5432
130+
CMD ["postgres"]

0 commit comments

Comments
 (0)