aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Joaquín Atria <jjatria@gmail.com>2020-04-02 18:34:05 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-04-08 13:12:12 +0200
commit2b8fac1454b3ca9077621420cedda3c228a87466 (patch)
tree81c7a6a110210544eb4a730bf5cd37f3aded7dbc
parentfb22c4933f7ef9f0fc5421b1463e23c3c0cc07b3 (diff)
Add build-docker action
-rw-r--r--lib/actions/build-docker.bash76
-rw-r--r--lib/docker/alpine25
-rw-r--r--lib/docker/archlinux24
-rw-r--r--lib/docker/centos24
-rw-r--r--lib/docker/debian27
5 files changed, 176 insertions, 0 deletions
diff --git a/lib/actions/build-docker.bash b/lib/actions/build-docker.bash
new file mode 100644
index 0000000..f7f6241
--- /dev/null
+++ b/lib/actions/build-docker.bash
@@ -0,0 +1,76 @@
+#!/usr/bin/bash
+
+action() {
+ local OPTIND
+ local base_image
+ local base_tag
+ local output_tag
+ local dockerfile
+ local template
+ local install_options
+
+ while getopts ":B:b:f:T:t:" opt
+ do
+ case "$opt" in
+ b) RSTAR_BACKEND=$OPTARG ;;
+ B) base_image=$OPTARG ;;
+ T) base_tag=$OPTARG ;;
+ t) output_tag=$OPTARG ;;
+ f) template=$OPTARG ;;
+ *) emerg "Invalid option specified: $opt" ;;
+ esac
+ done
+
+ # Base image must be specified
+ if [[ -z $base_image ]]
+ then
+ emerg "Must specify a base image with -B"
+ exit 2
+ fi
+
+ # Tag of base image defaults to 'latest'
+ [[ -z $base_tag ]] && base_tag="latest"
+
+ # Set a default tag for the built image with relevant information
+ if [[ -z "$output_tag" ]]
+ then
+ output_tag="rakudo:$base_image-$base_tag"
+ if [[ ! -z $RSTAR_BACKEND ]]
+ then
+ output_tag="$output_tag-$RSTAR_BACKEND"
+ fi
+ fi
+
+ dockerfile=$(tempfile)
+
+ # 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" ]]
+ 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
+ fi
+
+ # Fill in template placeholders
+ if [[ ! -z $RSTAR_BACKEND ]]
+ then
+ install_options="$install_options -b "'"'"$RSTAR_BACKEND"'"'
+ fi
+
+ sed < "$template" > "$dockerfile" \
+ -e "s/{{INSTALL_OPTIONS}}/$install_options/" \
+ -e "s/{{TAG}}/$base_tag/"
+
+ # Build the image with the generated Dockerfile
+ docker build -t "$output_tag" -f "$dockerfile" "$BASEDIR"
+
+ shift $(( OPTIND -1 ))
+}
diff --git a/lib/docker/alpine b/lib/docker/alpine
new file mode 100644
index 0000000..e4770c8
--- /dev/null
+++ b/lib/docker/alpine
@@ -0,0 +1,25 @@
+FROM alpine:{{TAG}} AS base
+
+RUN apk add --no-cache \
+ bash build-base git perl readline
+
+COPY . /home/rstar
+
+RUN /home/rstar/bin/rstar install \
+ -p /home/raku {{INSTALL_OPTIONS}}
+
+RUN apk del bash build-base git perl
+
+FROM alpine:{{TAG}}
+
+COPY --from=base /home/raku /usr/local
+COPY --from=base /usr/lib /usr/lib
+
+ENV PATH=/usr/local/share/perl6/site/bin:$PATH
+ENV PATH=/usr/local/share/perl6/vendor/bin:$PATH
+ENV PATH=/usr/local/share/perl6/core/bin:$PATH
+ENV PERL6LIB=/app/lib
+
+WORKDIR /app
+
+CMD [ "raku" ]
diff --git a/lib/docker/archlinux b/lib/docker/archlinux
new file mode 100644
index 0000000..637ba3c
--- /dev/null
+++ b/lib/docker/archlinux
@@ -0,0 +1,24 @@
+FROM archlinux:{{TAG}} AS base
+
+RUN pacman -Sy && pacman --noconfirm -S gcc make
+
+COPY . /home/rstar
+
+RUN /home/rstar/bin/rstar install \
+ -p /home/raku {{INSTALL_OPTIONS}}
+
+RUN pacman --noconfirm -Rs gcc make
+
+FROM archlinux:{{TAG}}
+
+COPY --from=base /home/raku /usr/local
+COPY --from=base /usr/lib /usr/lib
+
+ENV PATH=/usr/local/share/perl6/site/bin:$PATH
+ENV PATH=/usr/local/share/perl6/vendor/bin:$PATH
+ENV PATH=/usr/local/share/perl6/core/bin:$PATH
+ENV PERL6LIB=/app/lib
+
+WORKDIR /app
+
+CMD [ "raku" ]
diff --git a/lib/docker/centos b/lib/docker/centos
new file mode 100644
index 0000000..7c6b8d4
--- /dev/null
+++ b/lib/docker/centos
@@ -0,0 +1,24 @@
+FROM centos:{{TAG}} AS base
+
+RUN yum -y install perl git gcc make
+
+COPY . /home/rstar
+
+RUN /home/rstar/bin/rstar install \
+ -p /home/raku {{INSTALL_OPTIONS}}
+
+RUN yum -y remove perl git gcc make
+
+FROM centos:{{TAG}}
+
+COPY --from=base /home/raku /usr/local
+COPY --from=base /usr/lib64 /usr/lib64
+
+ENV PATH=/usr/local/share/perl6/site/bin:$PATH
+ENV PATH=/usr/local/share/perl6/vendor/bin:$PATH
+ENV PATH=/usr/local/share/perl6/core/bin:$PATH
+ENV PERL6LIB=/app/lib
+
+WORKDIR /app
+
+CMD ["raku"]
diff --git a/lib/docker/debian b/lib/docker/debian
new file mode 100644
index 0000000..2051a27
--- /dev/null
+++ b/lib/docker/debian
@@ -0,0 +1,27 @@
+FROM debian:{{TAG}} AS base
+
+RUN apt-get update
+RUN apt-get install -y \
+ git build-essential libreadline7
+
+COPY . /home/rstar
+
+RUN /home/rstar/bin/rstar install \
+ -p /home/raku {{INSTALL_OPTIONS}}
+
+RUN apt-get -y remove git build-essential
+RUN apt-get -y autoremove
+
+FROM debian:{{TAG}}
+
+COPY --from=base /home/raku /usr/local
+COPY --from=base /lib /lib
+
+ENV PATH=/usr/local/share/perl6/site/bin:$PATH
+ENV PATH=/usr/local/share/perl6/vendor/bin:$PATH
+ENV PATH=/usr/local/share/perl6/core/bin:$PATH
+ENV PERL6LIB=/app/lib
+
+WORKDIR /app
+
+CMD [ "raku" ]