Skip to content

Commit 6071d79

Browse files
authored
Merge pull request #15 from infosiftr/multiarch
Add support for multiple architectures
2 parents ef0fdf9 + 4eff23f commit 6071d79

File tree

7 files changed

+200
-18
lines changed

7 files changed

+200
-18
lines changed

.architectures-lib

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
_awkArch() {
4+
local version="$1"; shift
5+
local awkExpr="$1"; shift
6+
awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures"
7+
}
8+
9+
dpkgArches() {
10+
local version="$1"; shift
11+
_awkArch "$version" '{ print $2 }'
12+
}
13+
14+
hasBashbrewArch() {
15+
local version="$1"; shift
16+
local bashbrewArch="$1"; shift
17+
_awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch"
18+
}
19+
20+
dpkgToJuliaTarArch() {
21+
local version="$1"; shift
22+
local dpkgArch="$1"; shift
23+
_awkArch "$version" '$2 == dpkgArch { print $3; exit }' -v dpkgArch="$dpkgArch"
24+
}
25+
26+
dpkgToJuliaDirArch() {
27+
local version="$1"; shift
28+
local dpkgArch="$1"; shift
29+
_awkArch "$version" '$2 == dpkgArch { print $4; exit }' -v dpkgArch="$dpkgArch"
30+
}

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
language: bash
22
services: docker
33

4+
env:
5+
- ARCH=
6+
- ARCH=i386
7+
48
install:
59
- git clone https://github.com/docker-library/official-images.git ~/official-images
610

711
before_script:
812
- env | sort
913
- image='julia'
14+
- |
15+
if [ -n "$ARCH" ]; then
16+
from="$(awk '$1 == toupper("FROM") { print $2 }' Dockerfile)"
17+
docker pull "$ARCH/$from"
18+
docker tag "$ARCH/$from" "$from"
19+
fi
1020
1121
script:
1222
- travis_retry docker build -t "$image" .

Dockerfile

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
FROM debian:jessie
22

