From 20784cc5ad2baee710004a2f3ba258bff37da310 Mon Sep 17 00:00:00 2001 From: Ashwanth Kumar Date: Sun, 7 Aug 2016 22:22:05 +0530 Subject: [PATCH] Moving the long RUN command into a shell script Adding support for catching the command failure and restoring the permissions of the build dir so go can still Clean up the directory. 2. Adding support for pre_package hook that runs before the slug tarball is generated --- Dockerfile | 14 +++++--------- README.md | 3 +++ build-slug | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 build-slug diff --git a/Dockerfile b/Dockerfile index 03a8e59..09948c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,14 +16,10 @@ RUN curl --silent http://dl.gliderlabs.com/herokuish/latest/linux_x86_64.tgz \ | tar -xzC /bin COPY mesos-fix /bin/mesos-fix +COPY build-slug /bin/build-slug RUN /bin/herokuish buildpack install \ - && chmod +x /bin/mesos-fix - -CMD bash -c "addgroup --gid $GROUP_ID go \ - && adduser -q --disabled-password --gid $GROUP_ID --uid $USER_ID --gecos \"\" --shell /bin/bash --home /var/go go \ - && (/bin/herokuish buildpack build || chown -R go:go /app && false) \ - && /bin/mesos-fix \ - && /bin/herokuish slug generate \ - && /bin/herokuish slug export > /app/app.tar.gz \ - && chown -R go:go /app" + && chmod +x /bin/mesos-fix \ + && chmod +x /bin/build-slug + +CMD /bin/build-slug diff --git a/README.md b/README.md index 0fd63ff..aa0c483 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,8 @@ We expect the app material to be mounted on `/app` inside the container. After l $ docker run -e USER_ID="$(id -u $(whoami))" -e GROUP_ID="$(id -g $(whoami))" -v $PWD/app:/app ind9/python-stack ``` +## Hooks +- `bin/pre_package` - Run before the generating the slug tarball. Any changes to the directory structure will be reflected in the generated slug. + ### Note We need to do that `id` foo while doing `docker run` because else the mounted directory would have root files which GoCD can't delete or overwrite on the next run. diff --git a/build-slug b/build-slug new file mode 100644 index 0000000..6e03a2c --- /dev/null +++ b/build-slug @@ -0,0 +1,26 @@ +#!/bin/bash + +set -x -e + +run_in_sandbox() { + CMD=$1 + bash -c "${CMD} || (chown -R go:go /app && false)" +} + +addgroup --gid $GROUP_ID go +adduser -q --disabled-password --gid $GROUP_ID --uid $USER_ID --gecos \"\" --shell /bin/bash --home /var/go go +run_in_sandbox "/bin/herokuish buildpack build" +run_in_sandbox /bin/mesos-fix + +# Experimental - bin/pre_package hook run before the generating the slug tarball +pushd /app +if [ -f bin/pre_package ]; then + echo "-----> Running pre_package hook" + chmod +x bin/pre_package + ./bin/pre_package +fi +popd + +run_in_sandbox "/bin/herokuish slug generate" +run_in_sandbox "/bin/herokuish slug export > /app/app.tar.gz" +chown -R go:go /app