Skip to content

Commit 2b30b83

Browse files
authored
Merge pull request #452 from yhwang/ppc64le-support
Support Linux on ppc64le
2 parents 4f2354e + 8305e4c commit 2b30b83

9 files changed

+122
-35
lines changed

Dockerfile-slim.template

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ ENV NPM_CONFIG_LOGLEVEL info
2424
ENV NODE_VERSION 0.0.0
2525

2626
RUN buildDeps='xz-utils' \
27+
&& ARCH= && dpkgArch="$(dpkg --print-architecture)" \
28+
&& case "${dpkgArch##*-}" in \
29+
amd64) ARCH='x64';; \
30+
ppc64el) ARCH='ppc64le';; \
31+
*) echo "unsupported architecture"; exit 1 ;; \
32+
esac \
2733
&& set -x \
2834
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
2935
&& rm -rf /var/lib/apt/lists/* \
30-
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
36+
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
3137
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
3238
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
33-
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
34-
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
35-
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
39+
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
40+
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 \
41+
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
3642
&& apt-get purge -y --auto-remove $buildDeps \
3743
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
3844

Dockerfile-wheezy.template

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ RUN set -ex \
2323
ENV NPM_CONFIG_LOGLEVEL info
2424
ENV NODE_VERSION 0.0.0
2525

26-
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
26+
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
27+
&& case "${dpkgArch##*-}" in \
28+
amd64) ARCH='x64';; \
29+
ppc64el) ARCH='ppc64le';; \
30+
*) echo "unsupported architecture"; exit 1 ;; \
31+
esac \
32+
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
2733
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
2834
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
29-
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
30-
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
31-
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
35+
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
36+
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 \
37+
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
3238
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
3339

3440
ENV YARN_VERSION 0.0.0

Dockerfile.template

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ RUN set -ex \
2323
ENV NPM_CONFIG_LOGLEVEL info
2424
ENV NODE_VERSION 0.0.0
2525

26-
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
26+
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
27+
&& case "${dpkgArch##*-}" in \
28+
amd64) ARCH='x64';; \
29+
ppc64el) ARCH='ppc64le';; \
30+
*) echo "unsupported architecture"; exit 1 ;; \
31+
esac \
32+
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
2733
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
2834
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
29-
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
30-
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
31-
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
35+
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
36+
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 \
37+
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
3238
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
3339

3440
ENV YARN_VERSION 0.0.0

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ $ docker run node npm --loglevel=warn ...
137137

138138
The `node` images come in many flavors, each designed for a specific use case.
139139
All of the images contain pre-installed versions of `node`,
140-
[`npm`](https://www.npmjs.com/), and [`yarn`](https://yarnpkg.com).
140+
[`npm`](https://www.npmjs.com/), and [`yarn`](https://yarnpkg.com). For each
141+
supported architecutre, the supported variants are different. In the file:
142+
[architectures](./architectures), it lists all supported variants for all of
143+
the architecures that we support now.
141144

142145
## `node:<version>`
143146

architectures

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bashbrew-arch variants
2+
x64 alpine,onbuild,slim,wheezy
3+
ppc64le onbuild,slim

functions.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Utlity functions
4+
5+
# Get system architecture
6+
#
7+
# This is used to get the target architecture for docker image.
8+
# For crossing building, we need a way to specify the target
9+
# architecutre manually.
10+
function get_arch() {
11+
local arch
12+
case $(uname -m) in
13+
x86_64)
14+
arch="x64"
15+
;;
16+
ppc64le)
17+
arch="ppc64le"
18+
;;
19+
s390x)
20+
arch="s390x"
21+
;;
22+
*)
23+
echo "$0 does not support architecture $arch ... aborting"
24+
exit 1
25+
;;
26+
esac
27+
28+
echo "$arch"
29+
}
30+
31+
# Get corresponding variants based on the architecture.
32+
# All supported variants of each supported architecutre are listed in a
33+
# file - 'architectures'. Its format is:
34+
# <architecutre 1> <supported variant 1 >,<supported variant 2>...
35+
# <architecutre 2> <supported variant 1 >,<supported variant 2>...
36+
function get_variants() {
37+
local arch
38+
arch=$(get_arch)
39+
local variants
40+
variants=$(grep "$arch" architectures | sed -E 's/'"$arch"'\s*//' | sed -E 's/,/ /g')
41+
echo "$variants"
42+
}

generate-stackbrew-library.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
. functions.sh
34

45
hash git 2>/dev/null || { echo >&2 "git not found, exiting."; }
56

@@ -57,7 +58,9 @@ for version in "${versions[@]}"; do
5758
echo "Directory: ${version}"
5859
echo
5960

