diff --git a/Dockerfile b/Dockerfile index 84c7fe2..341baa3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,6 +63,12 @@ RUN ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/defau ADD ./index.php /usr/share/nginx/html/index.php RUN chown -Rf nginx.nginx /usr/share/nginx/html/ +# Add git commands to allow container updating +ADD ./pull /usr/bin/pull +ADD ./push /usr/bin/push +RUN chmod 755 /usr/bin/pull +RUN chmod 755 /usr/bin/push + # Supervisor Config RUN /usr/bin/easy_install supervisor RUN /usr/bin/easy_install supervisor-stdout diff --git a/README.md b/README.md index e77673b..30bac79 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,16 @@ sudo docker run -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -v ## Special Features +### Push code to Git +To push code changes back to git simply run: +``` +sudo docker exec -t -i /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: +``` +sudo docker exec -t -i /usr/bin/pull +``` ### Templating This container will automatically configure your web application if you template your code. For example if you are linking to MySQL like above, and you have a config.php file where you need to set the MySQL details include $$_MYSQL_ENV_MYSQL_DATABASE_$$ style template tags. diff --git a/pull b/pull new file mode 100755 index 0000000..8a726da --- /dev/null +++ b/pull @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ -z "$GIT_EMAIL" ]; then + echo "You need to pass the \$GIT_EMAIL variable to the container for this to work" + exit +fi + +if [ -z "$GIT_NAME" ]; then + echo "You need to pass the \$GIT_NAME variable to the container for this to work" + exit +fi + +cd /usr/share/nginx/html +git pull diff --git a/push b/push new file mode 100755 index 0000000..4fb06cb --- /dev/null +++ b/push @@ -0,0 +1,21 @@ +#!/bin/bash + +timestamp() { + date +"%D %T" +} + +if [ -z "$GIT_EMAIL" ]; then + echo "You need to pass the \$GIT_EMAIL variable to the container for this to work" + exit +fi + +if [ -z "$GIT_NAME" ]; then + echo "You need to pass the \$GIT_NAME variable to the container for this to work" + exit +fi + +ts=$(timestamp) +cd /usr/share/nginx/html +git add * +git commit -a -m "push from container $ts" +git push diff --git a/start.sh b/start.sh index 0781b1d..dd3a739 100644 --- a/start.sh +++ b/start.sh @@ -5,6 +5,15 @@ mkdir -p -m 0700 /root/.ssh echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config +# Setup git variables +if [ ! -z "$GIT_EMAIL" ]; then + git config --global user.email "$GIT_EMAIL" +fi +if [ ! -z "$GIT_NAME" ]; then + git config --global user.name "$GIT_NAME" + git config --global push.default simple +fi + # Pull down code form git for our site! if [ ! -z "$GIT_REPO" ]; then rm /usr/share/nginx/html/*