Browse Source

fix: [postgres] don't rely on host.

We were using ``lsof`` and ``pgm`` on host for some managing purpose. As
we want to be able to use ``compose`` from a docker container, these
got removed in favor of portable solutions.
framadate
Valentin Lab 6 years ago
parent
commit
105dc15812
  1. 40
      postgres/build/Dockerfile
  2. 54
      postgres/lib/common
  3. 1
      postgres/metadata.yml

40
postgres/build/Dockerfile

@ -0,0 +1,40 @@
## is a simple copy of postgres:10-alpine
FROM docker.0k.io/postgres:10-alpine as common
FROM common AS builder
RUN apk -U add alpine-sdk curl
RUN adduser -D packager && addgroup packager abuild
ENV MBUFFER_APKBUILD_URL=https://git.alpinelinux.org/cgit/aports/plain/testing/mbuffer/APKBUILD?id=026cabf316eb477b2ae3e26dadc3e9c30ff26626
USER packager
RUN mkdir -p /tmp/build && \
curl -L "${MBUFFER_APKBUILD_URL}" > /tmp/build/APKBUILD
RUN cd /tmp/build && \
sed -ri 's/^(\s+make -j1 check.*)/#\1/g' APKBUILD && \
abuild-keygen -a -i && \
abuild -r
USER root
RUN apk add curl
RUN curl -L https://github.com/0k/pgm/raw/master/bin/pgm > /bin/pgm && \
chmod +x /bin/pgm
FROM common
RUN apk -U add pv python file
COPY --from=builder /home/packager/packages/tmp/x86_64/*.apk /tmp/
COPY --from=builder /bin/pgm /bin
RUN apk add /tmp/mbuffer-2018*.apk --allow-untrusted
RUN ln -sf /usr/bin/mbuffer /usr/bin/buffer

54
postgres/lib/common

@ -8,27 +8,7 @@ export DB_PASSFILE=/root/.pgpass
is_db_locked() {
require lsof || apt-get install -y lsof </dev/null || {
err "Couldn't install command 'lsof'."
return 1
}
# "$lsof" +D "$host_db_working_dir" || true
## We need:
## 1- to protect against set -e
## 2- to detect if errorlevel 1 because lsof failed for good reason: permissions error, directory not found
## 3- to detect if errorlevel 1 because no process found
[ -d "$host_db_working_dir" ] || {
err "Directory '$host_db_working_dir' not found. Might be normal at this stage."
return 1
}
## We choose to ignore (2), and use stdout emptyness to ensure (3)
open_files=$(lsof +D "$host_db_working_dir") || true
[ "$open_files" ]
is_volume_used "$DATASTORE/${SERVICE_NAME}"
}
@ -102,19 +82,25 @@ db_change_password() {
ddb < <(echo "ALTER USER $user WITH PASSWORD '$password';")
}
PGM() {
ensure_db_docker_running </dev/null || return 1
## XXXvlab: Here we should have been able to use this, but
## pgm requires the ``prefix_pg_local_command=' '`` hack. As
## soon this is fixed, we can re
#dcmd /bin/sh pgm "$@"
echo docker run -i --rm \
$db_docker_opts -e prefix_pg_local_command=' ' \
--entrypoint pgm "$DOCKER_BASE_IMAGE" $db_cmd_opts "$@" >&2
docker run -i --rm \
$db_docker_opts -e prefix_pg_local_command=' ' \
--entrypoint pgm "$DOCKER_BASE_IMAGE" $db_cmd_opts "$@"
}
db_grant_rights () {
local dbname="$1" user="$2"
require psql || apt-get install -y postgresql-client </dev/null
require pgm || {
(
cd /opt/apps
git clone https://github.com/0k/pgm.git
ln -sf /opt/apps/pgm/bin/* /usr/local/bin/
apt-get install -y --force-yes pv buffer < /dev/null
# cd /opt/apps/0k-docker
# git checkout master
)
}
debug PGHOST="$DOCKER_IP" PGUSER=postgres pgm chown "$user" "$dbname"
PGHOST="$DOCKER_IP" PGUSER=postgres prefix_pg_local_command=" " pgm chown "$user" "$dbname"
PGM chown "$user" "$dbname"
}

1
postgres/metadata.yml

@ -1,5 +1,4 @@
summary: "Postgres server"
maintainer: "Valentin Lab <valentin.lab@kalysto.org>"
docker-image: docker.0k.io/postgres:10-alpine
data-resources:
- /var/lib/postgresql/data
Loading…
Cancel
Save