ynd-docker-ruby/git-hooks/pre-commit

28 lines
882 B
Bash
Executable File

#!/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.11" "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