-
Notifications
You must be signed in to change notification settings - Fork 4
/
pg_generate.sh
executable file
·136 lines (89 loc) · 3.19 KB
/
pg_generate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
BASEDIR="postgres"
TAGVERSIONS="en_US pt_BR"
BASEIMAGE="fike/debian"
AUTHOR="Fernando Ike <fike@midstorm.org>"
MAJORVERSION="9"
DEBIANVERSION="jessie"
function postgres(){
for TAGVERSION in $(echo $TAGVERSIONS)
do
for MINORVERSION in $(seq 2 6)
do
if [ "$TAGVERSION" = "en_US" ]
then
unset $TAGVERSION
FILE=$BASEDIR/$MAJORVERSION\.$MINORVERSION/Dockerfile
else
FILE=$BASEDIR/$MAJORVERSION\.$MINORVERSION\-$TAGVERSION/Dockerfile
fi
if [ ! -d "${FILE%/Dockerfile}" ]
then
mkdir -p "${FILE%/Dockerfile}"
fi
cat <<EOF > "$FILE"
FROM $BASEIMAGE:$DEBIANVERSION.$TAGVERSION
MAINTAINER $AUTHOR
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qq && \
apt-get upgrade -y
RUN apt-get install --no-install-recommends wget -y
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main $MAJORVERSION.$MINORVERSION" > /etc/apt/sources.list.d/pgdg.list
RUN gpg --keyserver keys.gnupg.net --recv-keys ACCC4CF8
RUN gpg --export --armor ACCC4CF8|apt-key add -
RUN apt-get update -qq && \
apt-get upgrade -y
RUN apt-get install --no-install-recommends -y \
postgresql-$MAJORVERSION.$MINORVERSION \
postgresql-client-$MAJORVERSION.$MINORVERSION
RUN apt-get clean && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN /etc/init.d/postgresql start && \
su postgres -c "psql --command \"ALTER USER postgres with password 'foobar';\" "
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$MAJORVERSION.$MINORVERSION/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/$MAJORVERSION.$MINORVERSION/main/postgresql.conf
EXPOSE 5432
USER postgres
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
CMD ["/usr/lib/postgresql/$MAJORVERSION.$MINORVERSION/bin/postgres", "-D", "/var/lib/postgresql/$MAJORVERSION.$MINORVERSION/main", "-c", "config_file=/etc/postgresql/$MAJORVERSION.$MINORVERSION/main/postgresql.conf"]
EOF
done
done
}
function contrib(){
for TAGVERSION in $(echo $TAGVERSIONS)
do
for MINORVERSION in $(seq 2 6)
do
if [ "$TAGVERSION" = "en_US" ]
then
unset $TAGVERSION
FILE=$BASEDIR/$MAJORVERSION\.$MINORVERSION-contrib/Dockerfile
else
FILE=$BASEDIR/$MAJORVERSION\.$MINORVERSION\-contrib-$TAGVERSION/Dockerfile
fi
if [ ! -d "${FILE%/Dockerfile}" ]
then
mkdir -p "${FILE%/Dockerfile}"
fi
cat <<EOF > "$FILE"
FROM fike/postgresql:$MAJORVERSION.$MINORVERSION
MAINTAINER Fernando Ike <fike@midstorm.org>
ENV DEBIAN_FRONTEND noninteractive
USER root
RUN apt-get update -qq && \
apt-get upgrade -y
RUN apt-get install --no-install-recommends -y \
postgresql-contrib-$MAJORVERSION.$MINORVERSION
RUN apt-get clean && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
USER postgres
CMD ["/usr/lib/postgresql/$MAJORVERSION.$MINORVERSION/bin/postgres", "-D", "/var/lib/postgresql/$MAJORVERSION.$MINORVERSION/main", "-c", "config_file=/etc/postgresql/$MAJORVERSION.$MINORVERSION/main/postgresql.conf"]
EOF
done
done
}
postgres
contrib