-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
539 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
#' Define default build variables | ||
## source ARGs | ||
ARG GO_VSN='1.23' | ||
ARG ERLANG_VSN='27.2' | ||
ARG ELIXIR_VSN='1.17.3' | ||
## general ARGs | ||
ARG UID='9000' | ||
ARG USER='ejabberd' | ||
ARG HOME="opt/$USER" | ||
ARG BUILD_DIR="/$USER" | ||
ARG VERSION='master' | ||
|
||
################################################################################ | ||
#' build elector | ||
FROM cgr.dev/chainguard/wolfi-base AS elector | ||
ARG GO_VSN | ||
RUN apk -U upgrade --available && apk add --no-cache \ | ||
build-base \ | ||
git \ | ||
go-$GO_VSN | ||
|
||
WORKDIR /elector | ||
RUN git clone https://github.com/sando38/k8s-elector \ | ||
--branch update-packages --depth 1 . | ||
|
||
RUN go get google.golang.org/[email protected] \ | ||
&& go get golang.org/x/[email protected] \ | ||
&& go mod tidy | ||
|
||
RUN make build-linux | ||
|
||
################################################################################ | ||
#' Build and base image | ||
FROM cgr.dev/chainguard/wolfi-base AS erlang | ||
ARG ERLANG_VSN | ||
ENV LC_ALL='C.UTF-8' \ | ||
LANG='C.UTF-8' | ||
|
||
RUN apk -U upgrade --available && apk add --no-cache \ | ||
autoconf \ | ||
automake \ | ||
bash \ | ||
build-base \ | ||
ca-certificates-bundle \ | ||
curl \ | ||
expat-dev \ | ||
file \ | ||
freetds freetds-dev \ | ||
freetype-dev \ | ||
gd-dev \ | ||
git \ | ||
libjpeg-dev \ | ||
libpng-dev \ | ||
libwebp-dev \ | ||
linux-pam-dev \ | ||
ncurses-dev \ | ||
pax-utils \ | ||
perl-dev \ | ||
openssl \ | ||
openssl-dev \ | ||
sqlite-dev \ | ||
unixodbc unixodbc-dev \ | ||
wget \ | ||
yaml-dev \ | ||
zlib-dev | ||
|
||
ARG ERLANG_VSN | ||
RUN wget -O - https://github.com/erlang/otp/releases/download/OTP-"$ERLANG_VSN"/otp_src_"$ERLANG_VSN".tar.gz \ | ||
| tar -xzf - | ||
|
||
WORKDIR /otp_src_"$ERLANG_VSN" | ||
## https://github.com/processone/ejabberd/commit/b288d5c76370e44fef3a9caa6fbb888435057a2a | ||
RUN sed -i 's|if(size == 0 && (sql_type == SQL_LONGVARCHAR|if((sql_type == SQL_LONGVARCHAR|g' lib/odbc/c_src/odbcserver.c | ||
RUN ./configure \ | ||
--prefix=/usr \ | ||
--sysconfdir=/etc \ | ||
--mandir=/usr/share/man \ | ||
--infodir=/usr/share/info \ | ||
--host="$CHOST" \ | ||
--build="$CBUILD" \ | ||
--enable-threads \ | ||
--enable-shared-zlib \ | ||
--enable-ssl=dynamic-ssl-lib \ | ||
--enable-jit \ | ||
&& make install | ||
|
||
WORKDIR / | ||
ARG ELIXIR_VSN | ||
RUN wget -O - https://github.com/elixir-lang/elixir/archive/v"$ELIXIR_VSN".tar.gz \ | ||
| tar -xzf - | ||
|
||
WORKDIR /elixir-"$ELIXIR_VSN" | ||
RUN make install clean | ||
|
||
RUN mix local.hex --force \ | ||
&& mix local.rebar --force | ||
|
||
################################################################################ | ||
#' Build and prepare ejabberd | ||
FROM erlang AS build | ||
ENV LC_ALL='C.UTF-8' \ | ||
LANG='C.UTF-8' | ||
|
||
ARG BUILD_DIR | ||
COPY / $BUILD_DIR/ | ||
|
||
WORKDIR $BUILD_DIR/.ejabberd-modules/sources/ejabberd-contrib | ||
|
||
# include some ejabberd contribution modules which may be nice for clusters | ||
RUN git clone https://github.com/processone/ejabberd-contrib --depth 1 . \ | ||
&& install mod_s3_upload/src/*.erl $BUILD_DIR/src \ | ||
&& install mod_s3_upload/include/*.hrl $BUILD_DIR/include \ | ||
&& install mod_ecaptcha/src/*.erl $BUILD_DIR/src \ | ||
&& install ejabberd_auth_http/src/*.erl $BUILD_DIR/src \ | ||
&& rm -rf mod_ecaptcha mod_http_redirect mod_s3_upload | ||
|
||
WORKDIR $BUILD_DIR | ||
RUN mv .github/container/ejabberdctl.template . \ | ||
&& ./autogen.sh \ | ||
&& ./configure --with-rebar=mix --enable-all \ | ||
&& make deps \ | ||
&& make rel | ||
|
||
WORKDIR /rootfs | ||
ARG VERSION | ||
ARG HOME | ||
RUN mkdir -p $HOME $HOME-$VERSION \ | ||
&& cp -r $BUILD_DIR/_build/prod/rel/ejabberd/* $HOME-$VERSION \ | ||
&& mv $HOME-$VERSION/conf $HOME/conf | ||
|
||
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 | ||
|
||
## openssl does not find /etc/ssl/openssl.cnf in workflow, check later | ||
# 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" | ||
RUN mkdir -p usr/local/bin $HOME/conf $HOME/database $HOME/logs $HOME/upload | ||
|
||
ARG BUILD_DIR | ||
RUN if [ ! -d $HOME/.ejabberd-modules ]; \ | ||
then \ | ||
if [ -d $BUILD_DIR/.ejabberd-modules ]; \ | ||
then cp -r $BUILD_DIR/.ejabberd-modules $HOME; \ | ||
else git clone https://github.com/processone/ejabberd-contrib --depth 1 \ | ||
$HOME/.ejabberd-modules/sources/ejabberd-contrib; \ | ||
fi \ | ||
fi | ||
|
||
## openssl does not find /etc/ssl/openssl.cnf in workflow, check later | ||
# RUN export PEM=$HOME/conf/server.pem \ | ||
# && openssl req -x509 \ | ||
# -batch \ | ||
# -nodes \ | ||
# -newkey rsa:4096 \ | ||
# -keyout $PEM \ | ||
# -out $PEM \ | ||
# -days 3650 \ | ||
# -subj "/CN=localhost" | ||
|
||
RUN home_root_dir=$(echo $HOME | sed 's|\(.*\)/.*|\1 |') \ | ||
&& echo -e \ | ||
"#!/bin/sh \ | ||
\n[ -z \$ERLANG_NODE_ARG ] && export ERLANG_NODE_ARG=ejabberd@localhost \ | ||
\nexport CONFIG_DIR=/$HOME/conf \ | ||
\nexport LOGS_DIR=/$HOME/logs \ | ||
\nexport SPOOL_DIR=/$HOME/database \ | ||
\nexec /$(find $home_root_dir -name ejabberdctl) \"\$@\"" \ | ||
> usr/local/bin/ejabberdctl \ | ||
&& chmod +x usr/local/bin/* \ | ||
&& scanelf --needed --nobanner --format '%n#p' --recursive "$PWD" \ | ||
| tr ',' '\n' \ | ||
| sort -u \ | ||
| awk 'system("[ -e $PWD" $1 " ]") == 0 { next } { print "so:" $1 }' \ | ||
> /tmp/runDeps | ||
|
||
ARG UID | ||
RUN chown -R $UID:$UID $HOME | ||
|
||
################################################################################ | ||
#' Get AlpineÄs busybox for ejabberdctl script | ||
FROM cgr.dev/chainguard/wolfi-base AS runtime | ||
RUN apk -U upgrade --available --no-cache | ||
|
||
ARG USER | ||
ARG UID | ||
ARG HOME | ||
RUN addgroup $USER -g $UID \ | ||
&& adduser -s /sbin/nologin -D -u $UID -h /$HOME -G $USER $USER | ||
|
||
COPY --from=build /tmp/runDeps /tmp/runDeps | ||
RUN apk add --no-cache -t .ejabberd-rundeps \ | ||
$(cat /tmp/runDeps) \ | ||
freetds unixodbc \ | ||
bind-tools \ | ||
busybox \ | ||
ca-certificates-bundle \ | ||
gettext \ | ||
jq \ | ||
netcat-openbsd \ | ||
tini \ | ||
wget | ||
|
||
RUN apk del --repositories-file /dev/null \ | ||
wolfi-base \ | ||
wolfi-keys \ | ||
apk-tools \ | ||
&& rm -rf /var/cache/apk /etc/apk /tmp/* \ | ||
&& find /lib/apk/db -type f -not -name 'installed' -delete | ||
|
||
################################################################################ | ||
#' Forge release image | ||
FROM scratch AS release | ||
ARG USER | ||
ARG HOME | ||
ENV ERL_DIST_PORT='5210' \ | ||
LC_ALL='C.UTF-8' \ | ||
LANG='C.UTF-8' | ||
|
||
COPY --from=runtime / / | ||
COPY --from=build /rootfs / | ||
COPY --from=elector /elector/elector /usr/local/bin/elector | ||
|
||
HEALTHCHECK \ | ||
--interval=1m \ | ||
--timeout=5s \ | ||
--start-period=5s \ | ||
--retries=10 \ | ||
CMD ejabberdctl status | ||
|
||
WORKDIR /$HOME | ||
USER $USER | ||
VOLUME ["/$HOME"] | ||
EXPOSE 5210 5222 5223 5280 | ||
|
||
ENTRYPOINT ["/sbin/tini","--","ejabberdctl"] | ||
CMD ["foreground"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
diff --git a/mix.exs b/mix.exs | ||
index 45f2479b..532eccc1 100644 | ||
--- a/mix.exs | ||
+++ b/mix.exs | ||
@@ -47,6 +47,7 @@ defmodule Ejabberd.MixProject do | ||
:logger, :mix] | ||
++ cond_apps(), | ||
included_applications: [:mnesia, :os_mon, | ||
+ :cuesport, :fusco, :ecaptcha, | ||
:cache_tab, :eimp, :mqtree, :p1_acme, | ||
:p1_oauth2, :pkix] | ||
++ cond_included_apps()] | ||
@@ -131,12 +132,15 @@ defmodule Ejabberd.MixProject do | ||
|
||
defp deps do | ||
[{:cache_tab, "~> 1.0"}, | ||
+ {:cuesport, github: "goj/cuesport", manager: :rebar3}, | ||
{:dialyxir, "~> 1.2", only: [:test], runtime: false}, | ||
+ {:ecaptcha, github: "seriyps/ecaptcha"}, | ||
{:eimp, "~> 1.0"}, | ||
{:ex_doc, "~> 0.31", only: [:dev, :edoc], runtime: false}, | ||
{:fast_tls, "~> 1.1.22"}, | ||
{:fast_xml, "~> 1.1.53", override: true}, | ||
{:fast_yaml, "~> 1.0"}, | ||
+ {:fusco, "~> 0.1"}, | ||
{:idna, "~> 6.0"}, | ||
{:mqtree, "~> 1.0"}, | ||
{:p1_acme, "~> 1.0"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
# Determine pod's cluster name | ||
pod_name="${POD_NAME:-$(hostname -s)}" # e.g. pod-0 | ||
pod_endpoint_name="$(hostname -f)" # e.g. pod-0.servicename.namespace.svc.cluster.local | ||
sts_name="$(echo $pod_name | sed 's|-[0-9]\+||g')" | ||
|
||
[ -z "$ERLANG_NODE_ARG" ] && export ERLANG_NODE_ARG="$sts_name@$pod_endpoint_name" | ||
export CONFIG_DIR="$HOME"/conf | ||
export LOGS_DIR="$HOME"/logs | ||
export SPOOL_DIR="$HOME"/database | ||
|
||
exec $(find /opt -name ejabberdctl) "$@" |
Oops, something went wrong.