martins

martins

Hi,

I’m able to run my test from my terminal, but if I’m not able to run the tests from within a container.

I get this error when I run docker compose up:

test-1  | Compiling 50 files (.ex)
test-1  | Generated easy_solutions app
test-1  | ** (exit) exited in: GenServer.call(ExUnit.Server, :modules_loaded, :infinity)
test-1  |     ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
test-1  |     (elixir 1.14.0) lib/gen_server.ex:1027: GenServer.call/3
test-1  |     (ex_unit 1.14.0) lib/ex_unit.ex:376: ExUnit.run/1
test-1  |     (mix 1.14.0) lib/mix/compilers/test.ex:42: Mix.Compilers.Test.require_and_run/4
test-1  |     (mix 1.14.0) lib/mix/tasks/test.ex:543: Mix.Tasks.Test.do_run/3
test-1  |     (mix 1.14.0) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
test-1  |     (mix 1.14.0) lib/mix/task.ex:475: Mix.Task.run_alias/6
test-1  |     (mix 1.14.0) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I have also tried to replace entrypoint with sleep, so that I can do a docker compose exec test /bin/bash into the container. I can confirm that mix compile works, and I get the same error when I run mix test.

Any suggestions to how I can debug this further?

test.Dockerfile

FROM ubuntu:24.04 

ENV MIX_ENV=test
ENV DOCKER_BUILDKIT=1


USER root
RUN apt update
RUN apt install -y erlang-dev elixir erlang-xmerl  
RUN apt install -y curl git 

RUN useradd -ms /bin/bash appuser
RUN mkdir /app
RUN chown -R appuser /app

USER appuser

COPY . /app
WORKDIR /app


RUN mix local.hex --force
RUN mix local.rebar --force

# install dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get

# compile dependencies
COPY config ./config/


ENTRYPOINT ["mix", "test"]

docker-compose.yaml

version: "3"

services:
  test:
    environment:
      DATABASE_PATH: priv/databases/test.db
      SECRET_KEY_BASE: "l7sdfjkhj"
  

    build:
      context: .
      dockerfile:
        test.Dockerfile
    volumes:
      - ./test_result:/app/test_result


Showing Posts 1 to 4

jarlah

jarlah

I have found this to work previously

ARG ELIXIR_VERSION=1.14.5
ARG OTP_VERSION=26.0.2
ARG DEBIAN_VERSION=bullseye-20231009-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# .... SNIP ...

FROM ${RUNNER_IMAGE}

# .... SNIP ...

martins

martins OP

Thanks for the suggestion, @jarlah!
Following your advice, I used the Dockerfile generated by mix phx.gen.release --docker.
I added this the the bottom of the Dockerfile:

FROM builder as test
WORKDIR "/app"

ENV MIX_ENV="test"
COPY . .

# install mix dependencies
RUN mix deps.get --only $MIX_ENV
CMD ["mix", "test"]

My docker-compose.yaml looks like this:


version: "3"

services:
  test:
    environment:
      DATABASE_PATH: priv/databases/test.db
      SECRET_KEY_BASE: "l7sdfjkhj"

    build:
      context: .
      dockerfile: Dockerfile

Now I can run my tests in a CI/CD pipeline by simply executing
docker compose up test

D4no0

D4no0

Is there a reason you are not using a pre-built docker image for that?

You can find them on dockerhub and hex.

They have erlang and elixir pre-installed and you can select the specific version you need.

martins

martins OP

Hi @D4no0,

I wasn’t aware of those images.
Thanks for telling me!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews