Skip to content

Instantly share code, notes, and snippets.

@andreybolonin
Created October 17, 2016 10:32
Show Gist options
  • Save andreybolonin/922e7118e848828a98fd3c84b000c1cf to your computer and use it in GitHub Desktop.
Save andreybolonin/922e7118e848828a98fd3c84b000c1cf to your computer and use it in GitHub Desktop.
# PHPUnit Docker Container.
FROM ubuntu:latest
MAINTAINER Julien Breux <julien.breux@gmail.com>
#RUN apk --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing add \
# bash \
# ca-certificates \
# git \
# curl \
# unzip \
# php7 \
# php7-xml \
# php7-zip \
# php7-xmlreader \
# php7-zlib \
# php7-opcache \
# php7-mcrypt \
# php7-openssl \
# php7-curl \
# php7-ctype \
# php7-intl \
# php7-mbstring \
# php7-json \
# php7-dom \
# php7-phar \
# php7-mbstring \
# php7-bcmath \
# php7-pdo \
# php7-pdo_pgsql \
# php7-pdo_sqlite \
# php7-pdo_mysql \
# php7-soap \
# php7-xdebug \
# php7-pcntl
RUN apt-get update && apt-get install -y php7.0 php7.0-intl php7.0-zip php7.0-mbstring php7.0-mysql phpunit git curl software-properties-common
WORKDIR /tmp
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql
# add gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && 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 --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true \
&& apt-get purge -y --auto-remove ca-certificates wget
RUN mkdir /docker-entrypoint-initdb.d
# install "pwgen" for randomizing passwords
# install "apt-transport-https" for Percona's repo (switched to https-only)
RUN apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https ca-certificates \
pwgen \
&& rm -rf /var/lib/apt/lists/*
# Key fingerprint = 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
# MariaDB Package Signing Key <package-signing-key@mariadb.org>
# Key fingerprint = 430B DF5C 56E7 C94E 848E E60C 1C4C BDCD CD2E FD2A
# Percona MySQL Development Team <mysql-dev@percona.com>
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \
&& apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A
RUN echo "deb https://repo.percona.com/apt jessie main" > /etc/apt/sources.list.d/percona.list \
&& { \
echo 'Package: *'; \
echo 'Pin: release o=Percona Development Team'; \
echo 'Pin-Priority: 998'; \
} > /etc/apt/preferences.d/percona
ENV MARIADB_MAJOR 10.1
ENV MARIADB_VERSION 10.1.18+maria-1~jessie
RUN echo "deb http://ftp.osuosl.org/pub/mariadb/repo/$MARIADB_MAJOR/debian jessie main" > /etc/apt/sources.list.d/mariadb.list \
&& { \
echo 'Package: *'; \
echo 'Pin: release o=MariaDB'; \
echo 'Pin-Priority: 999'; \
} > /etc/apt/preferences.d/mariadb
# add repository pinning to make sure dependencies from this MariaDB repo are preferred over Debian dependencies
# libmariadbclient18 : Depends: libmysqlclient18 (= 5.5.42+maria-1~wheezy) but 5.5.43-0+deb7u1 is to be installed
# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
# also, we set debconf keys to make APT a little quieter
RUN { \
echo mariadb-server-$MARIADB_MAJOR mysql-server/root_password password 'root'; \
echo mariadb-server-$MARIADB_MAJOR mysql-server/root_password_again password 'root'; \
} | debconf-set-selections \
&& apt-get update \
&& apt-get install -y \
mariadb-server=$MARIADB_VERSION \
# percona-xtrabackup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos
percona-xtrabackup \
socat \
&& rm -rf /var/lib/apt/lists/* \
# comment out any "user" entires in the MySQL config ("docker-entrypoint.sh" or "--user" will handle user switching)
&& sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/* \
# purge and re-create /var/lib/mysql with appropriate ownership
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
&& chmod 777 /var/run/mysqld
# comment out a few problematic configuration values
# don't reverse lookup hostnames, they are usually another container
RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
&& echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf \
&& mv /tmp/my.cnf /etc/mysql/my.cnf
VOLUME /var/lib/mysql
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 3306
CMD ["mysqld"]
# install mariadb
#RUN apt-get -y install mariadb-server mariadb-client \
# && /etc/init.d/mysql stop \
# && /etc/init.d/mysql start
#
## Declare
#VOLUME ["/var/lib/mysql"]
#EXPOSE 3306
#CMD ["mysqld"]
#
#RUN echo mariadb-server-$MARIADB_MAJOR mysql-server/root_password password 'root' \
# && echo mariadb-server-$MARIADB_MAJOR mysql-server/root_password_again password 'root';
# install java
#RUN add-apt-repository -y ppa:webupd8team/java \
# && apt-get update \
# && echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections \
# && apt-get -y install oracle-java8-installer
#
## install Elastic
#RUN wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add - \
# && echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list \
# && apt-get -y update && apt-get -y install elasticsearch \
# && update-rc.d elasticsearch defaults 95 10 \
# && echo "network.bind_host: 0" >> /etc/elasticsearch/elasticsearch.yml \
# && echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml \
# && /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/2.0 \
# && /usr/share/elasticsearch/bin/plugin install royrusso/elasticsearch-HQ \
# && /etc/init.d/elasticsearch restart
# install rabbitmq
#RUN echo 'deb http://www.rabbitmq.com/debian/ testing main' | tee /etc/apt/sources.list.d/rabbitmq.list \
# && wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add - \
# && apt-get -y update \
# && apt-get -y install rabbitmq-server \
# && rabbitmq-plugins enable rabbitmq_management \
# && /etc/init.d/rabbitmq-server restart
#VOLUME ["/app"]
#WORKDIR /app
#ENTRYPOINT ["/usr/local/bin/phpunit"]
#CMD ["--help"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment