forked from fancyremarker/docker-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.erb
95 lines (77 loc) · 3.69 KB
/
Dockerfile.erb
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
FROM quay.io/aptible/debian:<%= ENV.fetch 'DEBIAN_VERSION' %>
# cf. docker-library/postgres: explicitly create the user so uid and gid are consistent.
RUN groupadd -r postgres && useradd -r -g postgres postgres
# Let's not use flakey keyservers anymore
COPY GPGkeys /tmp/GPGkeys/
# Grab gosu: we'll need to step down from root and would rather not have to deal with sudo's
# awkwardness.
ENV GOSU_VERSION 1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget gnupg2 && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --import /tmp/GPGkeys/gosu.key \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true \
&& apt-get purge -y --auto-remove ca-certificates wget
# Define PostgreSQL version for shared scripts
ENV PG_VERSION <%= ENV.fetch 'POSTGRES_VERSION' %>
# Temporary workaround for host-container user conflicts on Linux Kernel >= 3.15
# See https://github.com/docker/docker/issues/6345 for details.
RUN ln -s -f /bin/true /usr/bin/chfn
# Install some helpers we'll need
RUN apt-install locales wget unzip sudo pwgen \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
# And now install Postgres from its own repos
ADD templates/etc/apt /etc/apt
RUN sed -ri 's/__DEBIAN__VERSION__/<%= ENV.fetch 'DEBIAN_VERSION' %>/' /etc/apt/sources.list.d/pgdg.list
# The package names below are anchored, becuase they're interpreted by apt as regexes
# (because they contain "."), which can result in undesired packages being installed if
# we don't update the PG and PostGIS versions properly, e.g.:
# $ sudo apt-get install -y postgresql-9.5-postgis-2.1
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# Note, selecting 'postgresql-9.5-postgis-2.1-scripts' for regex 'postgresql-9.5-postgis-2.1'
# 0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.
RUN apt-key add /tmp/GPGkeys/postgresql-debian.key \
&& apt-get update \
&& apt-get -y install postgresql-common \
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
&& apt-get -y install python \
"^postgresql-${PG_VERSION}\$" \
"^postgresql-client-${PG_VERSION}\$" \
"^postgresql-contrib-${PG_VERSION}\$" \
&& rm -rf /var/lib/apt/lists/*
ENV POSTGIS_VERSION <%= ENV.fetch 'POSTGIS_VERSION' %>
RUN apt-get update \
&& for v in ${POSTGIS_VERSION}; \
do sudo apt-get install -y "^postgresql-${PG_VERSION}-postgis-${v}\$" || true; \
done
# Export configuration
ENV AUTH_METHOD <%= ENV.fetch 'AUTH_METHOD' %>
ENV PRELOAD_LIB <%= ENV.fetch 'PRELOAD_LIB' %>
ENV TAG <%= ENV.fetch 'TAG' %>
# If any, install extras
<% if ENV['PG_CRON_VERSION'] %>
ENV PG_CRON_VERSION <%= ENV.fetch 'PG_CRON_VERSION' %>
ENV PG_CRON_SHA1SUM <%= ENV.fetch 'PG_CRON_SHA1SUM' %>
<% end %>
ADD "${TAG}"/install-extras.sh /install-extras.sh
RUN /install-extras.sh
ENV CONF_DIRECTORY /etc/postgresql/$PG_VERSION
ADD templates/etc/postgresql/PG_VERSION $CONF_DIRECTORY
ENV DATA_DIRECTORY /var/db
RUN mkdir $DATA_DIRECTORY && chown -R postgres $DATA_DIRECTORY
ADD bin/run-database.sh /usr/bin/
ADD bin/utilities.sh /usr/bin/
ADD bin/autotune /usr/local/bin/
ADD "${TAG}"/test /tmp/test
ADD test /tmp/test
VOLUME ["$DATA_DIRECTORY"]
EXPOSE 5432
ENTRYPOINT ["/usr/bin/run-database.sh"]