Skip to content

Commit

Permalink
Add alpine variant
Browse files Browse the repository at this point in the history
Also, shrink the diff between "logstash" and "elasticsearch".
  • Loading branch information
tianon committed Dec 9, 2016
1 parent 2da4090 commit 737fb64
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 18 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ language: bash
services: docker

env:
- VERSION=5
- VERSION=2.4
- VERSION=1.7
- VERSION=5 VARIANT=
- VERSION=5 VARIANT=alpine
- VERSION=2.4 VARIANT=
- VERSION=1.7 VARIANT=

install:
- git clone https://github.com/docker-library/official-images.git ~/official-images
Expand Down
3 changes: 2 additions & 1 deletion 1.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN set -x \
&& echo 'deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list

ENV ELASTICSEARCH_VERSION 1.7.6
ENV ELASTICSEARCH_DEB_VERSION 1.7.6

RUN set -x \
\
Expand All @@ -30,7 +31,7 @@ RUN set -x \
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /usr/share/elasticsearch/bin:$PATH
Expand Down
3 changes: 2 additions & 1 deletion 2.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN set -x \
&& echo 'deb http://packages.elasticsearch.org/elasticsearch/2.x/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list

ENV ELASTICSEARCH_VERSION 2.4.2
ENV ELASTICSEARCH_DEB_VERSION 2.4.2

RUN set -x \
\
Expand All @@ -30,7 +31,7 @@ RUN set -x \
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /usr/share/elasticsearch/bin:$PATH
Expand Down
3 changes: 2 additions & 1 deletion 5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN set -x \
&& echo 'deb https://artifacts.elastic.co/packages/5.x/apt stable main' > /etc/apt/sources.list.d/elasticsearch.list

ENV ELASTICSEARCH_VERSION 5.1.1
ENV ELASTICSEARCH_DEB_VERSION 5.1.1

RUN set -x \
\
Expand All @@ -30,7 +31,7 @@ RUN set -x \
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /usr/share/elasticsearch/bin:$PATH
Expand Down
60 changes: 60 additions & 0 deletions 5/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM openjdk:8-jre-alpine

# ensure elasticsearch user exists
RUN addgroup -S elasticsearch && adduser -S -G elasticsearch elasticsearch

# grab su-exec for easy step-down from root
# and bash for "bin/elasticsearch" among others
RUN apk add --no-cache 'su-exec>=0.2' bash

# https://artifacts.elastic.co/GPG-KEY-elasticsearch
ENV GPG_KEY 46095ACC8548582C1A2699A9D27D666CD88E42B4

ENV ELASTICSEARCH_VERSION 5.1.1

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

RUN set -ex; \
\
apk add --no-cache --virtual .fetch-deps \
ca-certificates \
gnupg \
openssl \
tar \
; \
\
wget -O elasticsearch.tar.gz "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"; \
\
wget -O elasticsearch.tar.gz.asc "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY"; \
gpg --batch --verify elasticsearch.tar.gz.asc elasticsearch.tar.gz; \
rm -r "$GNUPGHOME" elasticsearch.tar.gz.asc; \
\
tar -xf elasticsearch.tar.gz --strip-components=1; \
rm elasticsearch.tar.gz; \
\
apk del .fetch-deps; \
\
for path in \
./data \
./logs \
./config \
./config/scripts \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done; \
\
elasticsearch --version

COPY config ./config

VOLUME /usr/share/elasticsearch/data

COPY docker-entrypoint.sh /

EXPOSE 9200 9300
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]
5 changes: 5 additions & 0 deletions 5/alpine/config/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
network.host: 0.0.0.0

# this value is required because we set "network.host"
# be sure to modify it appropriately for a production cluster deployment
discovery.zen.minimum_master_nodes: 1
9 changes: 9 additions & 0 deletions 5/alpine/config/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
status = error

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n

rootLogger.level = info
rootLogger.appenderRef.console.ref = console
23 changes: 23 additions & 0 deletions 5/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

# Add elasticsearch as command if needed
if [ "${1:0:1}" = '-' ]; then
set -- elasticsearch "$@"
fi

# Drop root privileges if we are running elasticsearch
# allow the container to be started with `--user`
if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then
# Change the ownership of /usr/share/elasticsearch/data to elasticsearch
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data

set -- su-exec elasticsearch "$@"
#exec su-exec elasticsearch "$BASH_SOURCE" "$@"
fi

# As argument is not related to elasticsearch,
# then assume that user wants to run his own process,
# for example a `bash` shell to explore this image
exec "$@"
60 changes: 60 additions & 0 deletions Dockerfile-alpine.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM openjdk:8-jre-alpine

# ensure elasticsearch user exists
RUN addgroup -S elasticsearch && adduser -S -G elasticsearch elasticsearch

# grab su-exec for easy step-down from root
# and bash for "bin/elasticsearch" among others
RUN apk add --no-cache 'su-exec>=0.2' bash

# https://artifacts.elastic.co/GPG-KEY-elasticsearch
ENV GPG_KEY 46095ACC8548582C1A2699A9D27D666CD88E42B4

ENV ELASTICSEARCH_VERSION %%ELASTICSEARCH_VERSION%%

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

