From 337c33bdd163ea9a8b3d090540a7663270d74d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Fri, 17 Jul 2020 16:02:31 +0200 Subject: [PATCH] first edition --- .drone.yml | 37 +++++++++++++++++++++++++++ Dockerfile | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 62 +++++++++++++++++++++++++++++++++++++++++++-- docker-run.sh | 48 +++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 docker-run.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6a6bcd8 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,37 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: prepare-environment + image: ubuntu + environment: + ARTEMIS_VERSION: 2.13.0 + commands: + - apt update && apt install -y wget + - wget http://xenia.sote.hu/ftp/mirrors/www.apache.org/activemq/activemq-artemis/${ARTEMIS_VERSION}/apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz + - tar -xvf apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz + - mv apache-artemis-${ARTEMIS_VERSION}/* . + - rm -rf apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz + - rmdir apache-artemis-${ARTEMIS_VERSION} + + - name: kaniko + image: banzaicloud/drone-kaniko + settings: + registry: registry.kmlabz.com + repo: birbnetes/${DRONE_REPO_NAME} + username: + from_secret: DOCKER_USERNAME + password: + from_secret: DOCKER_PASSWORD + tags: + - latest + - ${DRONE_BUILD_NUMBER} + + - name: ms-teams + image: kuperiu/drone-teams + settings: + webhook: + from_secret: TEAMS_WEBHOOK + when: + status: [ failure ] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6bde29e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# ActiveMQ Artemis + +FROM jboss/base-jdk:8 +LABEL maintainer="Apache ActiveMQ Team" +# Make sure pipes are considered to determine success, see: https://github.com/hadolint/hadolint/wiki/DL4006 +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +WORKDIR /opt + +ENV ARTEMIS_USER artemis +ENV ARTEMIS_PASSWORD artemis +ENV ANONYMOUS_LOGIN false +ENV EXTRA_ARGS --http-host 0.0.0.0 --relax-jolokia + +USER root + +# add user and group for artemis +RUN groupadd -g 1001 -r artemis && useradd -r -u 1001 -g artemis artemis \ + && yum install -y libaio && yum -y clean all + +USER artemis + +ADD . /opt/activemq-artemis + +# Web Server +EXPOSE 8161 \ +# JMX Exporter + 9404 \ +# Port for CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE + 61616 \ +# Port for HORNETQ,STOMP + 5445 \ +# Port for AMQP + 5672 \ +# Port for MQTT + 1883 \ +#Port for STOMP + 61613 + +USER root + +RUN mkdir /var/lib/artemis-instance && chown -R artemis.artemis /var/lib/artemis-instance + +COPY ./docker/docker-run.sh / + +USER artemis + +# Expose some outstanding folders +VOLUME ["/var/lib/artemis-instance"] +WORKDIR /var/lib/artemis-instance + +ENTRYPOINT ["/docker-run.sh"] +CMD ["run"] diff --git a/README.md b/README.md index 2d8974d..b1beade 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,61 @@ -# activemq-artemis +# Apache ActiveMQ Artemis Container Image -ActiveMQ Artemis Container Image \ No newline at end of file +This is a container Image of Apache ActiveMQ Artemis that can be used inside Kubernetes. + +# Environment variables +Environment variables determine the options sent to `artemis create` on first execution of the Docker +container. The available options are: + +**`ARTEMIS_USER`** + +The administrator username. The default is `artemis`. + +**`ARTEMIS_PASSWORD`** + +The administrator password. The default is `artemis`. + +**`ANONYMOUS_LOGIN`** + +Set to `true` to allow anonymous logins. The default is `false`. + +**`EXTRA_ARGS`** + +Additional arguments sent to the `artemis create` command. The default is `--http-host 0.0.0.0 --relax-jolokia`. +Setting this value will override the default. See the documentation on `artemis create` for available options. + +**Final broker creation command:** + +The combination of the above environment variables results in the `docker-run.sh` script calling +the following command to create the broker instance the first time the Docker container runs: + + ${ARTEMIS_HOME}/bin/artemis create --user ${ARTEMIS_USER} --password ${ARTEMIS_PASSWORD} --silent ${LOGIN_OPTION} ${EXTRA_ARGS} + +Note: `LOGIN_OPTION` is either `--allow-anonymous` or `--require-login` depending on the value of `ANONYMOUS_LOGIN`. + +# Mapping point + +- `/var/lib/artemis-instance` + +It's possible to map a folder as the instance broker. +This will hold the configuration and the data of the running broker. This is useful for when you want the data persisted outside of a container. + + +# Lifecycle of the execution + +A broker instance will be created during the execution of the instance. If you pass a mapped folder for `/var/lib/artemis-instance` an image will be created or reused depending on the contents of the folder. + + + +## Running the image + +The image just created in the previous step allows both stateless or stateful runs. +The stateless run is achieved by: +``` +$ docker run --rm -it -p 61616:61616 -p 8161:8161 artemis-centos +``` +The image will also support mapped folders and mapped ports. To run the image with the instance persisted on the host: +``` +docker run -it -p 61616:61616 -p 8161:8161 -v :/var/lib/artemis-instance artemis-centos +``` +where `` is a folder where the broker instance is supposed to +be saved and reused on each run. diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 0000000..56431a7 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + + +# This is the entry point for the docker images. +# This file is executed when docker run is called. + + +set -e + +BROKER_HOME=/var/lib/ +CONFIG_PATH=$BROKER_HOME/etc +export BROKER_HOME OVERRIDE_PATH CONFIG_PATH + +if [[ ${ANONYMOUS_LOGIN,,} == "true" ]]; then + LOGIN_OPTION="--allow-anonymous" +else + LOGIN_OPTION="--require-login" +fi + +CREATE_ARGUMENTS="--user ${ARTEMIS_USER} --password ${ARTEMIS_PASSWORD} --silent ${LOGIN_OPTION} ${EXTRA_ARGS}" + +echo CREATE_ARGUMENTS=${CREATE_ARGUMENTS} + +if ! [ -f ./etc/broker.xml ]; then + /opt/activemq-artemis/bin/artemis create ${CREATE_ARGUMENTS} . +else + echo "broker already created, ignoring creation" +fi + +exec ./bin/artemis "$@" +