Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Building my own Docker image modeled after Heroku's production environment.
- # Started: 2017-07-25 based on a previous similar image that relies on MySQL instead.
- # WOULDDO:
- # • Set up user account so as to NOT run the image as root. e.g.: for Composer.
- # • Figure a way to log in to Heroku, but without commiting the logins to the image itself. e.g.: add config file via docker-compose.
- ##
- # INSTALL MY STACK: LINUX + APACHE + POSTGRES + PHP + pseudo-email + supervisor
- ##
- # 16.04 = Xenial
- FROM ubuntu:16.04
- # Avoid Dialog and other interactive features not suited to Dockerfiles
- ENV DEBIAN_FRONTEND noninteractive
- # Update and configure packages
- # Installing apt-utils to avoid `debconf: delaying package configuration, since apt-utils is not installed` warning when installing programs (except for `apt-utils` itself.)
- RUN apt-get update
- RUN apt-get install -y --no-install-recommends apt-utils
- # Set the timezone
- RUN apt-get install -y tzdata
- RUN echo "Europe/London" > /etc/timezone
- RUN dpkg-reconfigure -f noninteractive tzdata
- RUN ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
- # Install Apache httpd
- # Note: remember Ubuntu uses `/etc/apache2/sites-available/` and `/etc/apache2/sites-enabled/` for vhosts.
- # e.g.: we may want to alias the latter to the former to enable all vhosts. See my notes in `Docker.md`.
- RUN apt-get install -y apache2
- RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
- # Install Postgres
- # Should I install `postgresql-contrib` too? suffixed -9.6?
- RUN apt-get install -y software-properties-common
- RUN add-apt-repository -y "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
- RUN apt-get install -y wget
- RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add
- RUN apt-get update
- RUN apt-get install -y postgresql-9.6
- ENV PATH="${PATH}:/usr/lib/postgresql/9.6/bin"
- # Install PHP 5.6.30
- # Note the use of ppa:ondrej/php to install older PHP 5.6 on newer Ubuntu 16.04 -- until we move to PHP 7.
- # It's never clear to me where to see the list of available packages for `ppa:ondrej/php`.
- # See https://askubuntu.com/a/756186/441757 and https://github.com/oerdnj/deb.sury.org/issues/56#issuecomment-230329082
- # Note: I wanted to instal PHP-FPM. Doable with the below commands (just use `-fpm` prefix) but did not manage to get it to work.
- RUN apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
- RUN apt-get install -y software-properties-common
- RUN apt-get install -y language-pack-en-base
- RUN DEBIAN_FRONTEND=noninteractive LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php
- RUN apt-get update
- # Install PHP extensions
- # TO BE CLARIFIED: php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml -- do I need them? what for?
- # XHProf: php-pear php5-dev php5-mcrypt -- note only `php-pear` available from `ppa:ondrej/php`
- RUN apt-get install -y --allow-unauthenticated php5.6
- RUN apt-get install -y --allow-unauthenticated php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-dev php5.6-curl php5.6-zip php5.6-pgsql
- RUN apt-get install -y --allow-unauthenticated php-pear
- # Install supervisor
- # (We add its config file much later, as it depends on the other installed programs and is likely to change.
- # This way, we spare ourselves reinstalling things that didn't change when building the image.)
- RUN apt-get install -y supervisor
- # Install mhsendmail · “sendmail replacement which forwards mail to an SMTP server”
- # Requires go and git.
- # Note: we're aliasing sendmail to call mhsendmail. (Fine for a development platform, not so for a production platform.)
- # Alternative, e.g.: config php.ini to use it directly. Why not if/when we have one php.ini per environment.
- # `/usr/sbin/sendmail` is the default `sendmail_path` in php.ini (hence preferable to a `/usr/local/bin/sendmail` alias.)
- RUN apt-get install -y git
- RUN apt-get install -y wget
- RUN wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
- RUN sha256sum go1.8.1.linux-amd64.tar.gz
- RUN tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gz
- ENV PATH="${PATH}:/usr/local/go/bin"
- RUN mkdir -p /root/gocode \
- && export GOPATH=/root/gocode \
- && go get github.com/mailhog/mhsendmail \
- && mv /root/gocode/bin/mhsendmail /usr/local/bin \
- && rm -rf /root/gocode
- RUN ln -s /usr/local/bin/mhsendmail /usr/sbin/sendmail
- # Install MailHog · “email testing tool for developers”, i.e.: fake SMTP server for receiving my own outgoing mail.
- # Requires go and git.
- RUN mkdir -p /root/gocode \
- && export GOPATH=/root/gocode \
- && go get github.com/mailhog/MailHog \
- && mv /root/gocode/bin/MailHog /usr/local/bin \
- && rm -rf /root/gocode
- ##
- # INSTALL MORE DEV SOFTWARE
- ##
- # Install Composer
- # See https://getcomposer.org/download/ for latest version
- RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- RUN php composer-setup.php
- RUN php -r "unlink('composer-setup.php');"
- RUN mv composer.phar /usr/local/bin/composer
- # Install PHPUnit 5.7 (i.e.: for PHP 5.6)
- # Alternative: do so from Composer.
- RUN apt-get install -y wget
- RUN wget https://phar.phpunit.de/phpunit-5.7.phar
- RUN chmod +x phpunit-5.7.phar
- RUN mv phpunit-5.7.phar /usr/local/bin/phpunit
- RUN phpunit --version
- # Install BlackFire
- # See https://blackfire.io/docs/up-and-running/installation
- # CAREFUL! Personal LOGINS in here! (In the config files.)
- # WOULDDO: move those logins to environment variables.
- # For errors, check:
- # /etc/init.d/blackfire-agent status
- # Logs: `/var/log/blackfire/` and `/tmp/blackfire.log`
- # Let's disable it for now. I'm not using it.
- # RUN wget -O - https://packagecloud.io/gpg.key | apt-key add -
- # RUN echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list
- # RUN apt-get update
- # RUN apt-get install blackfire-agent
- # ADD config/agent /etc/blackfire/agent
- # #RUN blackfire-agent -register --server-id=b28430c8-380f-4117-9637-2a76cd5ddfdd --server-token=7dff98b95e60bb3c142f2752c6a536872e0a63a2d3d03df1c3d74a371a086e2e
- # #RUN apt-get install blackfire-agent
- # #RUN blackfire config --client-id="3a1dd7f3-bf2d-4a67-a34f-23f71f62d0c6" --client-token="df395989949be7174279da6ffb6c3314854ae41d8448ae8f15e73f081d38aea4" # does not work
- # ADD config/blackfire.ini /root/.blackfire.ini
- # RUN apt-get install blackfire-php
- # #RUN apache2ctl restart
- # Install Heroku CLI
- # Last because the install process changes frequently.
- # WOULDDO: maybe install PHP Buildpack too?
- RUN echo "FORCE HEROKU CLI UPDATE" # Need to rebuild the image once in a while when a new version of the Heroku CLI is available. NEXT TIME: may want to move it to end of file.
- RUN wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
- ##
- # TEMPORARY OR NON-CRITICAL
- ##
- # Re-install MySQL (MariaDB) to let us convert from MySQL to Postgres
- RUN apt-get update # without it (depsite an earlier identical command), it fails to grab `0.90ubuntu0.5` (not found) instead of fetching `0.90ubuntu0.6`.
- RUN apt-get install -y mariadb-server mariadb-client
- # Pgloader
- RUN apt-get install -y pgloader
- # Test
- # RUN chown -R postgres:postgres /var/lib/postgresql/9.6/main/
- # RUN chmod -R u+rwx,g-rwx,o-rwx /var/lib/postgresql/9.6/main/
- # PORTS TO EXPOSE
- # 22: SSH
- # 80: TCP, HTTP
- # 8025: MailHog UI (web)
- # 3306: MySQL to connect via a client (e.g.: Sequel Pro) -- but failed to get this to work.
- # 5432: Postgres -- but I did not need to export the MySQL port for things to work… So it's confusing why and whether I would need it here.
- EXPOSE 22 80 8025 3306 5432
- # Entry point for when the image starts
- ADD supervisord.conf /etc/
- CMD ["/usr/bin/supervisord"]
- ## MEMO.
- #
- # BUILD THE IMAGE LIKE SO:
- # cd /Users/fabien/Dropbox/DEV/Docker/images/img-fab-ubuntu-postgres
- # docker build -t fab/ubuntu-postgres .
- # Use `--no-cache` if needed.
- #
- # START THE IMAGE VIA DOCKER TO CHECK IT OUT:
- # docker run --name myubuntu -dit fab/ubuntu-postgres
- # docker exec -it myubuntu /bin/bash
- #
- # Besides installing programs here, remember to set them up to run inside of `supervisord.conf`!
- # Check they're actually running with `service --status-all`
- #
- # STATS: 2017-06-07, 12 min to build.
Advertisement
Add Comment
Please, Sign In to add comment