Skip to content

Commit 0dff428

Browse files
committed
ARTEMIS-3042 Add docker multistage build
This adds the possibility to create an artemis image with just the docker build command. First the image is downloaded in an Eclipse Temurin installation and later transferred to an alpine image. Thus, it ensures that only the relevant data is stored in alpine leading to a smaller attack surface.
1 parent eb11b04 commit 0dff428

File tree

3 files changed

+93
-4
lines changed

3 files changed

+93
-4
lines changed

artemis-docker/Dockerfile-alpine

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# ActiveMQ Artemis
19+
20+
ARG CURRENT_VERSION=2.17.0
21+
22+
FROM eclipse-temurin:11-jdk as builder
23+
ARG CURRENT_VERSION
24+
25+
ENV VERSION=$CURRENT_VERSION
26+
27+
RUN apt update -y && apt upgrade -y && apt install tree curl -y
28+
29+
ADD ./prepare-docker.sh /bin/prepareDocker
30+
WORKDIR /root/artemis-build
31+
COPY ./Dockerfile-alpine .
32+
COPY ./docker-run.sh .
33+
RUN prepareDocker --from-release --artemis-version ${VERSION}
34+
35+
36+
FROM alpine:latest
37+
38+
ARG CURRENT_VERSION
39+
40+
ENV VERSION=$CURRENT_VERSION
41+
42+
RUN apk --no-cache add openjdk17-jre-headless bash libaio\
43+
--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
44+
45+
46+
LABEL maintainer="Apache ActiveMQ Team"
47+
# Make sure pipes are considered to determine success, see: https://github.com/hadolint/hadolint/wiki/DL4006
48+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
49+
WORKDIR /opt
50+
51+
ENV ARTEMIS_USER artemis
52+
ENV ARTEMIS_PASSWORD artemis
53+
ENV ANONYMOUS_LOGIN false
54+
ENV EXTRA_ARGS --http-host 0.0.0.0 --relax-jolokia
55+
56+
# add user and group for artemis
57+
RUN addgroup -g 1001 artemis && adduser -u 1002 --ingroup artemis --disabled-password artemis
58+
59+
USER artemis
60+
61+
COPY --from=builder /root/artemis-build/_TMP_/artemis/${VERSION}/ /opt/activemq-artemis
62+
63+
# Web Server
64+
EXPOSE 8161 \
65+
# JMX Exporter
66+
9404 \
67+
# Port for CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE
68+
61616 \
69+
# Port for HORNETQ,STOMP
70+
5445 \
71+
# Port for AMQP
72+
5672 \
73+
# Port for MQTT
74+
1883 \
75+
#Port for STOMP
76+
61613
77+
78+
USER root
79+
80+
RUN mkdir /var/lib/artemis-instance && chown -R artemis.artemis /var/lib/artemis-instance
81+
82+
COPY --from=builder /root/artemis-build/_TMP_/artemis/${VERSION}/docker/docker-run.sh /
83+
84+
USER artemis
85+
86+
# Expose some outstanding folders
87+
VOLUME ["/var/lib/artemis-instance"]
88+
WORKDIR /var/lib/artemis-instance
89+
90+
ENTRYPOINT ["/docker-run.sh"]
91+
CMD ["run"]

artemis-docker/docker-run.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,4 @@ else
4444
echo "broker already created, ignoring creation"
4545
fi
4646

47-
exec ./bin/artemis "$@"
48-
49-
47+
exec ./bin/artemis "$@"

artemis-docker/prepare-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ cp ./docker-run.sh "$ARTEMIS_DIST_DIR/docker"
187187
echo "Docker file support files at:"
188188
tree "$ARTEMIS_DIST_DIR/docker"
189189

190-
next_step
190+
next_step

0 commit comments

Comments
 (0)