diff --git a/Makefile b/Makefile index 984b189..7246e8b 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,37 @@ .PHONY: build build: ## Builds all the dockerfiles in the repository. - ./build-all.sh + @$(CURDIR)/build-all.sh .PHONY: latest-versions latest-versions: ## Checks all the latest versions of the Dockerfile contents. - ./latest-versions.sh + @$(CURDIR)/latest-versions.sh + +check_defined = \ + $(strip $(foreach 1,$1, \ + $(call __check_defined,$1,$(strip $(value 2))))) +__check_defined = \ + $(if $(value $1),, \ + $(error Undefined $1$(if $2, ($2))$(if $(value @), \ + required by target `$@'))) + +.PHONY: run +run: ## Run a Dockerfile from the command at the top of the file (ex. DIR=telnet). + @:$(call check_defined, DIR, directory of the Dockefile) + @$(CURDIR)/run.sh "$(DIR)" .PHONY: test test: shellcheck dockerfiles ## Runs the tests on the repository. .PHONY: dockerfiles dockerfiles: ## Tests the changes to the Dockefiles build. - ./test.sh + @$(CURDIR)/test.sh # if this session isn't interactive, then we don't want to allocate a # TTY, which would fail, but if it is interactive, we do want to attach # so that the user can send e.g. ^C through. INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0) ifeq ($(INTERACTIVE), 1) - DOCKER_FLAGS += -t + DOCKER_FLAGS += -t endif .PHONY: shellcheck diff --git a/run.sh b/run.sh index 9fe156e..aa2f750 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # This script allows you to launch several images # from this repository once they're built. @@ -8,29 +8,32 @@ # can find it and execute it. # # Use pulseaudio/Dockerfile and skype/Dockerfile as examples. +set -e +set -o pipefail -if [ $# -eq 0 ]; then +if [[ $# -eq 0 ]]; then echo "Usage: $0 [--test] image1 image2 ..." exit 1 fi -if [ "$1" = "--test" ]; then +if [[ "$1" = "--test" ]]; then TEST=1 shift fi for name in "$@"; do - if [ ! -d $name ]; then - echo "unable to find container configuration with name $name" + if [[ ! -d "$name" ]]; then + echo "Unable to find container configuration with name: $name" exit 1 fi - script=`sed -n '/docker run/,/^#$/p' $name/Dockerfile | head -n -1 | sed -e 's/\#//' | sed -e 's/\\\//'` + script=$(sed -n '/docker run/,/^#$/p' "$name/Dockerfile" | head -n -1 | sed "s/#//" | sed "s#\\\##" | tr '\n' ' ' | sed "s/\$@//" | sed 's/""//') + echo "Running: $script" if [ $TEST ]; then - echo $script + echo "$script" else - eval $script + eval "$script" fi shift diff --git a/telnet/Dockerfile b/telnet/Dockerfile index 613170d..f13c3f0 100644 --- a/telnet/Dockerfile +++ b/telnet/Dockerfile @@ -1,7 +1,7 @@ # command to run Telnet # docker run -it --rm \ # --log-driver none \ -# jess/telnet "$@" +# jess/telnet towel.blinkenlights.nl # FROM alpine:latest LABEL maintainer "Jessie Frazelle "