Skip to content

Commit 737fb64

Browse files
committed
Add alpine variant
Also, shrink the diff between "logstash" and "elasticsearch".
1 parent 2da4090 commit 737fb64

12 files changed

+224
-18
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ language: bash
22
services: docker
33

44
env:
5-
- VERSION=5
6-
- VERSION=2.4
7-
- VERSION=1.7
5+
- VERSION=5 VARIANT=
6+
- VERSION=5 VARIANT=alpine
7+
- VERSION=2.4 VARIANT=
8+
- VERSION=1.7 VARIANT=
89

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

1.7/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN set -x \
2222
&& echo 'deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list
2323

2424
ENV ELASTICSEARCH_VERSION 1.7.6
25+
ENV ELASTICSEARCH_DEB_VERSION 1.7.6
2526

2627
RUN set -x \
2728
\
@@ -30,7 +31,7 @@ RUN set -x \
3031
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
3132
\
3233
&& apt-get update \
33-
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
34+
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
3435
&& rm -rf /var/lib/apt/lists/*
3536

3637
ENV PATH /usr/share/elasticsearch/bin:$PATH

2.4/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN set -x \
2222
&& echo 'deb http://packages.elasticsearch.org/elasticsearch/2.x/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list
2323

2424
ENV ELASTICSEARCH_VERSION 2.4.2
25+
ENV ELASTICSEARCH_DEB_VERSION 2.4.2
2526

2627
RUN set -x \
2728
\
@@ -30,7 +31,7 @@ RUN set -x \
3031
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
3132
\
3233
&& apt-get update \
33-
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
34+
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
3435
&& rm -rf /var/lib/apt/lists/*
3536

3637
ENV PATH /usr/share/elasticsearch/bin:$PATH

5/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN set -x \
2222
&& echo 'deb https://artifacts.elastic.co/packages/5.x/apt stable main' > /etc/apt/sources.list.d/elasticsearch.list
2323

2424
ENV ELASTICSEARCH_VERSION 5.1.1
25+
ENV ELASTICSEARCH_DEB_VERSION 5.1.1
2526

2627
RUN set -x \
2728
\
@@ -30,7 +31,7 @@ RUN set -x \
3031
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
3132
\
3233
&& apt-get update \
33-
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
34+
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
3435
&& rm -rf /var/lib/apt/lists/*
3536

3637
ENV PATH /usr/share/elasticsearch/bin:$PATH

5/alpine/Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM openjdk:8-jre-alpine
2+
3+
# ensure elasticsearch user exists
4+
RUN addgroup -S elasticsearch && adduser -S -G elasticsearch elasticsearch
5+
6+
# grab su-exec for easy step-down from root
7+
# and bash for "bin/elasticsearch" among others
8+
RUN apk add --no-cache 'su-exec>=0.2' bash
9+
10+
# https://artifacts.elastic.co/GPG-KEY-elasticsearch
11+
ENV GPG_KEY 46095ACC8548582C1A2699A9D27D666CD88E42B4
12+
13+
ENV ELASTICSEARCH_VERSION 5.1.1
14+
15+
ENV PATH /usr/share/elasticsearch/bin:$PATH
16+
WORKDIR /usr/share/elasticsearch
17+
18+
RUN set -ex; \
19+
\
20+
apk add --no-cache --virtual .fetch-deps \
21+
ca-certificates \
22+
gnupg \
23+
openssl \
24+
tar \
25+
; \
26+
\
27+
wget -O elasticsearch.tar.gz "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"; \
28+
\
29+
wget -O elasticsearch.tar.gz.asc "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz.asc"; \
30+
export GNUPGHOME="$(mktemp -d)"; \
31+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY"; \
32+
gpg --batch --verify elasticsearch.tar.gz.asc elasticsearch.tar.gz; \
33+
rm -r "$GNUPGHOME" elasticsearch.tar.gz.asc; \
34+
\
35+
tar -xf elasticsearch.tar.gz --strip-components=1; \
36+
rm elasticsearch.tar.gz; \
37+
\
38+
apk del .fetch-deps; \
39+
\
40+
for path in \
41+
./data \
42+
./logs \
43+
./config \
44+
./config/scripts \
45+
; do \
46+
mkdir -p "$path"; \
47+
chown -R elasticsearch:elasticsearch "$path"; \
48+
done; \
49+
\
50+
elasticsearch --version
51+
52+
COPY config ./config
53+
54+
VOLUME /usr/share/elasticsearch/data
55+
56+
COPY docker-entrypoint.sh /
57+
58+
EXPOSE 9200 9300
59+
ENTRYPOINT ["/docker-entrypoint.sh"]
60+
CMD ["elasticsearch"]

5/alpine/config/elasticsearch.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
network.host: 0.0.0.0
2+
3+
# this value is required because we set "network.host"
4+
# be sure to modify it appropriately for a production cluster deployment
5+
discovery.zen.minimum_master_nodes: 1

5/alpine/config/log4j2.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
status = error
2+
3+
appender.console.type = Console
4+
appender.console.name = console
5+
appender.console.layout.type = PatternLayout
6+
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n
7+
8+
rootLogger.level = info
9+
rootLogger.appenderRef.console.ref = console

5/alpine/docker-entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Add elasticsearch as command if needed
6+
if [ "${1:0:1}" = '-' ]; then
7+
set -- elasticsearch "$@"
8+
fi
9+
10+
# Drop root privileges if we are running elasticsearch
11+
# allow the container to be started with `--user`
12+
if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then
13+
# Change the ownership of /usr/share/elasticsearch/data to elasticsearch
14+
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data
15+
16+
set -- su-exec elasticsearch "$@"
17+
#exec su-exec elasticsearch "$BASH_SOURCE" "$@"
18+
fi
19+
20+
# As argument is not related to elasticsearch,
21+
# then assume that user wants to run his own process,
22+
# for example a `bash` shell to explore this image
23+
exec "$@"

Dockerfile-alpine.template

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM openjdk:8-jre-alpine
2+
3+
# ensure elasticsearch user exists
4+
RUN addgroup -S elasticsearch && adduser -S -G elasticsearch elasticsearch
5+
6+
# grab su-exec for easy step-down from root
7+
# and bash for "bin/elasticsearch" among others
8+
RUN apk add --no-cache 'su-exec>=0.2' bash
9+
10+
# https://artifacts.elastic.co/GPG-KEY-elasticsearch
11+
ENV GPG_KEY 46095ACC8548582C1A2699A9D27D666CD88E42B4
12+
13+
ENV ELASTICSEARCH_VERSION %%ELASTICSEARCH_VERSION%%
14+
15+
ENV PATH /usr/share/elasticsearch/bin:$PATH
16+
WORKDIR /usr/share/elasticsearch
17+
18+
RUN set -ex; \
19+
\
20+
apk add --no-cache --virtual .fetch-deps \
21+
ca-certificates \
22+
gnupg \
23+
openssl \
24+
tar \
25+
; \
26+
\
27+
wget -O elasticsearch.tar.gz "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"; \
28+
\
29+
wget -O elasticsearch.tar.gz.asc "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz.asc"; \
30+
export GNUPGHOME="$(mktemp -d)"; \
31+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY"; \
32+
gpg --batch --verify elasticsearch.tar.gz.asc elasticsearch.tar.gz; \
33+
rm -r "$GNUPGHOME" elasticsearch.tar.gz.asc; \
34+
\
35+
tar -xf elasticsearch.tar.gz --strip-components=1; \
36+
rm elasticsearch.tar.gz; \
37+
\
38+
apk del .fetch-deps; \
39+
\
40+
for path in \
41+
./data \
42+
./logs \
43+
./config \
44+
./config/scripts \
45+
; do \
46+
mkdir -p "$path"; \
47+
chown -R elasticsearch:elasticsearch "$path"; \
48+
done; \
49+
\
50+
elasticsearch --version
51+
52+
COPY config ./config
53+
54+
VOLUME /usr/share/elasticsearch/data
55+
56+
COPY docker-entrypoint.sh /
57+
58+
EXPOSE 9200 9300
59+
ENTRYPOINT ["/docker-entrypoint.sh"]
60+
CMD ["elasticsearch"]

Dockerfile.template renamed to Dockerfile-debian.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC85485
1919
# https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html
2020
RUN set -x \
2121
&& apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \
22-
&& echo 'deb %%ELASTICSEARCH_REPO_BASE%% stable main' > /etc/apt/sources.list.d/elasticsearch.list
22+
&& echo 'deb %%ELASTICSEARCH_DEB_REPO%% stable main' > /etc/apt/sources.list.d/elasticsearch.list
2323

2424
ENV ELASTICSEARCH_VERSION %%ELASTICSEARCH_VERSION%%
25+
ENV ELASTICSEARCH_DEB_VERSION %%ELASTICSEARCH_DEB_VERSION%%
2526

2627
RUN set -x \
2728
\
@@ -30,7 +31,7 @@ RUN set -x \
3031
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
3132
\
3233
&& apt-get update \
33-
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
34+
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
3435
&& rm -rf /var/lib/apt/lists/*
3536

3637
ENV PATH /usr/share/elasticsearch/bin:$PATH

generate-stackbrew-library.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,20 @@ for version in "${versions[@]}"; do
7676
GitCommit: $commit
7777
Directory: $version
7878
EOE
79+
80+
for variant in alpine; do
81+
[ -f "$version/$variant/Dockerfile" ] || continue
82+
83+
commit="$(dirCommit "$version/$variant")"
84+
85+
variantAliases=( "${versionAliases[@]/%/-$variant}" )
86+
variantAliases=( "${variantAliases[@]//latest-/}" )
87+
88+
echo
89+
cat <<-EOE
90+
Tags: $(join ', ' "${variantAliases[@]}")
91+
GitCommit: $commit
92+
Directory: $version/$variant
93+
EOE
94+
done
7995
done

update.sh

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,66 @@ versions=( "${versions[@]%/}" )
1111

1212
travisEnv=
1313
for version in "${versions[@]}"; do
14-
travisEnv='\n - VERSION='"$version$travisEnv"
15-
1614
rcVersion="${version%-rc}"
1715

1816
majorVersion="${rcVersion%%.*}"
1917
aptBucket="${majorVersion}.x"
2018
if [ "$rcVersion" != "$version" ]; then
2119
aptBucket+='-prerelease'
2220
fi
23-
repoBase=
21+
debRepo=
2422
if [ "$majorVersion" -ge 5 ]; then
25-
repoBase="https://artifacts.elastic.co/packages/$aptBucket/apt"
23+
debRepo="https://artifacts.elastic.co/packages/$aptBucket/apt"
2624
elif [ "$majorVersion" -ge 2 ]; then
27-
repoBase="http://packages.elasticsearch.org/elasticsearch/$aptBucket/debian"
25+
debRepo="http://packages.elasticsearch.org/elasticsearch/$aptBucket/debian"
2826
else
29-
repoBase="http://packages.elasticsearch.org/elasticsearch/$rcVersion/debian"
27+
debRepo="http://packages.elasticsearch.org/elasticsearch/$rcVersion/debian"
3028
fi
3129

32-
fullVersion="$(curl -fsSL "$repoBase/dists/stable/main/binary-amd64/Packages" | awk -F ': ' '$1 == "Package" { pkg = $2 } pkg == "elasticsearch" && $1 == "Version" && $2 ~ /^([0-9]+:)?'"$rcVersion"'/ { print $2 }' | sort -rV | head -n1)"
30+
fullVersion="$(curl -fsSL "$debRepo/dists/stable/main/binary-amd64/Packages" | awk -F ': ' '$1 == "Package" { pkg = $2 } pkg == "elasticsearch" && $1 == "Version" && $2 ~ /^([0-9]+:)?'"$rcVersion"'/ { print $2 }' | sort -rV | head -n1)"
3331
if [ -z "$fullVersion" ]; then
3432
echo >&2 "warning: cannot find full version for $version"
3533
continue
3634
fi
35+
# convert "1:5.0.2-1" over to "5.0.2"
36+
plainVersion="${fullVersion%%-*}" # strip non-upstream-version
37+
plainVersion="${plainVersion##*:}" # strip epoch
38+
tilde='~'; plainVersion="${plainVersion//$tilde/-}" # replace '~' with '-'
3739

3840
(
3941
set -x
4042
cp docker-entrypoint.sh "$version/"
4143
sed '
42-
s/%%ELASTICSEARCH_VERSION%%/'"$fullVersion"'/g;
43-
s!%%ELASTICSEARCH_REPO_BASE%%!'"$repoBase"'!g;
44-
' Dockerfile.template > "$version/Dockerfile"
44+
s!%%ELASTICSEARCH_VERSION%%!'"$plainVersion"'!g;
45+
s!%%ELASTICSEARCH_DEB_REPO%%!'"$debRepo"'!g;
46+
s!%%ELASTICSEARCH_DEB_VERSION%%!'"$fullVersion"'!g;
47+
' Dockerfile-debian.template > "$version/Dockerfile"
4548
)
49+
50+
if [ -d "$version/alpine" ]; then
51+
tarball="$tarballUrlBase/logstash/logstash-${plainVersion}.tar.gz"
52+
tarballAsc="${tarball}.asc"
53+
if ! wget --quiet --spider "$tarballAsc"; then
54+
tarballAsc=
55+
fi
56+
tarballSha1=
57+
for sha1Url in "${tarball}.sha1" "${tarball}.sha1.txt"; do
58+
if sha1="$(wget -qO- "$sha1Url")"; then
59+
tarballSha1="${sha1%% *}"
60+
break
61+
fi
62+
done
63+
(
64+
set -x
65+
cp docker-entrypoint.sh "$version/alpine/"
66+
sed -i 's/gosu/su-exec/g' "$version/alpine/docker-entrypoint.sh"
67+
sed \
68+
-e 's!%%ELASTICSEARCH_VERSION%%!'"$plainVersion"'!g' \
69+
Dockerfile-alpine.template > "$version/alpine/Dockerfile"
70+
)
71+
travisEnv='\n - VERSION='"$version VARIANT=alpine$travisEnv"
72+
fi
73+
travisEnv='\n - VERSION='"$version VARIANT=$travisEnv"
4674
done
4775

4876
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"

0 commit comments

Comments
 (0)