elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Update Docker build to use python3

Open jdeglopper opened this issue 6 years ago • 10 comments

Based on the changes by @nqkdev in #117, but including needed changes to launch elastalert under Python 3 while still using Python 2 for node-gyp.

jdeglopper avatar Aug 27 '19 20:08 jdeglopper

Jira needs to be updated to work with the new elastalert by the way - see https://github.com/Yelp/elastalert/issues/2437

jira>=2.0.0 should fix the problem.

caleb15 avatar Sep 12 '19 20:09 caleb15

Why this PR still didn't get merged?

Folyd avatar Dec 10 '19 03:12 Folyd

+1

alvarolmedo avatar Dec 10 '19 16:12 alvarolmedo

This dockerfile installs python3.7, this version is not supported by elastalert yet.

alvarolmedo avatar Dec 12 '19 22:12 alvarolmedo

I use this dockerfile and it's installs python3.6

hottwister avatar Jan 09 '20 12:01 hottwister

Well, I found the problem, and I can confirm that python3.7 is installed. the problem is the second Form in the multi-stage Dockerfile and the python installation in this stage (lines 27 and 32):

FROM node:alpine
(....)
RUN apk add --update --no-cache curl tzdata python2 python3 make libmagic

If you build a docker image with this sentences and run a container with the image generated, the version of python can be checked:

$ cat Dockerfile 
FROM node:alpine
RUN apk add --update --no-cache curl tzdata python2 python3

$ docker build -t test_python_version:latest .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM node:alpine
 ---> 5f8b3338a759
Step 2/2 : RUN apk add --update --no-cache curl tzdata python2 python3
 ---> Running in 6ed63b22c022
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(....)
Removing intermediate container 6ed63b22c022
 ---> 22d58201ed43
Successfully built 22d58201ed43
Successfully tagged test_python_version:latest

$ docker run --rm -ti --entrypoint /bin/sh test_python_version:latest
/ # python3 --version
Python 3.7.5
/ # exit

alvarolmedo avatar Jan 10 '20 13:01 alvarolmedo

And this is my python versions from running container builded with this DockerFile

# docker exec -u root -it elastalert sh
/opt/elastalert-server # python --version
Python 2.7.16
/opt/elastalert-server # python3 --version
Python 3.6.8

hottwister avatar Jan 10 '20 13:01 hottwister

When you build the image used by these container? Alpine could update this package in some moment between your build and my first build one month ago... Or, maybe, node:alpine image is in the host when the build is done (the FROM sentence doesn't forces the docker pull action), in this way, I've forced the docker pull of node:alpine and now the python3 version is right respect the info in alpine website[1]:

$ docker build -t test_python_version:latest .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM node:alpine
 ---> 364fb8e7f28a
Step 2/2 : RUN apk add --update --no-cache python3
 ---> Running in 9d86ff9da0ea
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(...)
(11/11) Installing python3 (3.8.1-r0)
Executing busybox-1.31.1-r8.trigger
OK: 73 MiB in 27 packages
Removing intermediate container 9d86ff9da0ea
 ---> eedaffec0d97
Successfully built eedaffec0d97
Successfully tagged test_python_version:latest

$ docker run --rm -ti --entrypoint /bin/sh test_python_version:latest
/ # python3 --version
Python 3.8.1

[1] https://pkgs.alpinelinux.org/package/edge/main/x86/python3

alvarolmedo avatar Jan 10 '20 14:01 alvarolmedo

@alvarolmedo thx for pointing to python version issue.

I've managed with this by:

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' >> /etc/apk/repositories
RUN apk add --update --no-cache curl tzdata python2 'python3<3.6.9' make libmagic

https://github.com/Karql/elastalert/commit/b2790b2e8d18e5f6ddef44dc363167eaaa1ca44f

Karql avatar Jan 16 '20 09:01 Karql

Great solution @Karql .

I changed the second base image:

FROM nikolaik/python-nodejs:python3.6-nodejs13-alpine

And a pair of changes more.... The target path changed:

COPY --from=py-ea /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages

And I need to create node user correctly:

RUN addgroup -g 1000 node && \
    adduser -u 1000 -G node -s /bin/sh -D node && \

I don't create a PR with my fix, because I consider it a temporary solution. So I will change my Dockerfile to your solution.

alvarolmedo avatar Jan 16 '20 18:01 alvarolmedo