60-
variants=$(echo "$version"/*/ | xargs -n1 basename)
61+
# Get supported variants according to the target architecture.
62+
# See details in function.sh
63+
variants=$(get_variants | tr ' ' '\n')
6164
for variant in $variants; do
6265
# Skip non-docker directories
6366
[ -f "$version/$variant/Dockerfile" ] || continue

test-build.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
set -uo pipefail
66
IFS=$'\n\t'
77

8+
. functions.sh
9+
810
info() {
911
printf "%s\n" "$@"
1012
}
@@ -43,7 +45,9 @@ for version in "${versions[@]}"; do
4345
fi
4446
info "Test of $tag succeeded."
4547

46-
variants=$(echo "$version"/*/ | xargs -n1 basename)
48+
# Get supported variants according to the target architecture.
49+
# See details in function.sh
50+
variants=$(get_variants | tr ' ' '\n')
4751

4852
for variant in $variants; do
4953
# Skip non-docker directories

update.sh

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
33

4+
. functions.sh
5+
46
cd "$(cd "${0%/*}" && pwd -P)";
57

68
versions=( "$@" )
@@ -9,22 +11,39 @@ if [ ${#versions[@]} -eq 0 ]; then
911
fi
1012
versions=( "${versions[@]%/}" )
1113

12-
13-
template=
14-
dockerfile=
14+
# Global variables
15+
# Get architecure and use this as target architecture for docker image
16+
# See details in function.sh
17+
# TODO: Should be able to specify target architecture manually
18+
arch=$(get_arch)
1519

1620
yarnVersion="$(curl -sSL --compressed https://yarnpkg.com/latest-version)"
1721

1822
function update_node_version {
23+
24+
local template=$1
25+
shift
26+
local dockerfile=$1
27+
shift
28+
local variant=
29+
if [[ $# -eq 1 ]]; then
30+
variant=$1
31+
shift
32+
fi
33+
1934
fullVersion="$(curl -sSL --compressed 'https://nodejs.org/dist' | grep '<a href="v'"$version." | sed -E 's!.*<a href="v([^"/]+)/?".*!\1!' | cut -f 3 -d . | sort -n | tail -1)"
2035
(
21-
cp $template $dockerfile
22-
sed -E -i.bak 's/^(ENV NODE_VERSION |FROM node:).*/\1'"$version.$fullVersion"'/' "$dockerfile"
23-
rm "$dockerfile.bak"
24-
sed -E -i.bak 's/^(ENV YARN_VERSION ).*/\1'"$yarnVersion"'/' "$dockerfile"
25-
rm "$dockerfile.bak"
26-
if [[ "${version/.*/}" -ge 8 ]]; then
27-
sed -E -i.bak 's/FROM alpine:3.4/FROM alpine:3.6/' "$dockerfile"
36+
cp "$template" "$dockerfile"
37+
local fromprefix=
38+
if [[ "$arch" != "x64" && "$variant" != "onbuild" ]]; then
39+
fromprefix="$arch\/"
40+
fi
41+
42+
sed -E -i.bak 's/^FROM (.*)/FROM '"$fromprefix"'\1/' "$dockerfile" && rm "$dockerfile".bak
43+
sed -E -i.bak 's/^(ENV NODE_VERSION |FROM .*node:).*/\1'"$version.$fullVersion"'/' "$dockerfile" && rm "$dockerfile".bak
44+
sed -E -i.bak 's/^(ENV YARN_VERSION ).*/\1'"$yarnVersion"'/' "$dockerfile" && rm "$dockerfile".bak
45+
if [[ "${version/.*/}" -ge 8 || "$arch" = "ppc64le" ]]; then
46+
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
2847
rm "$dockerfile.bak"
2948
fi
3049
)
@@ -34,21 +53,16 @@ for version in "${versions[@]}"; do
3453
# Skip "docs" and other non-docker directories
3554
[ -f "$version/Dockerfile" ] || continue
3655

37-
template="Dockerfile.template"
38-
dockerfile="$version/Dockerfile"
39-
40-
update_node_version
56+
update_node_version "Dockerfile.template" "$version/Dockerfile"
4157

42-
variants=$(echo "$version"/*/ | xargs -n1 basename)
58+
# Get supported variants according the target architecture
59+
# See details in function.sh
60+
variants=$(get_variants)
4361

4462
for variant in $variants; do
4563
# Skip non-docker directories
4664
[ -f "$version/$variant/Dockerfile" ] || continue
47-
48-
template="Dockerfile-$variant.template"
49-
dockerfile="$version/$variant/Dockerfile"
50-
51-
update_node_version
65+
update_node_version "Dockerfile-$variant.template" "$version/$variant/Dockerfile" "$variant"
5266

5367
done
5468
done

0 commit comments

Comments
 (0)