RUN set -ex; \
\
apk add --no-cache --virtual .fetch-deps \
ca-certificates \
gnupg \
openssl \
tar \
; \
\
wget -O elasticsearch.tar.gz "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"; \
\
wget -O elasticsearch.tar.gz.asc "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY"; \
gpg --batch --verify elasticsearch.tar.gz.asc elasticsearch.tar.gz; \
rm -r "$GNUPGHOME" elasticsearch.tar.gz.asc; \
\
tar -xf elasticsearch.tar.gz --strip-components=1; \
rm elasticsearch.tar.gz; \
\
apk del .fetch-deps; \
\
for path in \
./data \
./logs \
./config \
./config/scripts \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done; \
\
elasticsearch --version

COPY config ./config

VOLUME /usr/share/elasticsearch/data

COPY docker-entrypoint.sh /

EXPOSE 9200 9300
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]
5 changes: 3 additions & 2 deletions Dockerfile.template → Dockerfile-debian.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC85485
# https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \
&& echo 'deb %%ELASTICSEARCH_REPO_BASE%% stable main' > /etc/apt/sources.list.d/elasticsearch.list
&& echo 'deb %%ELASTICSEARCH_DEB_REPO%% stable main' > /etc/apt/sources.list.d/elasticsearch.list

ENV ELASTICSEARCH_VERSION %%ELASTICSEARCH_VERSION%%
ENV ELASTICSEARCH_DEB_VERSION %%ELASTICSEARCH_DEB_VERSION%%

RUN set -x \
\
Expand All @@ -30,7 +31,7 @@ RUN set -x \
&& dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
&& apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \
&& rm -rf /var/lib/apt/lists/*

ENV PATH /usr/share/elasticsearch/bin:$PATH
Expand Down
16 changes: 16 additions & 0 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ for version in "${versions[@]}"; do
GitCommit: $commit
Directory: $version
EOE

for variant in alpine; do
[ -f "$version/$variant/Dockerfile" ] || continue

commit="$(dirCommit "$version/$variant")"

variantAliases=( "${versionAliases[@]/%/-$variant}" )
variantAliases=( "${variantAliases[@]//latest-/}" )

echo
cat <<-EOE
Tags: $(join ', ' "${variantAliases[@]}")
GitCommit: $commit
Directory: $version/$variant
EOE
done
done
48 changes: 38 additions & 10 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,66 @@ versions=( "${versions[@]%/}" )

travisEnv=
for version in "${versions[@]}"; do
travisEnv='\n - VERSION='"$version$travisEnv"

rcVersion="${version%-rc}"

majorVersion="${rcVersion%%.*}"
aptBucket="${majorVersion}.x"
if [ "$rcVersion" != "$version" ]; then
aptBucket+='-prerelease'
fi
repoBase=
debRepo=
if [ "$majorVersion" -ge 5 ]; then
repoBase="https://artifacts.elastic.co/packages/$aptBucket/apt"
debRepo="https://artifacts.elastic.co/packages/$aptBucket/apt"
elif [ "$majorVersion" -ge 2 ]; then
repoBase="http://packages.elasticsearch.org/elasticsearch/$aptBucket/debian"
debRepo="http://packages.elasticsearch.org/elasticsearch/$aptBucket/debian"
else
repoBase="http://packages.elasticsearch.org/elasticsearch/$rcVersion/debian"
debRepo="http://packages.elasticsearch.org/elasticsearch/$rcVersion/debian"
fi

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)"
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)"
if [ -z "$fullVersion" ]; then
echo >&2 "warning: cannot find full version for $version"
continue
fi
# convert "1:5.0.2-1" over to "5.0.2"
plainVersion="${fullVersion%%-*}" # strip non-upstream-version
plainVersion="${plainVersion##*:}" # strip epoch
tilde='~'; plainVersion="${plainVersion//$tilde/-}" # replace '~' with '-'

(
set -x
cp docker-entrypoint.sh "$version/"
sed '
s/%%ELASTICSEARCH_VERSION%%/'"$fullVersion"'/g;
s!%%ELASTICSEARCH_REPO_BASE%%!'"$repoBase"'!g;
' Dockerfile.template > "$version/Dockerfile"
s!%%ELASTICSEARCH_VERSION%%!'"$plainVersion"'!g;
s!%%ELASTICSEARCH_DEB_REPO%%!'"$debRepo"'!g;
s!%%ELASTICSEARCH_DEB_VERSION%%!'"$fullVersion"'!g;
' Dockerfile-debian.template > "$version/Dockerfile"
)

if [ -d "$version/alpine" ]; then
tarball="$tarballUrlBase/logstash/logstash-${plainVersion}.tar.gz"
tarballAsc="${tarball}.asc"
if ! wget --quiet --spider "$tarballAsc"; then
tarballAsc=
fi
tarballSha1=
for sha1Url in "${tarball}.sha1" "${tarball}.sha1.txt"; do
if sha1="$(wget -qO- "$sha1Url")"; then
tarballSha1="${sha1%% *}"
break
fi
done
(
set -x
cp docker-entrypoint.sh "$version/alpine/"
sed -i 's/gosu/su-exec/g' "$version/alpine/docker-entrypoint.sh"
sed \
-e 's!%%ELASTICSEARCH_VERSION%%!'"$plainVersion"'!g' \
Dockerfile-alpine.template > "$version/alpine/Dockerfile"
)
travisEnv='\n - VERSION='"$version VARIANT=alpine$travisEnv"
fi
travisEnv='\n - VERSION='"$version VARIANT=$travisEnv"
done

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

0 comments on commit 737fb64

Please sign in to comment.