Skip to content

Instantly share code, notes, and snippets.

@gdotdesign
Last active June 30, 2016 04:40
Show Gist options
  • Select an option

  • Save gdotdesign/e01f49fa9081bdfface44de8609d0887 to your computer and use it in GitHub Desktop.

Select an option

Save gdotdesign/e01f49fa9081bdfface44de8609d0887 to your computer and use it in GitHub Desktop.
Dockering

This is a base image for development purposes and a script to manage shared volumes and projects.

Installed services:

  • Postgresql 9.5
  • Redis
  • RVM
  • NodeJS
  • Dependecies for
    • ImageMagick
    • Postgresql

This thing has to following features:

  • Automatically installs ruby versions, gems and packages and makes them persisted
  • Databases datas (postges, redis) are persisted
  • Run projects with the script that manages the persisted container and the running containers for each project
FROM ubuntu:16.04
# Set Locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Setup
RUN apt-get update
RUN apt-get install --yes apt-utils curl git build-essential
# Zshell
RUN apt-get install --yes zsh
RUN git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh \
&& cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
&& chsh -s /bin/zsh
# Postgres
RUN apt-get install --yes postgresql postgresql-contrib postgresql-client libpq-dev
# Make sure we can access postgres
RUN echo "local all all trust" > /etc/postgresql/9.5/main/pg_hba.conf
# Postgis
RUN apt-get install --yes postgis postgresql-9.5-postgis-2.2
# Redis
RUN apt-get install --yes redis-server
# RVM
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable --with-default-gems="bundler"
# RVM Dependencies
RUN apt-get install -y curl patch gawk g++ gcc make libc6-dev patch libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
RUN /bin/bash -l -c "rvm requirements"
# NodeJS
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash -
RUN apt-get install -y nodejs
# RMagick
RUN apt-get install -y imagemagick libmagickwand-dev
# Cleanup
RUN rm -rf /var/lib/apt/lists/*
# Create start script
RUN echo '\
service postgresql start\n\
redis-server --daemonize yes\n\
cd /Project\n\
if [ -f ".ruby-version" ]; then\n\
rvm install `cat .ruby-version`\n\
rvm gemset use `cat .ruby-gemset` --create\n\
if ! gem spec bundler > /dev/null 2>&1; then\n\
gem install bundler\n\
fi\n\
bundle install\n\
fi\n\
if [ -f package.json ]; then\n\
npm install\n\
fi\n\
/bin/zsh -il' >> ~/start.sh
# Make sure we can run the start script
RUN chmod +x ~/start.sh
# Persist data between runs
VOLUME ["/var/lib/postgresql/9.5/main", "/var/lib/redis", "/usr/local/rvm", "/root", "/usr/lib/node_modules"]
# Cmd
CMD /bin/bash -l "/root/start.sh"
#!/bin/bash
project=$1
port=$2
container=$3
name=`basename $project`
if [[ $(docker ps -a | grep DOCKER_DB) == "" ]]; then
docker run -p $port:$port -it --name DOCKER_DB -v $project:/Project gdotdesign:base
else
docker rm $name > /dev/null
docker run -p $port:$port -it --name $name --volumes-from DOCKER_DB -v $project:/Project gdotdesign:base
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment