Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Docker build to use python3 #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jdeglopper
Copy link

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.

Jacob DeGlopper and others added 2 commits August 27, 2019 00:17
@caleb15
Copy link

caleb15 commented Sep 12, 2019

Jira needs to be updated to work with the new elastalert by the way - see Yelp/elastalert#2437

jira>=2.0.0 should fix the problem.

@Folyd
Copy link

Folyd commented Dec 10, 2019

Why this PR still didn't get merged?

@alvarolmedo
Copy link
Contributor

+1

@alvarolmedo
Copy link
Contributor

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

@hottwister
Copy link

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

@alvarolmedo
Copy link
Contributor

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

@hottwister
Copy link

hottwister commented Jan 10, 2020

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

@alvarolmedo
Copy link
Contributor

alvarolmedo commented Jan 10, 2020

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

@Karql
Copy link

Karql commented Jan 16, 2020

@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

Karql/elastalert2-server@b2790b2

@alvarolmedo
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants