Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 60 additions & 42 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,111 +1,129 @@
FROM python:3.12-slim-bookworm
FROM python:3.12-slim-trixie AS builder
WORKDIR /


ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1

ARG BUILD_DATE
ARG RELEASE
ARG VERSION

ENV GAPIT_VERSION=${RELEASE}
ENV SERVER_VERSION=${RELEASE}
ENV CLIENT_VERSION=4.0.0
ENV WEBUI_VERSION=${RELEASE}

ENV NGINX_WORKER_PROCESSES=1
ENV NGINX_WORKER_CONNECTIONS=1024

ENV UWSGI_PROCESSES=5
ENV UWSGI_LISTEN=100
ENV UWSGI_BUFFER_SIZE=8192
ENV UWSGI_MAX_WORKER_LIFETIME=30
ENV UWSGI_WORKER_LIFETIME_DELTA=3
ENV FRONTEND_BASE_URL=/

ENV HEARTBEAT_SEVERITY=major
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
gnupg2 \
libldap2-dev \
libpq-dev \
libsasl2-dev \
postgresql-client \
python3-dev \
supervisor \
libpcre3 \
libpcre3-dev \
libpcre2-dev \
libpcre2-8-0 \
ca-certificates \
xmlsec1 && \
apt-get -y clean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add - && \
echo "deb https://nginx.org/packages/debian/ buster nginx" | tee /etc/apt/sources.list.d/nginx.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
nginx && \
apt-get -y clean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*

COPY requirements*.txt /app/

# hadolint ignore=DL3013
RUN pip install --no-cache-dir pip virtualenv jinja2 && \
RUN pip install --no-cache-dir pip virtualenv && \
python3.12 -m venv /venv && \
/venv/bin/pip install --no-cache-dir --upgrade setuptools && \
/venv/bin/pip install --no-cache-dir --requirement /app/requirements.txt && \
/venv/bin/pip install --no-cache-dir --requirement /app/requirements-docker.txt
/venv/bin/pip install --no-cache-dir --requirement /app/requirements-docker.txt && \
/venv/bin/pip install --no-cache-dir jinja2

ENV PATH=$PATH:/venv/bin

#download and install alerta client
ADD https://github.com/gapitio/python-alerta-client/releases/download/v${CLIENT_VERSION}/alerta-client.tar.gz /tmp/client/client.tar.gz
RUN tar zxvf /tmp/client/client.tar.gz -C /tmp/client/ && \
find /tmp/client/dist -name "*-py2.py3-none-any.whl" -print0 | xargs -0 -I{} /venv/bin/pip install {}

#download and install alerta server/backend
ADD https://github.com/gapitio/alerta/releases/download/${SERVER_VERSION}/alerta-api.tar.gz /tmp/backend/alerta.tar.gz
RUN tar zxvf /tmp/backend/alerta.tar.gz -C /tmp/backend && \
find /tmp/backend/dist -name "*-py2.py3-none-any.whl" -print0 | xargs -0 -I{} /venv/bin/pip install {}
COPY install-plugins.sh /app/install-plugins.sh
COPY plugins.txt /app/plugins.txt
RUN /app/install-plugins.sh

ENV ALERTA_SVR_CONF_FILE=/app/alertad.conf
ENV ALERTA_CONF_FILE=/app/alerta.conf

#download alerta frontend
ADD https://github.com/gapitio/alerta-webui/releases/download/${WEBUI_VERSION}/alerta-webui.tar.gz /tmp/webui.tar.gz
RUN tar zxvf /tmp/webui.tar.gz -C /tmp && \
mv /tmp/dist /web


FROM python:3.12-slim-trixie AS runtime
WORKDIR /

COPY --from=builder /venv /venv
COPY --from=builder /web /web
COPY --from=builder /app /app

ARG RELEASE
ENV GAPIT_VERSION=${RELEASE}

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1
ENV PATH=$PATH:/venv/bin

ENV NGINX_WORKER_PROCESSES=1
ENV NGINX_WORKER_CONNECTIONS=1024

ENV UWSGI_PROCESSES=5
ENV UWSGI_LISTEN=100
ENV UWSGI_BUFFER_SIZE=8192
ENV UWSGI_MAX_WORKER_LIFETIME=30
ENV UWSGI_WORKER_LIFETIME_DELTA=3
ENV FRONTEND_BASE_URL=/

ENV HEARTBEAT_SEVERITY=major

ENV ALERTA_SVR_CONF_FILE=/app/alertad.conf
ENV ALERTA_CONF_FILE=/app/alerta.conf
ENV ALERTA_WEB_CONF_FILE=/web/config.json

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
gnupg2 \
libpq-dev \
supervisor \
ca-certificates \
xmlsec1 \
nginx && \
apt-get -y clean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*

COPY config/templates/app/ /app
COPY config/templates/web/ /web

RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

# user and permissions
RUN chgrp -R 0 /app /venv /web && \
chmod -R g=u /app /venv /web && \
useradd -u 1001 -g 0 -d /app alerta

USER 1001

COPY docker-entrypoint.sh /usr/local/bin/

