Skip to content

Instantly share code, notes, and snippets.

@jacobrask
Created October 14, 2014 18:40
Show Gist options
  • Save jacobrask/bdedcbb06a0483cfa70f to your computer and use it in GitHub Desktop.
Save jacobrask/bdedcbb06a0483cfa70f to your computer and use it in GitHub Desktop.
Critic Docker manager
#!/bin/bash
function install {
# Stop and clean up existing containers
docker ps -a | grep critic | awk '{print $1}' | xargs docker rm -f
# Run a postgres container based on the standard Docker postgres image
docker run --name critic-postgres -d postgres
# Build a Critic image based on Debian
cat > Dockerfile << EOF
FROM debian:wheezy
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y -qq && apt-get install -y -qq git python apache2 postgresql \
libapache2-mod-wsgi postgresql-client python-passlib python-psycopg2 python-pygments python-requests
ADD ./ /opt/critic
WORKDIR /opt/critic
RUN git reset --hard HEAD && git clean -dfx
EOF
docker build -q --force-rm -t critic/base .
rm -f Dockerfile
# Install Critic in a new container
docker run --name critic-installed \
--link critic-postgres:postgres -e "PGHOST=postgres" \
critic/base \
python ./install.py --headless --auth-mode critic \
--admin-username admin --admin-password 1234 \
--admin-fullname Administrator --admin-email admin@localhost \
--system-username critic --system-email admin@localhost --skip-testmail
# Save changes from install to a new image
docker commit critic-installed critic/app
}
function run {
# Run Critic as a daemon, with Apache in the foreground to keep the container running
docker rm -f critic
docker run --name critic -d -p 8080:80 \
--link critic-postgres:postgres -e "PGHOST=postgres" \
critic/app \
/bin/bash -c "service critic-main restart && apachectl -DFOREGROUND"
}
function update {
# Create temporary Dockerfile to ADD files to critic/app
cat > Dockerfile << EOF
FROM critic/app
ADD ./ /opt/critic
WORKDIR /opt/critic
EOF
docker build -q --force-rm -t critic/app .
rm -f Dockerfile
docker rm -f critic
docker run --name critic \
--link critic-postgres:postgres -e "PGHOST=postgres" \
critic/app \
/bin/bash -c "git reset --hard HEAD && git clean -dfx &&
python ./upgrade.py --headless"
# Save changes
docker commit critic critic/app
run
}
$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment