Skip to content

Add support for multiple architectures #15

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

Merged
merged 1 commit into from
Aug 24, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .architectures-lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

_awkArch() {
local version="$1"; shift
local awkExpr="$1"; shift
awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures"
}

dpkgArches() {
local version="$1"; shift
_awkArch "$version" '{ print $2 }'
}

hasBashbrewArch() {
local version="$1"; shift
local bashbrewArch="$1"; shift
_awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch"
}

dpkgToJuliaTarArch() {
local version="$1"; shift
local dpkgArch="$1"; shift
_awkArch "$version" '$2 == dpkgArch { print $3; exit }' -v dpkgArch="$dpkgArch"
}

dpkgToJuliaDirArch() {
local version="$1"; shift
local dpkgArch="$1"; shift
_awkArch "$version" '$2 == dpkgArch { print $4; exit }' -v dpkgArch="$dpkgArch"
}
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
language: bash
services: docker

env:
- ARCH=
- ARCH=i386

install:
- git clone https://github.com/docker-library/official-images.git ~/official-images

before_script:
- env | sort
- image='julia'
- |
if [ -n "$ARCH" ]; then
from="$(awk '$1 == toupper("FROM") { print $2 }' Dockerfile)"
docker pull "$ARCH/$from"
docker tag "$ARCH/$from" "$from"
fi

script:
- travis_retry docker build -t "$image" .
Expand Down
48 changes: 35 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
FROM debian:jessie

RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*

ENV JULIA_PATH /usr/local/julia
ENV JULIA_VERSION 0.6.0

RUN mkdir $JULIA_PATH \
&& apt-get update && apt-get install -y curl \
&& curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-x86_64.tar.gz" -o julia.tar.gz \
&& curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-x86_64.tar.gz.asc" -o julia.tar.gz.asc \
&& export GNUPGHOME="$(mktemp -d)" \
# http://julialang.org/juliareleases.asc
# https://julialang.org/juliareleases.asc
# Julia (Binary signing key) <[email protected]>
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 3673DF529D9049477F76B37566E3C7DC03D6E495 \
&& gpg --batch --verify julia.tar.gz.asc julia.tar.gz \
&& rm -r "$GNUPGHOME" julia.tar.gz.asc \
&& tar -xzf julia.tar.gz -C $JULIA_PATH --strip-components 1 \
&& rm -rf /var/lib/apt/lists/* julia.tar.gz*
ENV JULIA_GPG 3673DF529D9049477F76B37566E3C7DC03D6E495

# https://julialang.org/downloads/
ENV JULIA_VERSION 0.6.0

RUN set -ex; \
\
# https://julialang.org/downloads/#julia-command-line-version
# https://julialang-s3.julialang.org/bin/checksums/julia-0.6.0.sha256
# this "case" statement is generated via "update.sh"
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) tarArch='x86_64'; dirArch='x64'; sha256='3a27ea78b06f46701dc4274820d9853789db205bce56afdc7147f7bd6fa83e41' ;; \
armhf) tarArch='arm'; dirArch='arm'; sha256='7515f5977b2aac0cea1333ef249b3983928dee76ea8eb3de9dd6a7cdfbd07d2d' ;; \
i386) tarArch='i686'; dirArch='x86'; sha256='bfebd2ef38c25ce72dd6661cdd8a6f509800492a4d250c2908f83e791c0a444a' ;; \
*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding Julia binary release"; exit 1 ;; \
esac; \
\
curl -fL -o julia.tar.gz "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz"; \
curl -fL -o julia.tar.gz.asc "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz.asc"; \
\
echo "${sha256} *julia.tar.gz" | sha256sum -c -; \
\
export GNUPGHOME="$(mktemp -d)"; \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$JULIA_GPG"; \
gpg --batch --verify julia.tar.gz.asc julia.tar.gz; \
rm -rf "$GNUPGHOME" julia.tar.gz.asc; \
\
mkdir "$JULIA_PATH"; \
tar -xzf julia.tar.gz -C "$JULIA_PATH" --strip-components 1; \
rm julia.tar.gz


ENV PATH $JULIA_PATH/bin:$PATH
Expand Down
42 changes: 42 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM debian:jessie

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*

ENV JULIA_PATH /usr/local/julia

# https://julialang.org/juliareleases.asc
# Julia (Binary signing key) <[email protected]>
ENV JULIA_GPG 3673DF529D9049477F76B37566E3C7DC03D6E495

# https://julialang.org/downloads/
ENV JULIA_VERSION %%JULIA_VERSION%%

RUN set -ex; \
\
# https://julialang.org/downloads/#julia-command-line-version
# https://julialang-s3.julialang.org/bin/checksums/julia-%%JULIA_VERSION%%.sha256
# this "case" statement is generated via "update.sh"
%%ARCH-CASE%%; \
\
curl -fL -o julia.tar.gz "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz"; \
curl -fL -o julia.tar.gz.asc "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz.asc"; \
\
echo "${sha256} *julia.tar.gz" | sha256sum -c -; \
\
export GNUPGHOME="$(mktemp -d)"; \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$JULIA_GPG"; \
gpg --batch --verify julia.tar.gz.asc julia.tar.gz; \
rm -rf "$GNUPGHOME" julia.tar.gz.asc; \
\
mkdir "$JULIA_PATH"; \
tar -xzf julia.tar.gz -C "$JULIA_PATH" --strip-components 1; \
rm julia.tar.gz


ENV PATH $JULIA_PATH/bin:$PATH

CMD ["julia"]
34 changes: 34 additions & 0 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ dirCommit() {
)
}

getArches() {
local repo="$1"; shift
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'

eval "declare -g -A parentRepoToArches=( $(
find -name 'Dockerfile' -exec awk '
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
print "'"$officialImagesUrl"'" $2
}
' '{}' + \
| sort -u \
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
) )"
}
getArches 'julia'

source '.architectures-lib'

parentArches() {
local version="$1"; shift # "1.8", etc

local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/Dockerfile")"
local parentArches="${parentRepoToArches[$parent]:-}"

local arches=()
for arch in $parentArches; do
if hasBashbrewArch "$version" "$arch"; then
arches+=( "$arch" )
fi
done
echo "${arches[*]}"
}

cat <<-EOH
# this file is generated via https://github.com/docker-library/julia/blob/$(fileCommit "$self")/$self

Expand Down Expand Up @@ -55,5 +88,6 @@ versionAliases+=( $fullVersion latest )
echo
cat <<-EOE
Tags: $(join ', ' "${versionAliases[@]}")
Architectures: $(join ', ' $(parentArches .))
GitCommit: $commit
EOE
9 changes: 9 additions & 0 deletions release-architectures
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# see https://julialang.org/downloads/#julia-command-line-version

# bashbrew-arch dpkg-arch julia-tar-arch julia-dir-arch
amd64 amd64 x86_64 x64
arm32v7 armhf arm arm
i386 i386 i686 x86

# ppc64le appears to be "0.6.0-rc3"-only as of 2017-08-24
#ppc64le ppc64el ppc64le ppc64le
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like aarch64 is also in-progress! 😄 👍

45 changes: 40 additions & 5 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
#!/bin/bash
set -e
#!/usr/bin/env bash
set -Eeuo pipefail

cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
pattern='.*\/julia-([0-9]+\.[0-9]+\.[0-9]+)-linux-x86_64\.tar\.gz.*'
version=$(curl -sSL 'http://julialang.org/downloads/' | sed -rn "s/${pattern}/\1/gp")

sed -ri 's/^(ENV JULIA_VERSION) .*/\1 '"$version"'/' "Dockerfile"
source '.architectures-lib'

