Skip to content
Permalink
Browse files

Docker (#340)

* Add Dockerfile supporting multiple kernels for different Scala versions

* Build and push docker images via travis

- build snapshots only when pushing to master, not when pushing a tag
  • Loading branch information...
sbrunk authored and alexarchambault committed Mar 27, 2019
1 parent 2082c45 commit 5fc241af627b34ceaca5334e6537e8ec7d2a748b
Showing with 80 additions and 42 deletions.
  1. +2 −0 .travis.yml
  2. +25 −0 Dockerfile
  3. +21 −0 scripts/install-kernels.sh
  4. +32 −42 scripts/update-docker-images.sh
@@ -11,6 +11,8 @@ git:
before_install:
- source scripts/website/setup-build-tools.sh
sudo: required
services:
- docker
stages:
- name: test
- name: release
@@ -0,0 +1,25 @@
# Dockerfile with support for creating images with kernels for multiple Scala versions.
# Expects ALMOND_VERSION and SCALA_VERSIONS to be set as build arg, like this:
# docker build --build-arg ALMOND_VERSION=0.3.1 --build-arg SCALA_VERSIONS="2.11.12 2.12.8" .

# Set LOCAL_IVY=yes to have the contents of ivy-local copied into the image.
# Can be used to create an image with a locally built almond that isn't on maven central yet.
ARG LOCAL_IVY=no

FROM almondsh/almond:coursier as local_ivy_yes
USER $NB_UID
ONBUILD RUN mkdir -p .ivy2/local/
ONBUILD COPY --chown=1000:100 ivy-local/ .ivy2/local/

FROM almondsh/almond:coursier as local_ivy_no

FROM local_ivy_${LOCAL_IVY}
ARG ALMOND_VERSION
# Set to a single Scala version string or list of Scala versions separated by a space.
# i.e SCALA_VERSIONS="2.11.12 2.12.8"
ARG SCALA_VERSIONS
USER $NB_UID
COPY scripts/install-kernels.sh .
RUN ./install-kernels.sh && \
rm install-kernels.sh && \
rm -rf .ivy2
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -eu

[ -z "$SCALA_VERSIONS" ] && { echo "SCALA_VERSIONS is empty" ; exit 1; }
[ -z "$ALMOND_VERSION" ] && { echo "ALMOND_VERSION is empty" ; exit 1; }
for SCALA_FULL_VERSION in ${SCALA_VERSIONS}; do
# remove patch version
SCALA_MAJOR_VERSION=${SCALA_FULL_VERSION%.*}
# remove all dots for the kernel id
SCALA_MAJOR_VERSION_TRIMMED=$(echo ${SCALA_MAJOR_VERSION} | tr -d .)
echo Installing almond ${ALMOND_VERSION} for Scala ${SCALA_FULL_VERSION}
coursier bootstrap \
-r jitpack \
-i user -I user:sh.almond:scala-kernel-api_${SCALA_FULL_VERSION}:${ALMOND_VERSION} \
sh.almond:scala-kernel_${SCALA_FULL_VERSION}:${ALMOND_VERSION} \
--default=true --sources \
-o almond
./almond --install --log info --metabrowse --id scala${SCALA_MAJOR_VERSION_TRIMMED} --display-name "Scala ${SCALA_MAJOR_VERSION}"
rm -f almond
done
echo Installation was successful
@@ -1,49 +1,39 @@
#!/usr/bin/env bash
set -euv
set -e

SCALA212_VERSION="$(grep -oP '(?<=def scala212 = ")[^"]*(?<!")' project/Settings.scala)"
SCALA211_VERSION="$(grep -oP '(?<=def scala211 = ")[^"]*(?<!")' project/Settings.scala)"

VERSION="$(git describe --tags --abbrev=0 --match 'v*' | sed 's/^v//')"
ALMOND_VERSION="$(git describe --tags --abbrev=0 --match 'v*' | sed 's/^v//')"

DOCKER_REPO=almondsh/almond

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

if [[ ${TRAVIS_TAG} != v* ]]; then
echo "Not on a git tag, creating snapshot image"
ALMOND_VERSION=${ALMOND_VERSION%.*}.$((${ALMOND_VERSION##*.} + 1))-SNAPSHOT
IMAGE_NAME=${DOCKER_REPO}:snapshot
sbt '+ publishLocal'
cp -r $HOME/.ivy2/local/ ivy-local/
docker build --build-arg ALMOND_VERSION=${ALMOND_VERSION} --build-arg=LOCAL_IVY=yes \
--build-arg SCALA_VERSIONS="$SCALA211_VERSION $SCALA212_VERSION" -t ${IMAGE_NAME} .
docker push ${IMAGE_NAME}
else
echo "Creating release images for almond ${ALMOND_VERSION}"
IMAGE_NAME=${DOCKER_REPO}:${ALMOND_VERSION}
docker build --build-arg ALMOND_VERSION=${ALMOND_VERSION} \
--build-arg SCALA_VERSIONS="$SCALA211_VERSION $SCALA212_VERSION" -t ${IMAGE_NAME} .
docker build --build-arg ALMOND_VERSION=${ALMOND_VERSION} \
--build-arg SCALA_VERSIONS="$SCALA211_VERSION" -t ${IMAGE_NAME}-scala-${SCALA211_VERSION} .
docker build --build-arg ALMOND_VERSION=${ALMOND_VERSION} \
--build-arg SCALA_VERSIONS="$SCALA212_VERSION" -t ${IMAGE_NAME}-scala-${SCALA212_VERSION} .

docker push ${IMAGE_NAME}-scala-${SCALA211_VERSION}
docker push ${IMAGE_NAME}-scala-${SCALA212_VERSION}
docker push ${IMAGE_NAME}
docker tag ${IMAGE_NAME} ${DOCKER_REPO}:latest
docker push ${DOCKER_REPO}:latest
fi

mkdir -p target
cd target

git clone "https://$GH_TOKEN@github.com/almond-sh/docker-images.git" -b template
cd docker-images

BRANCHES=()

for sv in "$SCALA211_VERSION" "$SCALA212_VERSION"; do

BRANCH="almond-$VERSION-scala-$sv"
git checkout -b "$BRANCH" template
BRANCHES+=("$BRANCH")

mv Dockerfile Dockerfile.tmp
cat Dockerfile.tmp |
sed 's@{SCALA_VERSION}@'"$sv"'@g' |
sed 's@{VERSION}@'"$VERSION"'@g' > Dockerfile
rm -f Dockerfile.tmp

git add Dockerfile
git commit -m "almond $VERSION, scala $sv"
done

DEFAULT_BRANCH="almond-$VERSION-scala-$SCALA212_VERSION"

BRANCH="almond-$VERSION"
git checkout -b "$BRANCH" "$DEFAULT_BRANCH"
BRANCHES+=("$BRANCH")

BRANCH="latest"
git checkout -b "$BRANCH" "$DEFAULT_BRANCH"
BRANCHES+=("$BRANCH")

for b in "${BRANCHES[@]}"; do
if [ "$b" = "latest" ]; then
git push -f origin "$b"
else
git push origin "$b"
fi
done

0 comments on commit 5fc241a

Please sign in to comment.
You can’t perform that action at this time.