Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker #340

Merged
merged 4 commits into from Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -11,6 +11,8 @@ git:
before_install:
- source scripts/website/setup-build-tools.sh
sudo: required
services:
- docker
stages:
- name: test
- name: release
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
@@ -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
21 changes: 21 additions & 0 deletions scripts/install-kernels.sh
@@ -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
74 changes: 32 additions & 42 deletions scripts/update-docker-images.sh
@@ -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
alexarchambault marked this conversation as resolved.
Show resolved Hide resolved

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