Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Moving the long RUN command into a shell script
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ashwanthkumar committed Aug 7, 2016
1 parent d819da7 commit 20784cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
26 changes: 26 additions & 0 deletions build-slug
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 20784cc

Please sign in to comment.