susom/docker-nginx-php-git

Name: docker-nginx-php-git

Owner: Stanford School of Medicine

Description: :whale: Docker Image with Nginx, PHP-FPM, Git auto-pull and webhooks

Forked from: eduwass/docker-nginx-php-git

Created: 2017-02-28 00:24:37.0

Updated: 2017-02-28 00:34:15.0

Pushed: 2017-03-11 16:37:53.0

Homepage: null

Size: 34

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

docker-nginx-php-git

Minimal base image for hosting Nginx + PHP-FPM powered websites with Automatic Git Deployment functionalities including Webhooks

Configuration
Available Configuration Parameters

The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.

Dynamically Pulling code from git

One of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time.

Note: You need to have your SSH key that you use with git to enable the deployment. I recommend using a special deploy key per project to minimise the risk.

Preparing your SSH key

The container expects you pass it the SSH_KEY variable with a base64 encoded private key. First generate your key and then make sure to add it to github and give it write permissions if you want to be able to push code back out the container. Then run:

64 /path_to_your_key

Note: Copy the output be careful not to copy your prompt

To run the container and pull code simply specify the GIT_REPO URL including git@ and then make sure you have also supplied your base64 version of your ssh deploy key:

 docker run -d -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm

To pull a repository and specify a branch add the GIT_BRANCH environment variable:

 docker run -d -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -e 'GIT_BRANCH=stage' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm
Enabling SSL or Special Nginx Configs

You can either map a local folder containing your configs to /etc/nginx or we recommend editing the files within conf directory that are in the git repo, and then rebuilding the base image.

Lets Encrypt support (Experimental)
Setup

You can use Lets Encrypt to secure your container. Make sure you start the container `DOMAIN, GIT_EMAILand ``WEBROOT``` variables to enable this to work. Then run:

 docker exec -t <CONTAINER_NAME> /usr/bin/letsencrypt-setup

Ensure your container is accessible on the `DOMAIN` you supply in order for this to work

Renewal

Lets Encrypt certs expire every 90 days, to renew simply run:

 docker exec -t <CONTAINER_NAME> /usr/bin/letsencrypt-renew
Special Git Features

You'll need some extra ENV vars to enable this feature. These are `GIT_EMAILand ``GIT_NAME```. This allows git to be set up correctly and allow the following commands to work.

docker-hook - Git Webhook

docker-hook is preconfigured to listen to incoming HTTP requests on port 8555

All you have to do is setup the GIT_HOOK_TOKEN env var, and any requests to http://yourdomain:8555/<GIT_HOOK_TOKEN> will trigger a Git pull

You can also enable docker-hook on your default nginx ports with DOCKER_HOOK_PROXY. If enabled, you can POST your github webhook to http(s)://yourdomain/docker-hook/<GIT_HOOK_TOKEN> without using port 8555.

More info on how it works here: schickling/docker-hook

Push code to Git

To push code changes made within the container back to git simply run:

 docker exec -t -i <CONTAINER_NAME> /usr/bin/push
Pull code from Git (Refresh)

In order to refresh the code in a container and pull newer code form git simply run:

 docker exec -t -i <CONTAINER_NAME> /usr/bin/pull
Templating

NOTE: You now need to enable templates see below This container will automatically configure your web application if you template your code.

Using environment variables

For example if you are using a MySQL server, and you have a config.php file where you need to set the MySQL details include $$MYSQL_HOST$$ style template tags.

Example config.php::

p
base_host = $$_MYSQL_HOST_$$;
base_user = $$_MYSQL_USER_$$;
base_pass = $$_MYSQL_PASS_$$


To set the variables simply pass them in as environmental variables on the docker command line.

Example:

 docker run -d -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -e 'SSH_KEY=base64_key' -e 'TEMPLATE_NGINX_HTML=1' -e 'GIT_BRANCH=stage' -e 'MYSQL_HOST=host.x.y.z' -e 'MYSQL_USER=username' -e 'MYSQL_PASS=supper_secure_password' richarvey/nginx-php-fpm

This will expose the following variables that can be used to template your code.

L_HOST=host.x.y.z
L_USER=username
L_PASS=password
Template anything

Yes ANYTHING, any variable exposed by the -e flag lets you template your configuration files. This means you can add redis, mariaDB, memcache or anything you want to your application very easily.

Logging and Errors
Logging

All logs should now print out in stdout/stderr and are available via the docker logs command:

er logs <CONTAINER_NAME>
Thanks to

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.