processone / docker-ejabberd

Set of ejabberd Docker images
94 stars 77 forks source link

How to run python script with docker-compose ejabberd #75

Closed Carlososuna11 closed 2 years ago

Carlososuna11 commented 2 years ago

Hello make this docker-compose and I have an external authorization script in python, what is the configuration that I have to do to make it run? Docker-compose

...
  ejabberd:
    image: ejabberd/ecs:21.07
    restart: always
    env_file:
      - ./.env.dev
    depends_on:
      - db
    environment:
      - ERLANG_NODE_ARG=ejabberd@pictune_develop
      - CTL_ON_CREATE=register pictune_develop pictune_develop pictune_develop ;
                      module_install mod_offline_http_post ;
      - CTL_ON_START=stats registeredusers ;
                    status
    command: ["foreground"]
    # healthcheck:
    #   test: netstat -nl | grep -q 5222
    #   start_period: 5s
    #   interval: 5s
    #   timeout: 5s
    #   retries: 120
    ports:
      - "5222:5222"
      - "5269:5269"
      - "5280:5280"
      - "5443:5443"
    volumes:
      - ./app/:/usr/src/app/
      - ./ejabberd/conf/:/home/ejabberd/conf
      - ejabberd_data:/home/ejabberd/database
      - ejabberd_logs:/home/ejabberd/logs
      - ejabberd_uplo:/home/ejabberd/upload
      - ./ejabberd/modules/mod_offline_http_post/:/home/ejabberd/.ejabberd-modules/mod_offline_http_post
      # - ./ejabberd/modules/mod_offline_http_post:/home/ejabberd/.ejabberd-modules/mod_offline_http_post
      # - ./ejabberd/modules/mod_offline_http_post/ebin/*:/home/ejabberd/lib/ejabberd-21.07/ebin/
      - ./ejabberd/auth/auth.py:/home/ejabberd/conf/auth/auth.py

...

Update: I saw my mistake, sorry :)

badlop commented 2 years ago

Hi! I'm curious how you acomplished that. How did you make the python script work?

Carlososuna11 commented 2 years ago

I extended ejabberd's Dockerfile and added python to it. This works for me

FROM ejabberd/ecs:21.07

USER root

ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

RUN apk upgrade --update musl \
    && apk add \
    postgresql-dev gcc python3-dev musl-dev git

COPY ./requirements.txt .
RUN pip install -r requirements.txt

USER ejabberd
VOLUME ["$HOME/database","$HOME/conf","$HOME/logs","$HOME/upload"]
EXPOSE 1883 4369-4399 5222 5269 5280 5443

ENTRYPOINT ["/home/ejabberd/bin/ejabberdctl"]
CMD ["foreground"]

If you have a better solution, I would like to know