-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDockerfile
102 lines (84 loc) · 3.75 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
FROM python:3.6-alpine
LABEL description="ElastAlert for docker reference @sc250024/docker-elastalert"
LABEL maintainer="anjia0532 ([email protected]) Scott Crooks <[email protected]>"
ARG ELASTALERT_VERSION=v0.2.4
ARG MIRROR=false
ARG ALPINE_HOST="mirrors.aliyun.com"
ARG PIP_MIRROR="https://mirrors.aliyun.com/pypi/simple/"
# base env
ENV ELASTALERT_HOME=/opt/elastalert \
SET_CONTAINER_TIMEZONE=true \
CONTAINER_TIMEZONE=Etc/UTC
# elastalert env
ENV ELASTALERT_URL=https://github.com/Yelp/elastalert/archive/${ELASTALERT_VERSION}.tar.gz \
ELASTALERT_RULES_DIRECTORY=${ELASTALERT_HOME}/rules \
ELASTALERT_PLUGIN_DIRECTORY=${ELASTALERT_HOME}/elastalert_modules \
ELASTALERT_ENHANCEMENT_DIRECTORY=${ELASTALERT_HOME}/elastalert_enhancements \
ELASTALERT_CONFIG="${ELASTALERT_HOME}/config.yaml" \
ELASTALERT_INDEX=elastalert_status \
ELASTALERT_SYSTEM_GROUP=elastalert \
ELASTALERT_SYSTEM_USER=elastalert \
ELASTICSEARCH_HOST=elasticsearch \
ELASTICSEARCH_PORT=9200 \
ELASTICSEARCH_USE_SSL=False \
ELASTICSEARCH_VERIFY_CERTS=False
WORKDIR ${ELASTALERT_HOME}
# Get Dockerize for configuration templating
COPY --from=jwilder/dockerize:0.6.1 /usr/local/bin/dockerize /usr/local/bin/dockerize
RUN chmod +x "/usr/local/bin/dockerize"
# Create directories and Elastalert system user/group.
# The /var/empty directory is used by openntpd.
RUN mkdir -p "${ELASTALERT_HOME}" && \
mkdir -p "${ELASTALERT_PLUGIN_DIRECTORY}" && \
mkdir -p "${ELASTALERT_ENHANCEMENT_DIRECTORY}" && \
mkdir -p "${ELASTALERT_RULES_DIRECTORY}" && \
mkdir -p /var/empty && \
addgroup "${ELASTALERT_SYSTEM_GROUP}" && \
adduser -S -G "${ELASTALERT_SYSTEM_GROUP}" "${ELASTALERT_SYSTEM_USER}" && \
chown -R "${ELASTALERT_SYSTEM_USER}":"${ELASTALERT_SYSTEM_GROUP}" "${ELASTALERT_HOME}" "${ELASTALERT_PLUGIN_DIRECTORY}" "${ELASTALERT_RULES_DIRECTORY}"
# set up environment install packages
RUN set -ex && \
if $MIRROR; then sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_HOST}/g" /etc/apk/repositories ; pip config set global.index-url ${PIP_MIRROR} ; /bin/echo -e "[easy_install]\\nindex-url = ${PIP_MIRROR}" >> ~/.pydistutils.cfg ; fi && \
apk update && \
apk upgrade && \
apk add --no-cache \
ca-certificates \
tzdata \
su-exec \
dumb-init \
bash \
curl \
openssl && \
apk add --no-cache --virtual \
.build-dependencies \
gcc \
libffi-dev \
python-dev \
tar \
musl-dev \
openssl-dev && \
pip install --upgrade pip
# compile elastalert
RUN set -ex && \
curl -Lo elastalert.tar.gz ${ELASTALERT_URL} && \
tar -xzvf elastalert.tar.gz -C ${ELASTALERT_HOME} --strip-components 1 && \
rm elastalert.tar.gz && \
cd ${ELASTALERT_HOME} &&\
python setup.py install && \
apk del --purge .build-dependencies && \
rm -rf /var/cache/apk/*
COPY ./rules/* ${ELASTALERT_RULES_DIRECTORY}/
COPY ./elastalert_modules/* ${ELASTALERT_PLUGIN_DIRECTORY}/
COPY ./elastalert_enhancements/* ${ELASTALERT_ENHANCEMENT_DIRECTORY}/
# Copy the ${ELASTALERT_HOME} template
COPY config.yaml.tpl "${ELASTALERT_HOME}/config.yaml.tpl"
# Copy the script used to launch the Elastalert when a container is started.
COPY docker-entrypoint.sh /opt/docker-entrypoint.sh
RUN chmod +x /opt/docker-entrypoint.sh
# The square brackets around the 'e' are intentional. They prevent `grep`
# itself from showing up in the process list and falsifying the results.
# See here: https://stackoverflow.com/questions/9375711/more-elegant-ps-aux-grep-v-grep
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD ps -ef | grep "[e]lastalert.elastalert" >/dev/null 2>&1
# Launch Elastalert when a container is started.
CMD ["/opt/docker-entrypoint.sh"]