33
RUN apt-get update \
4-
&& apt-get install -y --no-install-recommends ca-certificates \
4+
&& apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
curl \
57
&& rm -rf /var/lib/apt/lists/*
68

79
ENV JULIA_PATH /usr/local/julia
8-
ENV JULIA_VERSION 0.6.0
910

10-
RUN mkdir $JULIA_PATH \
11-
&& apt-get update && apt-get install -y curl \
12-
&& curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-x86_64.tar.gz" -o julia.tar.gz \
13-
&& 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 \
14-
&& export GNUPGHOME="$(mktemp -d)" \
15-
# http://julialang.org/juliareleases.asc
11+
# https://julialang.org/juliareleases.asc
1612
# Julia (Binary signing key) <[email protected]>
17-
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 3673DF529D9049477F76B37566E3C7DC03D6E495 \
18-
&& gpg --batch --verify julia.tar.gz.asc julia.tar.gz \
19-
&& rm -r "$GNUPGHOME" julia.tar.gz.asc \
20-
&& tar -xzf julia.tar.gz -C $JULIA_PATH --strip-components 1 \
21-
&& rm -rf /var/lib/apt/lists/* julia.tar.gz*
13+
ENV JULIA_GPG 3673DF529D9049477F76B37566E3C7DC03D6E495
14+
15+
# https://julialang.org/downloads/
16+
ENV JULIA_VERSION 0.6.0
17+
18+
RUN set -ex; \
19+
\
20+
# https://julialang.org/downloads/#julia-command-line-version
21+
# https://julialang-s3.julialang.org/bin/checksums/julia-0.6.0.sha256
22+
# this "case" statement is generated via "update.sh"
23+
dpkgArch="$(dpkg --print-architecture)"; \
24+
case "${dpkgArch##*-}" in \
25+
amd64) tarArch='x86_64'; dirArch='x64'; sha256='3a27ea78b06f46701dc4274820d9853789db205bce56afdc7147f7bd6fa83e41' ;; \
26+
armhf) tarArch='arm'; dirArch='arm'; sha256='7515f5977b2aac0cea1333ef249b3983928dee76ea8eb3de9dd6a7cdfbd07d2d' ;; \
27+
i386) tarArch='i686'; dirArch='x86'; sha256='bfebd2ef38c25ce72dd6661cdd8a6f509800492a4d250c2908f83e791c0a444a' ;; \
28+
*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding Julia binary release"; exit 1 ;; \
29+
esac; \
30+
\
31+
curl -fL -o julia.tar.gz "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz"; \
32+
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"; \
33+
\
34+
echo "${sha256} *julia.tar.gz" | sha256sum -c -; \
35+
\
36+
export GNUPGHOME="$(mktemp -d)"; \
37+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$JULIA_GPG"; \
38+
gpg --batch --verify julia.tar.gz.asc julia.tar.gz; \
39+
rm -rf "$GNUPGHOME" julia.tar.gz.asc; \
40+
\
41+
mkdir "$JULIA_PATH"; \
42+
tar -xzf julia.tar.gz -C "$JULIA_PATH" --strip-components 1; \
43+
rm julia.tar.gz
2244

2345

2446
ENV PATH $JULIA_PATH/bin:$PATH

Dockerfile.template

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM debian:jessie
2+
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
curl \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
ENV JULIA_PATH /usr/local/julia
10+
11+
# https://julialang.org/juliareleases.asc
12+
# Julia (Binary signing key) <[email protected]>
13+
ENV JULIA_GPG 3673DF529D9049477F76B37566E3C7DC03D6E495
14+
15+
# https://julialang.org/downloads/
16+
ENV JULIA_VERSION %%JULIA_VERSION%%
17+
18+
RUN set -ex; \
19+
\
20+
# https://julialang.org/downloads/#julia-command-line-version
21+
# https://julialang-s3.julialang.org/bin/checksums/julia-%%JULIA_VERSION%%.sha256
22+
# this "case" statement is generated via "update.sh"
23+
%%ARCH-CASE%%; \
24+
\
25+
curl -fL -o julia.tar.gz "https://julialang-s3.julialang.org/bin/linux/${dirArch}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${tarArch}.tar.gz"; \
26+
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"; \
27+
\
28+
echo "${sha256} *julia.tar.gz" | sha256sum -c -; \
29+
\
30+
export GNUPGHOME="$(mktemp -d)"; \
31+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$JULIA_GPG"; \
32+
gpg --batch --verify julia.tar.gz.asc julia.tar.gz; \
33+
rm -rf "$GNUPGHOME" julia.tar.gz.asc; \
34+
\
35+
mkdir "$JULIA_PATH"; \
36+
tar -xzf julia.tar.gz -C "$JULIA_PATH" --strip-components 1; \
37+
rm julia.tar.gz
38+
39+
40+
ENV PATH $JULIA_PATH/bin:$PATH
41+
42+
CMD ["julia"]

generate-stackbrew-library.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,39 @@ dirCommit() {
2626
)
2727
}
2828

29+
getArches() {
30+
local repo="$1"; shift
31+
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
32+
33+
eval "declare -g -A parentRepoToArches=( $(
34+
find -name 'Dockerfile' -exec awk '
35+
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
36+
print "'"$officialImagesUrl"'" $2
37+
}
38+
' '{}' + \
39+
| sort -u \
40+
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
41+
) )"
42+
}
43+
getArches 'julia'
44+
45+
source '.architectures-lib'
46+
47+
parentArches() {
48+
local version="$1"; shift # "1.8", etc
49+
50+
local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/Dockerfile")"
51+
local parentArches="${parentRepoToArches[$parent]:-}"
52+
53+
local arches=()
54+
for arch in $parentArches; do
55+
if hasBashbrewArch "$version" "$arch"; then
56+
arches+=( "$arch" )
57+
fi
58+
done
59+
echo "${arches[*]}"
60+
}
61+
2962
cat <<-EOH
3063
# this file is generated via https://github.com/docker-library/julia/blob/$(fileCommit "$self")/$self
3164
@@ -55,5 +88,6 @@ versionAliases+=( $fullVersion latest )
5588
echo
5689
cat <<-EOE
5790
Tags: $(join ', ' "${versionAliases[@]}")
91+
Architectures: $(join ', ' $(parentArches .))
5892
GitCommit: $commit
5993
EOE

release-architectures

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# see https://julialang.org/downloads/#julia-command-line-version
2+
3+
# bashbrew-arch dpkg-arch julia-tar-arch julia-dir-arch
4+
amd64 amd64 x86_64 x64
5+
arm32v7 armhf arm arm
6+
i386 i386 i686 x86
7+
8+
# ppc64le appears to be "0.6.0-rc3"-only as of 2017-08-24
9+
#ppc64le ppc64el ppc64le ppc64le

update.sh

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1-
#!/bin/bash
2-
set -e
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
33

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

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

8+
# see http://stackoverflow.com/a/2705678/433558
9+
sed_escape_rhs() {
10+
echo "$@" | sed -e 's/[\/&]/\\&/g' | sed -e ':a;N;$!ba;s/\n/\\n/g'
11+
}
12+
13+
for version in '.'; do
14+
pattern='.*/julia-([0-9]+\.[0-9]+\.[0-9]+)-linux-x86_64\.tar\.gz.*'
15+
fullVersion="$(curl -fsSL 'https://julialang.org/downloads/' | sed -rn "s!${pattern}!\1!gp")"
16+
if [ -z "$fullVersion" ]; then
17+
echo >&2 "error: failed to determine latest release for '$version'"
18+
exit 1
19+
fi
20+
21+
sha256s="$(curl -fsSL "https://julialang-s3.julialang.org/bin/checksums/julia-${fullVersion}.sha256")"
22+
23+
linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n'
24+
linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n'
25+
for dpkgArch in $(dpkgArches "$version"); do
26+
tarArch="$(dpkgToJuliaTarArch "$version" "$dpkgArch")"
27+
dirArch="$(dpkgToJuliaDirArch "$version" "$dpkgArch")"
28+
sha256="$(echo "$sha256s" | grep "*julia-${fullVersion}-linux-${tarArch}.tar.gz$" | cut -d' ' -f1)"
29+
if [ -z "$sha256" ]; then
30+
echo >&2 "error: cannot find sha256 for $fullVersion on arch $tarArch / $dirArch ($dpkgArch)"
31+
exit 1
32+
fi
33+
linuxArchCase+=$'\t\t'"$dpkgArch) tarArch='$tarArch'; dirArch='$dirArch'; sha256='$sha256' ;; "$'\\\n'
34+
done
35+
linuxArchCase+=$'\t\t''*) echo >&2 "error: current architecture ($dpkgArch) does not have a corresponding Julia binary release"; exit 1 ;; '$'\\\n'
36+
linuxArchCase+=$'\t''esac'
37+
38+
echo "$version: $fullVersion"
39+
40+
sed -r \
41+
-e 's!%%JULIA_VERSION%%!'"$fullVersion"'!g' \
42+
-e 's!%%ARCH-CASE%%!'"$(sed_escape_rhs "$linuxArchCase")"'!g' \
43+
Dockerfile.template > "$version/Dockerfile"
44+
done

0 commit comments

Comments
 (0)