Skip to content

Commit

Permalink
docker: Separate DB from image
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Marusak <[email protected]>
  • Loading branch information
marusak authored and xsuchy committed Feb 28, 2018
1 parent 1c144ea commit 94d029d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
4 changes: 1 addition & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ RUN dnf -y update && \
sudo \
which \
cronie \
postgresql-server \
postgresql \
python-psycopg2 \
pg-semver \
python-psycopg2 \
faf-* && \
dnf clean all && \
echo faf:${password:-passwd} | chpasswd && \
Expand All @@ -30,7 +29,6 @@ RUN crontab -u faf /etc/faf/crontab-faf && \
sed -i -e"s/allow-unpackaged\s*=\s*False/allow-unpackaged = True/i" /etc/faf/faf.conf && \
sed -i -e"s/type\s*=\s*simple/type = null/i" /etc/faf/plugins/web.conf

VOLUME /var/lib/postgres
VOLUME /var/spool/faf

EXPOSE 80
Expand Down
10 changes: 10 additions & 0 deletions docker/Dockerfile_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM candidate-registry.fedoraproject.org/postgresql

USER root

# Adds the semver extension on top of the official image
RUN dnf install -y wget pg-semver && \
dnf clean all

# Run the container as user postgres
USER 26
18 changes: 16 additions & 2 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
DB_IP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' db`
DB_PASS="NotSoSecretPassword"

build:
docker build -t faf-image -f Dockerfile ../

build_local:
docker build -t faf-image-local -f Dockerfile_local ../

build_db:
docker build -t postgres_w_semver -f Dockerfile_db ../

run:
docker run --name faf -dit faf-image
docker run --name faf -dit -e PGHOST=$(DB_IP) -e PGUSER=faf -e PGPASSWORD=scrt -e PGPORT=5432 -e PGDATABASE=faf faf-image

run_local:
docker run --name faf -dit faf-image-local
docker run --name faf -dit -e PGHOST=$(DB_IP) -e PGUSER=faf -e PGPASSWORD=scrt -e PGPORT=5432 -e PGDATABASE=faf faf-image-local

# When running as docker containers and need persistent storage, do this for the first time
# mkdir /var/tmp/data
# chown 26:26 /var/tmp/data
# chcon -t svirt_sandbox_file_t /var/tmp/data

run_db:
docker run -p 5432:5432 -v /var/tmp/data:/var/lib/pgsql/data -e POSTGRESQL_ADMIN_PASSWORD=$(DB_PASS) --name db -dit postgres_w_semver

sh:
docker exec -it faf bash
Expand Down
21 changes: 15 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

## How to deploy

It is as simple as:
Prerequisites:
A postgres database with semver extension is needed. Using abrt/postgres_w_semver
image is recommended.
`docker run --name faf_db -dit abrt/postgres_w_semver`

`docker run --name faf -dit abrt/faf-image`
Running FAF is as simple as:

However you also probably want to mount volumes to `/var/lib/postgres` and
to `/var/spool/faf` not to lose database and FAF's data.
`docker run --name faf -dit --link faf_db abrt/faf-image`

`docker run --name faf -v /var/lib/faf-docker/faf:/var/spool/faf -v
/var/lib/faf-docker/postgres:/var/lib/postgres/ -dit abrt/faf-image`
However you also probably want to mount volumes to `/var/spool/faf` not to lose
FAF's data.

`docker run --name faf -v /var/lib/faf-docker/faf:/var/spool/faf --link faf_db
-dit abrt/faf-image`

Then FAF is ready for use.

Expand Down Expand Up @@ -43,6 +48,8 @@ To run any FAF action, please run them as faf user.

`make build_local` to build from currently checked out github branch

`make build_db` to build database

For easier using and debugging you can use also:

`make run` to run copr version of FAF
Expand All @@ -52,3 +59,5 @@ For easier using and debugging you can use also:
`make sh` to jump into bash in the container

`make del` to remove faf container

'make run_db' to run database
26 changes: 9 additions & 17 deletions docker/files/run_faf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash

mkdir -p /var/lib/postgres/data
chown postgres:postgres /var/lib/postgres/data
chmod 755 /var/lib/postgres

mkdir -p /var/spool/faf/reports/incoming /var/spool/faf/reports/saved /var/spool/faf/reports/deferred /var/spool/faf/lob /var/spool/faf/attachments/incoming
chown faf:faf /var/spool/faf/
chown -R faf:faf /var/spool/faf/reports
Expand All @@ -13,21 +9,17 @@ chmod 755 /var/spool/faf

if [ ! -f /var/lib/postgres/fafdb.created ]
then
sudo -u postgres /usr/bin/pg_ctl initdb -D /var/lib/postgres/data > /dev/null
sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/postgres/data -w > /dev/null

sudo -u postgres psql -c "CREATE USER faf;"
sudo -u postgres psql -c "CREATE DATABASE faf;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE faf TO faf;"
sudo -u postgres psql -c "ALTER USER faf WITH superuser;"
sudo -u faf psql -c "CREATE EXTENSION semver;"
sudo -u faf faf-migrate-db --create-all
sudo -u faf faf-migrate-db --stamp-only
sudo -u faf faf init
sudo -u faf faf pull-releases -o fedora
sudo -E -u postgres psql -c "CREATE USER faf;"
sudo -E -u postgres psql -c "CREATE DATABASE faf;"
sudo -E -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE faf TO faf;"
sudo -E -u postgres psql -c "ALTER USER faf WITH superuser;"
sudo -E -u faf psql -c "CREATE EXTENSION semver;"
sudo -E -u faf faf-migrate-db --create-all
sudo -E -u faf faf-migrate-db --stamp-only
sudo -E -u faf faf init
sudo -E -u faf faf pull-releases -o fedora
touch /var/lib/postgres/fafdb.created
else
sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/postgres/data -w > /dev/null
sudo -u faf faf-migrate-db
fi
crond
Expand Down

0 comments on commit 94d029d

Please sign in to comment.