Skip to content

Instantly share code, notes, and snippets.

@ryansch
Last active October 24, 2017 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryansch/b313d0068922d51334c9c7a459e3fbec to your computer and use it in GitHub Desktop.
Save ryansch/b313d0068922d51334c9c7a459e3fbec to your computer and use it in GitHub Desktop.
Docker snippet for rubygems

Usage:

dev build

dev run --rm projectname rspec

OR

dev run --rm projectname ruby -Ilib:../lib test/test_foo.rb

version: '2'
services:
projectname:
build: .
image: projectname:dev
stdin_open: true
tty: true
volumes:
- bundler-data:/usr/local/bundle
- .:/srv
volumes:
bundler-data:
driver: local
#!/bin/dumb-init /bin/bash
if [ "$(stat -c %u /usr/local/bundle)" = '0' ]; then
chown deploy:deploy /usr/local/bundle
fi
if [ "$(which "$1")" = '' ]; then
if [ "$(ls -A /usr/local/bundle/bin)" = '' ]; then
echo 'command not in path and bundler not initialized'
echo 'running bundle install'
gosu deploy bundle install
fi
fi
if [ "$1" = 'bundle' ]; then
set -- gosu deploy "$@"
elif [ "$1" = 'ruby' ]; then
set -- gosu deploy "$@"
gosu deploy bash -c 'bundle check || bundle install'
elif ls /usr/local/bundle/bin | grep -q "\b$1\b"; then
set -- gosu deploy bundle exec "$@"
gosu deploy bash -c 'bundle check || bundle install'
fi
exec "$@"
FROM outstand/ruby-base:2.4.2-alpine
RUN addgroup -S deploy && \
adduser -S -G deploy deploy && \
mv /usr/local/bin/rake /usr/local/bin/rake.back && \
apk add --no-cache bash build-base linux-headers tzdata curl curl-dev less && \
apk upgrade --no-cache
WORKDIR /srv
COPY . /srv/
RUN chown -R deploy:deploy /srv
COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment