aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-04-08 14:16:48 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-04-08 14:16:48 +0200
commit6a336f0167393318639b6bc1c9ccf0484219c970 (patch)
tree216ec664235bb02adc56beebab1e5fc7daec7a74
parent2b8fac1454b3ca9077621420cedda3c228a87466 (diff)
Rewrite the build-docker action
-rw-r--r--.dockerignore8
-rw-r--r--lib/actions/build-docker.bash108
-rw-r--r--lib/docker/alpine.Dockerfile (renamed from lib/docker/alpine)12
-rw-r--r--lib/docker/archlinux.Dockerfile (renamed from lib/docker/archlinux)12
-rw-r--r--lib/docker/centos.Dockerfile (renamed from lib/docker/centos)11
-rw-r--r--lib/docker/debian.Dockerfile (renamed from lib/docker/debian)14
-rw-r--r--lib/main.bash39
7 files changed, 110 insertions, 94 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..7d375a9
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,8 @@
+.git
+dist
+bin
+!bin/rstar
+lib/libmoar.so
+include
+share
+tmp
diff --git a/lib/actions/build-docker.bash b/lib/actions/build-docker.bash
index f7f6241..86060df 100644
--- a/lib/actions/build-docker.bash
+++ b/lib/actions/build-docker.bash
@@ -1,76 +1,90 @@
-#!/usr/bin/bash
+#!/usr/bin/env bash
action() {
local OPTIND
- local base_image
- local base_tag
- local output_tag
+ local name
+ local version
+ local description
+ local tag
local dockerfile
- local template
- local install_options
+ local target
- while getopts ":B:b:f:T:t:" opt
+ while getopts ":T:b:d:ln:t:" opt
do
case "$opt" in
+ T) tag=$OPTARG ;;
b) RSTAR_BACKEND=$OPTARG ;;
- B) base_image=$OPTARG ;;
- T) base_tag=$OPTARG ;;
- t) output_tag=$OPTARG ;;
- f) template=$OPTARG ;;
+ d) description=$OPTARG ;;
+ l) tag_latest=1 ;;
+ n) name=$OPTARG ;;
+ t) version=$OPTARG ;;
*) emerg "Invalid option specified: $opt" ;;
esac
done
- # Base image must be specified
- if [[ -z $base_image ]]
+ shift $(( OPTIND - 1 ))
+
+ SOURCE_DATE_EPOCH="$(git log -1 --pretty=format:%at)"
+
+ if (( $# < 1 ))
+ then
+ alert "You must specify a base image to build for"
+ action_build_docker_list
+ return 2
+ fi
+
+ target=$1
+
+ if (( 1 < $# ))
then
- emerg "Must specify a base image with -B"
- exit 2
+ warn "Only $target will be built, additional arguments are being ignored!"
fi
- # Tag of base image defaults to 'latest'
- [[ -z $base_tag ]] && base_tag="latest"
+ # Set defaults for the Docker tag value
+ [[ -z $name ]] && name="$USER/rakudo-star"
- # Set a default tag for the built image with relevant information
- if [[ -z "$output_tag" ]]
+ # Build up a nice tag if none was explicitly defined
+ if [[ -z $tag ]]
then
- output_tag="rakudo:$base_image-$base_tag"
- if [[ ! -z $RSTAR_BACKEND ]]
- then
- output_tag="$output_tag-$RSTAR_BACKEND"
- fi
+ [[ -z $version ]] && version="$(datetime %Y.%m)"
+ [[ -z $description ]] && description="$target"
+
+ tag="$version-$description"
fi
- dockerfile=$(tempfile)
+ dockerfile="$BASEDIR/lib/docker/$target.Dockerfile"
+
+ debug "Using $dockerfile"
- # We use the Dockerfile template for this image + tag pair if it exists,
- # or use the image default template
- if [[ -z $template ]] && [[ -f "$BASEDIR/lib/docker/$base_image/$base_tag" ]]
+ if [[ ! -f $dockerfile ]]
then
- template="$BASEDIR/lib/docker/$base_image/$base_tag"
- else
- if [[ -f "$BASEDIR/lib/docker/$base_image" ]]
- then
- template="$BASEDIR/lib/docker/$base_image"
- else
- # Die if we have not found a template to use
- emerg "No Dockerfile template found for '$base_image:$base_tag'!"
- exit 2
- fi
+ alert "Target '$target' is not supported"
+ action_build_docker_list
+ return 2
fi
- # Fill in template placeholders
- if [[ ! -z $RSTAR_BACKEND ]]
+ # Build the image
+ docker build \
+ -t "$name:$tag" \
+ -f "$dockerfile" \
+ --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
+ --build-arg RSTAR_BACKEND="$RSTAR_BACKEND" \
+ "$BASEDIR"
+
+ # Also tag the image as "latest"
+ if [[ $tag_latest ]]
then
- install_options="$install_options -b "'"'"$RSTAR_BACKEND"'"'
+ docker tag "$name:$tag" "$name:latest-$target"
fi
+}
- sed < "$template" > "$dockerfile" \
- -e "s/{{INSTALL_OPTIONS}}/$install_options/" \
- -e "s/{{TAG}}/$base_tag/"
+action_build_docker_list() {
+ chgdir "$BASEDIR/lib/docker" > /dev/null
- # Build the image with the generated Dockerfile
- docker build -t "$output_tag" -f "$dockerfile" "$BASEDIR"
+ info "Available targets are:"
- shift $(( OPTIND -1 ))
+ for target in *.Dockerfile
+ do
+ info " ${target%.*}"
+ done
}
diff --git a/lib/docker/alpine b/lib/docker/alpine.Dockerfile
index e4770c8..2170c0e 100644
--- a/lib/docker/alpine
+++ b/lib/docker/alpine.Dockerfile
@@ -1,16 +1,12 @@
-FROM alpine:{{TAG}} AS base
-
-RUN apk add --no-cache \
- bash build-base git perl readline
+FROM alpine:latest AS base
COPY . /home/rstar
-RUN /home/rstar/bin/rstar install \
- -p /home/raku {{INSTALL_OPTIONS}}
-
+RUN apk add --no-cache bash build-base git perl readline
+RUN /home/rstar/bin/rstar install -p /home/raku
RUN apk del bash build-base git perl
-FROM alpine:{{TAG}}
+FROM alpine:latest
COPY --from=base /home/raku /usr/local
COPY --from=base /usr/lib /usr/lib
diff --git a/lib/docker/archlinux b/lib/docker/archlinux.Dockerfile
index 637ba3c..24663dd 100644
--- a/lib/docker/archlinux
+++ b/lib/docker/archlinux.Dockerfile
@@ -1,15 +1,13 @@
-FROM archlinux:{{TAG}} AS base
-
-RUN pacman -Sy && pacman --noconfirm -S gcc make
+FROM archlinux:latest AS base
COPY . /home/rstar
-RUN /home/rstar/bin/rstar install \
- -p /home/raku {{INSTALL_OPTIONS}}
-
+RUN pacman -Sy
+RUN pacman --noconfirm -S gcc make
+RUN /home/rstar/bin/rstar install -p /home/raku
RUN pacman --noconfirm -Rs gcc make
-FROM archlinux:{{TAG}}
+FROM archlinux:latest
COPY --from=base /home/raku /usr/local
COPY --from=base /usr/lib /usr/lib
diff --git a/lib/docker/centos b/lib/docker/centos.Dockerfile
index 7c6b8d4..bebe219 100644
--- a/lib/docker/centos
+++ b/lib/docker/centos.Dockerfile
@@ -1,15 +1,12 @@
-FROM centos:{{TAG}} AS base
-
-RUN yum -y install perl git gcc make
+FROM centos:latest AS base
COPY . /home/rstar
-RUN /home/rstar/bin/rstar install \
- -p /home/raku {{INSTALL_OPTIONS}}
-
+RUN yum -y install perl git gcc make
+RUN /home/rstar/bin/rstar install -p /home/raku
RUN yum -y remove perl git gcc make
-FROM centos:{{TAG}}
+FROM centos:latest
COPY --from=base /home/raku /usr/local
COPY --from=base /usr/lib64 /usr/lib64
diff --git a/lib/docker/debian b/lib/docker/debian.Dockerfile
index 2051a27..52652a4 100644
--- a/lib/docker/debian
+++ b/lib/docker/debian.Dockerfile
@@ -1,18 +1,14 @@
-FROM debian:{{TAG}} AS base
-
-RUN apt-get update
-RUN apt-get install -y \
- git build-essential libreadline7
+FROM debian:latest AS base
COPY . /home/rstar
-RUN /home/rstar/bin/rstar install \
- -p /home/raku {{INSTALL_OPTIONS}}
-
+RUN apt-get update
+RUN apt-get install -y git build-essential libreadline7
+RUN /home/rstar/bin/rstar install -p /home/raku
RUN apt-get -y remove git build-essential
RUN apt-get -y autoremove
-FROM debian:{{TAG}}
+FROM debian:latest
COPY --from=base /home/raku /usr/local
COPY --from=base /lib /lib
diff --git a/lib/main.bash b/lib/main.bash
index c535ba5..7b08ed6 100644
--- a/lib/main.bash
+++ b/lib/main.bash
@@ -27,10 +27,11 @@ main() {
# Declare some global variables
declare -a RSTAR_TOOLS
- declare RSTAR_BACKEND=moar
- declare RSTAR_PREFIX="$BASEDIR"
declare -A RSTAR_PLATFORM
+ [[ -z $RSTAR_BACKEND ]] && RSTAR_BACKEND="moar"
+ [[ -z $RSTAR_PREFIX ]] && RSTAR_PREFIX="$BASEDIR"
+
# Figure out system details
debug "Discovering system information"
discover_system
@@ -74,6 +75,7 @@ usage() {
cat <<EOF
Usage:
rstar -h
+ rstar build-docker [-T tag] [-b backend] [-d description] [-l] [-n name] [-t version] <base>
rstar clean [-s]
rstar dist [version]
rstar fetch
@@ -84,20 +86,25 @@ Usage:
rstar is the entry point for all utilities to deal with Rakudo Star.
Actions:
- clean Clean up the repository. If -s is given, the src directory
- will also be removed.
- dist Create a distributable tarball of this repository. If no
- version identifier is specified, it will use the current year
- and month in "yyyy.mm" notation.
- fetch Fetch all required sources.
- install Install Raku on this system. By default, MoarVM will be used
- as the only backend, and the Rakudo Star directory will be
- used as prefix. If neither core nor modules are given as
- explicit targets, all targets will be installed.
- sysinfo Show information about your system. Useful for debugging.
- test Run tests on Raku and the bundled ecosystem modules. If
- neither spectest nor modules are given as explicit targets,
- all targets will be tested.
+ build-docker Build a Docker image for Rakudo Star. You can specify the
+ tag of the resulting image using -T, which will cause -d,
+ -t, and -l to be ignored. -n specifies the name of the
+ image. If -l is passed, a "latest" tag will also be made.
+ You can specify a specific backend with -b.
+ clean Clean up the repository. If -s is given, the src
+ directory will also be removed.
+ dist Create a distributable tarball of this repository. If no
+ version identifier is specified, it will use the current
+ year and month in "yyyy.mm" notation.
+ fetch Fetch all required sources.
+ install Install Raku on this system. By default, MoarVM will be
+ used as the only backend, and the Rakudo Star directory
+ will be used as prefix. If neither core nor modules are
+ given as explicit targets, all targets will be installed.
+ sysinfo Show information about your system. Useful for debugging.
+ test Run tests on Raku and the bundled ecosystem modules. If
+ neither spectest nor modules are given as explicit
+ targets, all targets will be tested.
EOF
}