Created
February 8, 2018 18:54
-
-
Save agate/513f669a86a52ed7190de6698360cd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function colorize_echo() { echo -e "\033[0;${1}m${@:2}\033[0m"; } | |
function red_echo() { colorize_echo 31 $@; } | |
function green_echo() { colorize_echo 32 $@; } | |
function yellow_echo() { colorize_echo 33 $@; } | |
function blue_echo() { colorize_echo 34 $@; } | |
CURRENT_DIR="$(pwd)" | |
DIR_NAME=docker-ruby-bundle-test | |
IMAGE_NAME=$DIR_NAME:latest | |
blue_echo "Create test dir" | |
mkdir -p $DIR_NAME | |
cd $DIR_NAME | |
blue_echo "Create dockerfile" | |
cat <<END > Dockerfile | |
FROM ruby:2.3 | |
ADD Gemfile /tmp/bundle/ | |
RUN cd /tmp/bundle && bundle install | |
END | |
blue_echo "Create gemfile" | |
cat <<END > Gemfile | |
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem "json", "2.0.3" | |
END | |
blue_echo "Build docker image" | |
docker build --tag $IMAGE_NAME . | |
blue_echo "Problem demo A" | |
docker run --rm $IMAGE_NAME bash -c ' | |
echo hostname: | |
hostname | |
echo pwd: | |
pwd | |
echo ls: | |
echo `ls` | |
echo bundle: | |
bundle' | |
red_echo "What? How pwd:/ can run bundle? Where is the Gemfile?" | |
blue_echo "Problem demo B" | |
docker run --rm $IMAGE_NAME bash -c ' | |
echo hostname: | |
hostname | |
echo pwd: | |
pwd | |
echo ls: | |
echo `ls` | |
cat <<END > Gemfile | |
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem "json", "2.0.4" | |
END | |
bundle' | |
red_echo "What? Why still use the json 2.0.3?" | |
blue_echo "Problem demo C" | |
docker run --rm $IMAGE_NAME bash -c ' | |
cd /tmp/bundle | |
echo hostname: | |
hostname | |
echo pwd: | |
pwd | |
echo ls: | |
echo `ls` | |
cat <<END > Gemfile | |
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem "json", "2.0.4" | |
END | |
bundle' | |
green_echo "OK... Now it works." | |
blue_echo "Cleanup" | |
docker rmi $IMAGE_NAME | |
cd "$CURRENT_DIR" | |
rm -rf $DIR_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment