Skip to content

Instantly share code, notes, and snippets.

@leftdevel
Last active September 19, 2016 16:57
Show Gist options
  • Save leftdevel/885182b421247a25919c5cf02192f09d to your computer and use it in GitHub Desktop.
Save leftdevel/885182b421247a25919c5cf02192f09d to your computer and use it in GitHub Desktop.
Docker JQJobs db.
# Warning. This is just a test DB. Use this when testing the webapp, autoscaler or notifications services.
# Connecting to the prod DB is done on convox dashboard by setting the connection parameters as ENV variables.
FROM ubuntu:16.04
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# install supporting packages.
RUN apt-get update && apt-get install -y python-software-properties software-properties-common git curl zip unzip \
# Install PostgreSQL
postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 \
# Install php
php php7.0-xml php7.0-zip php7.0-pgsql
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Download jqjobs
ENV JQJOBS_ROOT_DIR /jqjobs
RUN git clone --depth=1 https://github.com/apinstein/jqjobs.git $JQJOBS_ROOT_DIR
RUN cd $JQJOBS_ROOT_DIR && composer install
# Patch mp/Migrator.php to make it compatible with PHP7.
# it will turn `$migration->$info['migrateF']($this);` into `$migration->{$info['migrateF']}($this);`
RUN sed -i "s/\$migration->\$info\['migrateF'\](\$this);/\$migration->{\$info['migrateF']}(\$this);/g" $JQJOBS_ROOT_DIR/vendor/apinstein/mp/Migrator.php
RUN chown -R postgres $JQJOBS_ROOT_DIR
# Run the rest of the commands as the ``postgres`` user.
USER postgres
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/9.3/main/pg_hba.conf
# Disable password protection completely
RUN sed -i 's/md5/trust/g' /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Create the schema + tables.
RUN /etc/init.d/postgresql start \
&& createdb -U postgres jqjobs_test \
&& cd $JQJOBS_ROOT_DIR \
&& ./vendor/bin/mp -x'pgsql:dbname=jqjobs_test;user=postgres;host=localhost' -r -m head \
&& /etc/init.d/postgresql stop
EXPOSE 5432
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment