Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTL_OVER_HTTP and containers frictionless #4340

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
265413a
ejabberd_listener: Handle unix socket when logging remote client
badlop Jan 6, 2025
553ebbb
ejabberd_listener: Add support for socket relative path
badlop Jan 3, 2025
512ba7c
ejabberd_listener: Use /tmp for temporary socket, as path is restrict…
badlop Jan 7, 2025
0d93e2e
ejabberd_listener: Apparently the sleep 5 seconds isn't needed anymore
badlop Jan 8, 2025
033ae5f
New ejabberdctl option CTL_OVER_HTTP
badlop Jan 6, 2025
a64b336
ejabberd_admin: Separate Status command result with newline
badlop Jan 6, 2025
a42cd92
ejabberd_listener: When opening ctl_over_http connection, log in DEBUG
badlop Jan 8, 2025
4c6ad54
Container: Copy files to stable path, add ecs backwards compatibility
badlop Dec 26, 2024
66c3d51
Container: Copy main example configuration file, will be customized
badlop Dec 27, 2024
dffff5a
Container: Apply customizations directly in the configuration file
badlop Dec 27, 2024
b87f455
Container: Define and use macros in the configuration file
badlop Dec 27, 2024
c42ff2e
Container: Listen for webadmin in a port number lower than any other
badlop Dec 27, 2024
49ce02d
Container: Compile ejabberdapi during build
badlop Dec 30, 2024
32eeea5
Container: Improve entrypoint script: register account, or set random
badlop Dec 27, 2024
d101533
Container: Link path to mnesia spool dir for backwards compatibility
badlop Jan 2, 2025
2da7bb2
Container: Remove runDeps file once it's used
badlop Jan 10, 2025
3f64f53
Container: Copy support for CTL_OVER_HTTP
badlop Jan 7, 2025
9d809a1
Container: Enable CTL_OVER_HTTP by default
badlop Jan 8, 2025
74103fb
Container: Use again direct METHOD, qemu got fixed (3983)(4280)
badlop Jan 8, 2025
7a5bb54
Container: Add ERL_FLAGS to compile elixir on qemu cross-platform
badlop Jan 10, 2025
d64a703
CONTAINER.md: Update with all the recent improvements
badlop Dec 30, 2024
3c28bf8
CONTAINER.md: Include documentation for ecs container image
badlop Jan 3, 2025
6de3f3a
ejabberdctl: If socket doesn't exist, use erlang connection
badlop Jan 16, 2025
64a91bf
ejabberdctl: If curl not executable, use erlang connection
badlop Jan 16, 2025
95dbf7c
ejabberdctl: Improve method to pass command arguments
badlop Jan 16, 2025
2569305
ejabberdctl: Document the --auth option
badlop Jan 16, 2025
8355853
Container: Place sockets/ outside database/
badlop Jan 16, 2025
c9ea7d5
Container: Fix CTL_OVER_HTTP configuration: it uses the existing api_…
badlop Jan 16, 2025
ed82bd4
Container: Copy improvements in ejabberdctl.template
badlop Jan 16, 2025
ca35172
CONTAINER.md: Add more marks about version support
badlop Jan 16, 2025
c230c97
Container: Fix warning about relative workdir
badlop Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 53 additions & 39 deletions .github/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#' Define default build variables
## specifc ARGs for METHOD='direct'
ARG OTP_VSN='27.2'
ARG ELIXIR_VSN='1.18.1'
## specifc ARGs for METHOD='package'
ARG ALPINE_VSN='3.19'
## general ARGs
ARG UID='9000'
ARG USER='ejabberd'
ARG HOME="opt/$USER"
ARG METHOD='direct'
ARG BUILD_DIR="/$USER"
ARG VERSION='master'

################################################################################
#' METHOD='direct' - build and install ejabberd directly from source
FROM docker.io/erlang:${OTP_VSN}-alpine AS direct
#' Compile ejabberdapi
FROM docker.io/golang:1.23-alpine AS api
RUN go install -v \
github.com/processone/ejabberd-api/cmd/ejabberd@master \
&& mv bin/ejabberd bin/ejabberdapi

################################################################################
#' build and install ejabberd directly from source
FROM docker.io/erlang:${OTP_VSN}-alpine AS ejabberd

RUN apk -U add --no-cache \
autoconf \
Expand All @@ -39,7 +41,8 @@ ARG ELIXIR_VSN
RUN wget -O - https://github.com/elixir-lang/elixir/archive/v$ELIXIR_VSN.tar.gz \
| tar -xzf -

WORKDIR elixir-$ELIXIR_VSN
WORKDIR /elixir-$ELIXIR_VSN
ENV ERL_FLAGS="+JPperf true"
RUN make install clean

RUN mix local.hex --force \
Expand All @@ -50,6 +53,7 @@ COPY / $BUILD_DIR/

WORKDIR $BUILD_DIR
RUN mv .github/container/ejabberdctl.template . \
&& mv .github/container/ejabberd.yml.example . \
&& ./autogen.sh \
&& ./configure --with-rebar=mix --enable-all \
&& make deps \
Expand All @@ -67,36 +71,18 @@ RUN cp -p $BUILD_DIR/tools/captcha*.sh $HOME-$VERSION/lib
RUN find "$HOME-$VERSION/bin" -name 'ejabberd' -delete \
&& find "$HOME-$VERSION/releases" -name 'COOKIE' -delete

RUN wget -O "$HOME/conf/cacert.pem" 'https://curl.se/ca/cacert.pem' \
&& sed -i '/^loglevel:/a \ \
\nca_file: /opt/ejabberd/conf/cacert.pem \
\ncertfiles: \
\n - /opt/ejabberd/conf/server.pem' "$HOME/conf/ejabberd.yml"

################################################################################
#' METHOD='package' - install ejabberd from binary tarball package
FROM docker.io/alpine:${ALPINE_VSN} AS package
COPY tarballs/ejabberd-*-linux-musl-*.tar.gz /tmp/
WORKDIR /rootfs
ARG HOME
RUN home_root_dir=$(echo $HOME | sed 's|\(.*\)/.*|\1 |') \
&& mkdir -p $home_root_dir \
&& ARCH=$(uname -m | sed -e 's/x86_64/x64/;s/aarch64/arm64/') \
&& tar -xzf /tmp/ejabberd-*-linux-musl-$ARCH.tar.gz -C $home_root_dir
RUN wget -O "$HOME/conf/cacert.pem" 'https://curl.se/ca/cacert.pem'

################################################################################
#' Prepare ejabberd for runtime
FROM ${METHOD} AS ejabberd
RUN apk -U add --no-cache \
git \
libcap \
openssl

WORKDIR /rootfs
ARG HOME
RUN mkdir -p usr/local/bin $HOME/conf $HOME/database $HOME/logs $HOME/upload

ARG BUILD_DIR
COPY --from=api /go/bin/ejabberdapi usr/local/bin/

RUN if [ ! -d $HOME/.ejabberd-modules ]; \
then \
if [ -d $BUILD_DIR/.ejabberd-modules ]; \
Expand All @@ -116,11 +102,35 @@ RUN export PEM=$HOME/conf/server.pem \
-days 3650 \
-subj "/CN=localhost"

RUN sed -i 's|^#CTL_OVER_HTTP=|CTL_OVER_HTTP=../|' "$HOME/conf/ejabberdctl.cfg"

RUN home_root_dir=$(echo $HOME | sed 's|\(.*\)/.*|\1 |') \
&& setcap 'cap_net_bind_service=+ep' $(find $home_root_dir -name beam.smp) \
&& echo -e \
"#!/bin/sh \
\n[ -z \$ERLANG_NODE_ARG ] && export ERLANG_NODE_ARG=ejabberd@localhost \
\nexport EMA=\"\$EJABBERD_MACRO_ADMIN\" \
\nexport HOST=\"\${EJABBERD_MACRO_HOST:-localhost}\" \
\nif [ -n \"\$EMA\" ] \
\nthen \
\n if [ \"\$EMA\" != \"\${EMA%%@*}\" ] \
\n then \
\n export USERNAME=\"\${EMA%%@*}\" \
\n export HOST=\"\${EMA##*@}\" \
\n else \
\n export USERNAME=\"\$EMA\" \
\n export SHOW_WARNING=\"true\" \
\n fi \
\nelif [ -n \"\$REGISTER_ADMIN_PASSWORD\" ] \
\nthen \
\n export USERNAME=\"admin\" \
\nelse \
\n export USERNAME=\"\$(od -A n -N 8 -t x8 /dev/urandom)\" \
\nfi \
\nexport EJABBERD_MACRO_ADMIN=\"\$USERNAME@\$HOST\" \
\n[ -n \"\$SHOW_WARNING\" ] && echo \"WARNING: The EJABBERD_MACRO_ADMIN environment variable was set to '\$EMA', but it should include the host... I'll overwrite it to become '\$EJABBERD_MACRO_ADMIN'.\" \
\n[ -n \"\$CTL_ON_CREATE\" ] && export SEPARATOR=\";\" \
\n[ -n \"\$REGISTER_ADMIN_PASSWORD\" ] && export CTL_ON_CREATE=\"register \${EJABBERD_MACRO_ADMIN%%@*} \${EJABBERD_MACRO_ADMIN##*@} \$REGISTER_ADMIN_PASSWORD \$SEPARATOR \$CTL_ON_CREATE\" \
\nexport CONFIG_DIR=/$HOME/conf \
\nexport LOGS_DIR=/$HOME/logs \
\nexport SPOOL_DIR=/$HOME/database \
Expand All @@ -137,28 +147,28 @@ RUN home_root_dir=$(echo $HOME | sed 's|\(.*\)/.*|\1 |') \
ARG UID
RUN chown -R $UID:$UID $HOME

RUN cp /rootfs/$HOME-$VERSION/lib/captcha*.sh usr/local/bin/
RUN mkdir $HOME/sql \
&& find /rootfs/$HOME-$VERSION/lib/ -name *.sql -exec cp {} $HOME/sql \; -exec cp {} $HOME/database \;

################################################################################
#' METHOD='direct' - Remove erlang/OTP & rebar3
FROM docker.io/erlang:${OTP_VSN}-alpine AS runtime-direct
#' Remove erlang/OTP & rebar3
FROM docker.io/erlang:${OTP_VSN}-alpine AS runtime
RUN apk del .erlang-rundeps \
&& rm -f $(which rebar3) \
&& find /usr -type d -name 'erlang' -exec rm -rf {} + \
&& find /usr -type l -exec test ! -e {} \; -delete

################################################################################
#' METHOD='package' - define runtime base image
FROM docker.io/alpine:${ALPINE_VSN} AS runtime-package

################################################################################
#' Update alpine, finalize runtime environment
FROM runtime-${METHOD} AS runtime
COPY --from=ejabberd /tmp/runDeps /tmp/runDeps
RUN apk -U upgrade --available --no-cache \
&& apk add --no-cache \
$(cat /tmp/runDeps) \
so:libcap.so.2 \
so:libtdsodbc.so.0 \
curl \
tini \
&& rm /tmp/runDeps \
&& ln -fs /usr/lib/libtdsodbc.so.0 /usr/lib/libtdsodbc.so

ARG USER
Expand All @@ -167,9 +177,13 @@ ARG HOME
RUN addgroup $USER -g $UID \
&& adduser -s /sbin/nologin -D -u $UID -h /$HOME -G $USER $USER

RUN ln -fs /usr/local/bin/ /opt/ejabberd/bin
RUN rm -rf /home \
&& ln -fs /opt /home

################################################################################
#' Build together production image
FROM scratch AS prod
FROM scratch
ARG USER
ARG HOME

Expand All @@ -186,7 +200,7 @@ HEALTHCHECK \
WORKDIR /$HOME
USER $USER
VOLUME ["/$HOME"]
EXPOSE 1883 4369-4399 5210 5222 5269 5280 5443
EXPOSE 1880 1883 4369-4399 5210 5222 5269 5280 5443

ENTRYPOINT ["/sbin/tini","--","ejabberdctl"]
CMD ["foreground"]
Loading
Loading