Skip to content

Commit

Permalink
Upgrade k8s contrib to v6 (#94)
Browse files Browse the repository at this point in the history
* Update Dockerfile

* install pip packages with virtual env and permissions for the alerta user

* Update to use new config file.json rather than .js

* add port to uswigi
  • Loading branch information
doodle-tnw authored and satterly committed Oct 18, 2018
1 parent 304370d commit aa8576f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 56 deletions.
6 changes: 3 additions & 3 deletions contrib/kubernetes/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6.5
FROM python:3.6
ENV PYTHONUNBUFFERED 1

ARG VERSION
Expand All @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \
RUN pip install --no-cache-dir virtualenv && \
virtualenv --python=python3 /venv && \
/venv/bin/pip install uwsgi alerta alerta-server==$VERSION

ENV PATH $PATH:/venv/bin

WORKDIR /app
Expand All @@ -22,11 +23,10 @@ RUN chgrp -R 0 /app /venv && \
USER 1001

COPY wsgi.py /app/wsgi.py
COPY uwsgi.ini.template /app/uwsgi.ini.template
COPY uwsgi.ini /app/uwsgi.ini

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

ENV BASE_URL /
ENV INSTALL_PLUGINS ""
Expand Down
33 changes: 22 additions & 11 deletions contrib/kubernetes/backend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ EOF
fi

if [ ! -f "${RUN_ONCE}" ]; then
# Init admin users and API Keys

# Init admin users and API keys
if [ -n "${ADMIN_USERS}" ]; then
alertad user --password ${ADMIN_PASSWORD:-alerta} --all
alertad key --all
fi

# Generate alerta CLI config
API_KEY=`alertad keys 2>/dev/null | head -1 | cut -d" " -f1`
if [ -n "${API_KEY}" ]; then
cat >${ALERTA_CONF_FILE} << EOF
[DEFAULT]
endpoint = http://localhost:8080
key = ${API_KEY}
EOF
# Create user-defined API key, if required
if [ -n "${ADMIN_KEY}" ]; then
alertad key --username $(echo ${ADMIN_USERS} | cut -d, -f1) --key ${ADMIN_KEY}
fi
fi

# Install plugins
Expand All @@ -37,6 +33,21 @@ EOF
touch ${RUN_ONCE}
fi

envsubst < /app/uwsgi.ini.template > /app/uwsgi.ini
# Generate client config, if not supplied
if [ ! -f "${ALERTA_CONF_FILE}" ]; then
API_KEY=${ADMIN_KEY:-$(alertad keys 2>/dev/null | head -1 | cut -d" " -f1)}
if [ -n "${API_KEY}" ]; then
cat >${ALERTA_CONF_FILE} << EOF
[DEFAULT]
endpoint = http://localhost:8080${BASE_URL}
key = ${API_KEY}
EOF
else
cat >${ALERTA_CONF_FILE} << EOF
[DEFAULT]
endpoint = http://localhost:8080${BASE_URL}
EOF
fi
fi

exec "$@"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[uwsgi]
chdir = /
mount = ${BASE_URL}=/app/wsgi.py
mount = $(BASE_URL)=/app/wsgi.py
callable = app
manage-script-name = true

Expand All @@ -13,4 +13,4 @@ uid = alerta
gid = alerta
vacuum = true

die-on-term = true
die-on-term = true
6 changes: 1 addition & 5 deletions contrib/kubernetes/backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

try:
from alerta import app # alerta >= 5.0
except ImportError:
from alerta.app import app # alerta < 5.0
from alerta import app
17 changes: 3 additions & 14 deletions contrib/kubernetes/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ ADD https://github.com/alerta/angular-alerta-webui/archive/master.tar.gz /tmp/we
RUN tar zxvf /tmp/web.tar.gz -C /tmp && \
rm -rf /usr/share/nginx/html && \
mv /tmp/angular-alerta-webui-master/app /usr/share/nginx/html && \
mv /usr/share/nginx/html/config.js /usr/share/nginx/html/config.js.orig
mv /usr/share/nginx/html/config.json /usr/share/nginx/html/config.json.orig


ENV ALERTA_API_SERVER '"http://"+window.location.hostname+":8080"'
ENV AUTH_PROVIDER basic
ENV CLIENT_ID "INSERT-CLIENT-ID-HERE"
ENV GITHUB_URL ""
ENV GITLAB_URL "https://gitlab.com"
ENV KEYCLOAK_URL "https://keycloak.example.org"
ENV KEYCLOAK_REALM "master"
ENV PINGFEDERATE_URL "https://pingfederate.example.org"
ENV COLORS {}
ENV SEVERITY {}
ENV AUDIO {}
ENV TRACKING_ID ""
ENV ALERTA_API_SERVER 'http://alerta:8080/'

COPY config.js.template /usr/share/nginx/html/config.js.template
COPY config.json.template /usr/share/nginx/html/config.json.template
COPY alerta-frontend-entrypoint.sh /alerta-frontend-entrypoint.sh

ENTRYPOINT ["/alerta-frontend-entrypoint.sh"]
Expand Down
7 changes: 3 additions & 4 deletions contrib/kubernetes/frontend/alerta-frontend-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

if ! echo -n "${ALERTA_API_SERVER}" | grep -q '^".*"$'; then
ALERTA_API_SERVER="\"${ALERTA_API_SERVER}\""
# Generate web console config, if not supplied
if [ ! -f "${ALERTA_WEB_CONF_FILE}" ]; then
envsubst < /usr/share/nginx/html/config.json.template > /usr/share/nginx/html/config.json
fi

envsubst < /usr/share/nginx/html/config.js.template > /usr/share/nginx/html/config.js

exec "$@"
17 changes: 0 additions & 17 deletions contrib/kubernetes/frontend/config.js.template

This file was deleted.

1 change: 1 addition & 0 deletions contrib/kubernetes/frontend/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"endpoint": "${ALERTA_API_SERVER}"}

0 comments on commit aa8576f

Please sign in to comment.