diff --git a/README.md b/README.md new file mode 100644 index 0000000..329da97 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# docker-ruby + +This repository provides Dockerfiles for Alpine and CentOS based images with Ruby. Dockerfiles are generated with pre-commit git hook (`./git-hooks/pre-commit`) and corresponding template in the project's root, so one needs to run `git config core.hooksPath git-hooks` first in order to use it. + +Alpine template is based on official [docker-library/ruby](https://github.com/docker-library/ruby). diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit new file mode 100755 index 0000000..2ea8661 --- /dev/null +++ b/git-hooks/pre-commit @@ -0,0 +1,27 @@ +#!/bin/bash +# Script is used to generate all the necessary Dockerfiles based on the templates + +declare -a ruby_versions=("2.5.3" "2.6.2" "2.6.3" "2.6.5") +declare -a distributions=("alpine:3.12" "centos:7") + +for i in "${distributions[@]}" +do + DISTRO_NAME="$(cut -d ':' -f1 <<< $i)" + DISTRO_VERSION="$(cut -d ':' -f2 <<< $i)" + + for j in "${ruby_versions[@]}" + do + # E.g. ./alpine/3.11/2.5.3 + TARGET_DIR="./generated/$DISTRO_NAME/$DISTRO_VERSION/$j" + RUBY_MAJOR="$(echo $j | grep --only-matching -E '[[:digit:]]+\.[[:digit:]]+')" + + mkdir --parents $TARGET_DIR + cp ./Dockerfile.$DISTRO_NAME.template $TARGET_DIR/Dockerfile + + sed -i "s/{RUBY_VERSION}/$j/g" $TARGET_DIR/Dockerfile + sed -i "s/{RUBY_MAJOR}/$RUBY_MAJOR/g" $TARGET_DIR/Dockerfile + sed -i "s/{DISTRO_VERSION}/$DISTRO_VERSION/g" $TARGET_DIR/Dockerfile + done +done + +git add ./generated