ortuman / jackal

💬 Instant messaging server for the Extensible Messaging and Presence Protocol (XMPP).
Apache License 2.0
1.44k stars 128 forks source link

Docker-compose doesn't work #274

Open mirkoperillo opened 1 year ago

mirkoperillo commented 1 year ago

docker-compose doesn't work out of the box.

Running the command sudo docker-compose -f dockerfiles/docker-compose.yml up the jackal service fails to start with this log message

jackal_1  | exec ./wait-for-it.sh: exec format error
mirkoperillo commented 1 year ago

I have tried to understand better the problem, more details about:

command:
     - echo
     - "Hi Jackal!"

I've got the same error exec format error

The problem seems specific of the jackal docker image. I've tried to run wait-for-it using directly the debian:stable-slim image (the one used by jackal image) and wait-for-it script works correctly

jackal:
    image: debian:stable-slim
    depends_on:
      - etcd
      - pgsql
    volumes:
      - ../scripts:/scripts
    command:
      - /scripts/wait-for-it.sh
      - pgsql:5432
      - --
      - echo
      - "Hi Jackal!"

Output

jackal_1  | wait-for-it.sh: waiting 15 seconds for pgsql:5432
jackal_1  | wait-for-it.sh: pgsql:5432 is available after 0 seconds
jackal_1  | Hi Jackal!
dockerfiles_jackal_1 exited with code 0
mirkoperillo commented 1 year ago

More tests about the problem.

I think I have isolated the problem, it is something about the image platform used by docker-compose.

To test this I have created a Dockerfile.local without --platform=$BUILDPLATFORM and GOARCH=$TARGETARCH part, so something like this

FROM golang:1.19.1-bullseye as stage

ADD . /src
WORKDIR /src

RUN CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags "-s -w" "github.com/ortuman/jackal/cmd/jackal"
RUN CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags "-s -w" "github.com/ortuman/jackal/cmd/jackalctl"
RUN chmod +x jackal jackalctl

FROM debian:stable-slim

RUN apt-get update && apt-get install -y ca-certificates
RUN update-ca-certificates

WORKDIR /jackal

COPY --from=stage /src/jackal /jackal
COPY --from=stage /src/jackalctl /jackal

EXPOSE 5222

ENV PATH $PATH:/jackal

CMD ["./jackal"]

and have used this Dockerfile.local directly into docker-compose, so with a jackal service definition like this

 jackal:
    build:
      context: ..
      dockerfile: dockerfiles/Dockerfile.local
    ports:
      - 5222:5222
      - 15280:15280
    environment:
      - JACKAL_LOG_STANZAS=on
    depends_on:
      - etcd
      - pgsql
    working_dir: /jackal
    volumes:
      - ../scripts/wait-for-it.sh:/jackal/wait-for-it.sh
      - ../config/docker-compose.config.yaml:/jackal/config.yaml
    command:
      - ./wait-for-it.sh
      - pgsql:5432
      - --
      - ./wait-for-it.sh
      - etcd:2379
      - --
      - ./jackal

then I have executed the command sudo docker-compose -f dockerfiles/docker-compose.yml up --force-recreate

and wait-for-it.sh script works as expected

The output:

jackal_1  | wait-for-it.sh: waiting 15 seconds for pgsql:5432
jackal_1  | wait-for-it.sh: pgsql:5432 is available after 0 seconds
jackal_1  | wait-for-it.sh: waiting 15 seconds for etcd:2379
jackal_1  | wait-for-it.sh: etcd:2379 is available after 0 seconds
jackal_1  | level=info ts=2022-10-28T16:55:13.685507956Z caller=jackal.go:190 msg="jackal is starting...
...
...