# see http://stackoverflow.com/a/2705678/433558
sed_escape_rhs() {
echo "$@" | sed -e 's/[\/&]/\\&/g' | sed -e ':a;N;$!ba;s/\n/\\n/g'
}

for version in '.'; do
pattern='.*/julia-([0-9]+\.[0-9]+\.[0-9]+)-linux-x86_64\.tar\.gz.*'
fullVersion="$(curl -fsSL 'https://julialang.org/downloads/' | sed -rn "s!${pattern}!\1!gp")"
if [ -z "$fullVersion" ]; then
echo >&2 "error: failed to determine latest release for '$version'"
exit 1
fi

sha256s="$(curl -fsSL "https://julialang-s3.julialang.org/bin/checksums/julia-${fullVersion}.sha256")"

linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n'
linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n'
for dpkgArch in $(dpkgArches "$version"); do
tarArch="$(dpkgToJuliaTarArch "$version" "$dpkgArch")"
dirArch="$(dpkgToJuliaDirArch "$version" "$dpkgArch")"
sha256="$(echo "$sha256s" | grep "*julia-${fullVersion}-linux-${tarArch}.tar.gz$" | cut -d' ' -f1)"
if [ -z "$sha256" ]; then
echo >&2 "error: cannot find sha256 for $fullVersion on arch $tarArch / $dirArch ($dpkgArch)"
exit 1
fi
linuxArchCase+=$'\t\t'"$dpkgArch) tarArch='$tarArch'; dirArch='$dirArch'; sha256='$sha256' ;; "$'\\\n'
done
linuxArchCase+=$'\t\t''*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding Julia binary release"; exit 1 ;; '$'\\\n'
linuxArchCase+=$'\t''esac'

echo "$version: $fullVersion"

sed -r \
-e 's!%%JULIA_VERSION%%!'"$fullVersion"'!g' \
-e 's!%%ARCH-CASE%%!'"$(sed_escape_rhs "$linuxArchCase")"'!g' \
Dockerfile.template > "$version/Dockerfile"
done