|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e +x -o pipefail |
| 4 | + |
| 5 | +function bootstrap_docker() |
| 6 | +{ |
| 7 | + sudo apt-get update --quiet --quiet |
| 8 | + sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common jq |
| 9 | + |
| 10 | + export CODENAME=$(source /etc/os-release && echo "$VERSION_CODENAME") |
| 11 | + export DISTRO=$(source /etc/os-release && echo "$ID") |
| 12 | + export ARCH=$(dpkg --print-architecture) |
| 13 | + # get gpg key for download.docker |
| 14 | + curl -fsSL https://download.docker.com/linux/${DISTRO}/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/download.docker.gpg |
| 15 | + sudo tee <<<"deb [arch=${ARCH}] https://download.docker.com/linux/${DISTRO} ${CODENAME} stable" /etc/apt/sources.list.d/download.docker.list |
| 16 | + sudo apt update --quiet --quiet |
| 17 | + sudo apt install docker-ce docker-ce-cli docker-compose-plugin |
| 18 | + sudo usermod -a -G docker vagrant |
| 19 | +} |
| 20 | + |
| 21 | +function build() |
| 22 | +{ |
| 23 | + local CODENAME="$1" |
| 24 | + |
| 25 | + date_suffix=$(date +%Y-%m-%d) |
| 26 | + |
| 27 | + echo "Building packagingbuild image..." |
| 28 | + (docker build --progress plain -f "packagingbuild/${CODENAME}/Dockerfile" -t "stackstorm/packagingbuild:${CODENAME}" -t "stackstorm/packagingbuild:${CODENAME}-${date_suffix}" .) || exit -1 |
| 29 | + |
| 30 | + echo "Building packagingtest image..." |
| 31 | + (docker build --progress plain -f "packagingtest/${CODENAME}/Dockerfile" -t "stackstorm/packagingtest:${CODENAME}" -t "stackstorm/packagingtest:${CODENAME}-${date_suffix}" .) || exit -1 |
| 32 | +} |
| 33 | + |
| 34 | +function build_target() |
| 35 | +{ |
| 36 | + local CODENAME="$1" |
| 37 | + for DOCKERFILE in packagingbuild/$CODENAME/Dockerfile |
| 38 | + do |
| 39 | + TARGET_PATH=$(dirname $DOCKERFILE) |
| 40 | + TARGET=$(basename $TARGET_PATH) |
| 41 | + build $TARGET |
| 42 | + done |
| 43 | +} |
| 44 | + |
| 45 | +function usage() |
| 46 | +{ |
| 47 | + cat <<EOF |
| 48 | +Usage $0 <bootstrap|build [distro]> |
| 49 | +
|
| 50 | + bootstrap - Configure the system with the Docker repository and |
| 51 | + install Docker CE and Docker Compose packages. (Ubuntu only) |
| 52 | + build [distro] - Build the Docker images for the given distro codename. |
| 53 | + Builds all distros when no codename provided. |
| 54 | +
|
| 55 | +EOF |
| 56 | +} |
| 57 | + |
| 58 | +if [[ $# -eq 0 ]]; then |
| 59 | + usage |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +case "$1" in |
| 64 | + "bootstrap") |
| 65 | + bootstrap_docker |
| 66 | + ;; |
| 67 | + "build") |
| 68 | + if [[ -n "$2" ]]; then |
| 69 | + build_target "$2" |
| 70 | + else |
| 71 | + build_target '*' |
| 72 | + fi |
| 73 | + ;; |
| 74 | + *) |
| 75 | + usage |
| 76 | + exit 1 |
| 77 | + ;; |
| 78 | +esac |
0 commit comments