# entry point
ENV INIT_LOG=false

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 8080 1717
CMD ["supervisord", "-c", "/app/supervisord.conf"]
CMD ["supervisord", "-c", "/app/supervisord.conf"]
1 change: 1 addition & 0 deletions config/templates/app/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ http {
index index.html;

location {{ env.FRONTEND_BASE_URL }} {
default_type text/html;
try_files $uri $uri/ {{ env.FRONTEND_BASE_URL }}index.html;
}

Expand Down
16 changes: 8 additions & 8 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MAXAGE=${ADMIN_KEY_MAXAGE:-315360000} # default=10 years
if [ ! -f "${ALERTA_SVR_CONF_FILE}" ]; then
if [ $INIT_LOG = true ]; then echo "# Create server configuration file."; fi
export SECRET_KEY=${SECRET_KEY:-$(< /dev/urandom tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= | head -c 32)}
python3 -c "${JINJA2}" < ${ALERTA_SVR_CONF_FILE}.j2 >${ALERTA_SVR_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${ALERTA_SVR_CONF_FILE}.j2 >${ALERTA_SVR_CONF_FILE}
fi

# Init admin users and API keys
Expand All @@ -43,7 +43,7 @@ if [ ! -f "${ALERTA_CONF_FILE}" ]; then
# Add API key to client config, if required
if [ "${AUTH_REQUIRED,,}" == "true" ]; then
if [ $INIT_LOG = true ]; then echo "# Auth enabled; add admin API key to client configuration."; fi
HOUSEKEEPING_SCOPES="--scope read --scope write:alerts --scope admin:management --scope write:notification_rules --scope delete:alerts"
HOUSEKEEPING_SCOPES="--scope read --scope write:alerts --scope admin:management --scope write:notification.rules --scope delete:alerts"
if grep -qE 'CUSTOMER_VIEWS.*=.*True' ${ALERTA_SVR_CONF_FILE};then
HOUSEKEEPING_SCOPES="--scope admin:alerts ${HOUSEKEEPING_SCOPES}"
fi
Expand All @@ -54,26 +54,26 @@ if [ ! -f "${ALERTA_CONF_FILE}" ]; then
--text "Housekeeping")
fi
if [ $INIT_LOG = true ]; then echo "# Create client configuration file."; fi
python3 -c "${JINJA2}" < ${ALERTA_CONF_FILE}.j2 >${ALERTA_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${ALERTA_CONF_FILE}.j2 >${ALERTA_CONF_FILE}
fi

# Generate supervisord config, if not supplied
if [ ! -f "${SUPERVISORD_CONF_FILE}" ]; then
if [ $INIT_LOG = true ]; then echo "# Create supervisord configuration file."; fi
python3 -c "${JINJA2}" < ${SUPERVISORD_CONF_FILE}.j2 >${SUPERVISORD_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${SUPERVISORD_CONF_FILE}.j2 >${SUPERVISORD_CONF_FILE}
fi

# Generate nginx config, if not supplied.
if [ ! -f "${NGINX_CONF_FILE}" ]; then
if [ $INIT_LOG = true ]; then echo "# Create nginx configuration file."; fi
python3 -c "${JINJA2}" < ${NGINX_CONF_FILE}.j2 >${NGINX_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${NGINX_CONF_FILE}.j2 >${NGINX_CONF_FILE}
fi
nginx -t -c ${NGINX_CONF_FILE}

# Generate uWSGI config, if not supplied.
if [ ! -f "${UWSGI_CONF_FILE}" ]; then
if [ $INIT_LOG = true ]; then echo "# Create uWSGI configuration file."; fi
python3 -c "${JINJA2}" < ${UWSGI_CONF_FILE}.j2 >${UWSGI_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${UWSGI_CONF_FILE}.j2 >${UWSGI_CONF_FILE}
fi

if [ ! -d "/web${FRONTEND_BASE_URL}" ]; then
Expand All @@ -84,7 +84,7 @@ fi
# Generate web config, if not supplied.
if [ ! -f "${ALERTA_WEB_CONF_FILE}" ]; then
if [ $INIT_LOG = true ]; then echo "# Create web configuration file."; fi
python3 -c "${JINJA2}" < ${ALERTA_WEB_CONF_FILE}.j2 >${ALERTA_WEB_CONF_FILE}
/venv/bin/python3 -c "${JINJA2}" < ${ALERTA_WEB_CONF_FILE}.j2 >${ALERTA_WEB_CONF_FILE}
fi

if [ $INIT_LOG = true ]; then
Expand All @@ -97,7 +97,7 @@ if [ $INIT_LOG = true ]; then
nginx -v
echo uwsgi $(uwsgi --version)
psql --version
python3 --version
/venv/bin/python3 --version
/venv/bin/pip list

echo
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.test.postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- ADMIN_USERS=admin@alerta.io,devops@alerta.io # default password: alerta
- ADMIN_KEY=demo-key
- ADMIN_KEY_MAXAGE=31536000 # 1 year in seconds
- PLUGINS=reject,blackout,normalise,enhance
- PLUGINS=reject,blackout
- HEARTBEAT_SEVERITY=warning
# Disable hearbeat alerts by setting below env var to empty string
# - HEARTBEAT_SEVERITY=
Expand Down
4 changes: 2 additions & 2 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM ruby:3.0
FROM ruby:4.0

COPY Gemfile* ./
RUN gem install bundler && bundle install --jobs=3 --retry=3

RUN apt-get -q update && apt-get -qy install netcat
RUN apt-get -q update && apt-get -qy install netcat-traditional
RUN wget https://raw.githubusercontent.com/eficode/wait-for/v2.2.0/wait-for && chmod +x wait-for

COPY .rspec .
Expand Down
1 change: 1 addition & 0 deletions tests/docker/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Gemfile
source "https://rubygems.org"

gem 'logger'
gem "rspec"
gem 'rest-client'
gem 'nokogiri'
Loading