4 ms·
Here is an example of post-receive script I use for that: #!/usr/bin/env bash export APP=appname export DOCKER_OPTS="" unset GIT_DIR rm -
by xu6ahb8E 6y ago
Here is an example of post-receive script I use for that:
#!/usr/bin/env bash
export APP=appname
export DOCKER_OPTS=""
unset GIT_DIR
rm -rf /home/username/apps/$APP
cd /home/username/apps && \
git clone /home/username/git/$APP && \
cd $APP && \
echo building image && \
docker build -t $APP .
if [[ "$?" != "0" ]]; then
echo "error while building image."
exit 1
fi
echo "Stopping previous container..."
docker stop $APP
echo "Starting new container..."
sleep 1
docker run -d --name $APP --rm $APP
- dugmartin 6y agoFYI, you can avoid the $APP directory removal and clone by doing: GIT_WORK_TREE=/home/username/apps/$APP git checkout master
- xu6ahb8E 6y agoYes, that's true, thanks for mentioning it. It comes from a time when I did not use docker so I wanted to get rid of build artifacts, but building within docker, this is not a problem anymore.
- c17r 6y agoIf you need to use your "old way" for something else, you can use 'git clean -fdx' which will remove all files and directories that git does not track.
- deleted 6y ago[deleted]
- phaemon 6y agoYou should at least use `set -u` in this script, otherwise, at some point, you'll fail to set $APP and end up running: rm -rf /home/username/apps/ Guess how I learned this lesson? :)
- Operyl 6y agoOoooh, I need to start documenting my war stories. They'll make for a fun read at some point years down the line.