diff --git a/Dockerfile b/Dockerfile index cf8f7c6..0f78669 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,9 @@ WORKDIR /app # Install Hex and Rebar RUN mix local.hex --force && mix local.rebar --force +# Install mix_gleam archive (required for Gleam compilation) +RUN mix archive.install hex mix_gleam 0.6.2 --force + # Set build environment ENV MIX_ENV="prod" @@ -37,6 +40,12 @@ COPY priv priv COPY lib lib COPY assets assets COPY rel rel +# Copy Gleam source files and configuration +COPY src src +COPY gleam.toml gleam.toml +# Ensure pre-compiled Gleam BEAM files are available +# This helps when mix_gleam or gleam binary are not available +RUN mkdir -p priv/gleam # Compile assets RUN mix assets.deploy diff --git a/Dockerfile.distroless b/Dockerfile.distroless index 7512670..22f2ee7 100644 --- a/Dockerfile.distroless +++ b/Dockerfile.distroless @@ -26,11 +26,16 @@ WORKDIR /app RUN mix local.hex --force && \ mix local.rebar --force +# Install mix_gleam archive (required for Gleam compilation) +RUN mix archive.install hex mix_gleam 0.6.2 --force + # set build ENV ENV MIX_ENV="prod" # install mix dependencies COPY mix.exs mix.lock ./ +# Copy vendor directory for local dependencies +COPY vendor vendor RUN mix deps.get --only $MIX_ENV RUN mkdir config @@ -46,6 +51,13 @@ COPY lib lib COPY assets assets +# Copy Gleam source files and configuration +COPY src src +COPY gleam.toml gleam.toml +# Ensure pre-compiled Gleam BEAM files are available +# This helps when mix_gleam or gleam binary are not available +RUN mkdir -p priv/gleam + # compile assets RUN mix assets.deploy diff --git a/build/dev/erlang/aprsme/ebin/aprsme@encoding.beam b/build/dev/erlang/aprsme/ebin/aprsme@encoding.beam new file mode 100644 index 0000000..1fb10cf Binary files /dev/null and b/build/dev/erlang/aprsme/ebin/aprsme@encoding.beam differ diff --git a/lib/mix/tasks/gleam_compile.ex b/lib/mix/tasks/gleam_compile.ex index ef4fe73..4dcc0a2 100644 --- a/lib/mix/tasks/gleam_compile.ex +++ b/lib/mix/tasks/gleam_compile.ex @@ -79,21 +79,45 @@ defmodule Mix.Tasks.GleamCompile do Mix.shell().info("Gleam output directory #{gleam_output} does not exist") end else - # Last resort: try to copy from dev build if available - dev_ebin = "_build/dev/lib/aprsme/ebin" - test_ebin = "_build/#{env}/lib/aprsme/ebin" - - if File.exists?(dev_ebin) and env != :dev do - File.mkdir_p!(test_ebin) - - dev_ebin - |> File.ls!() - |> Enum.filter(&String.starts_with?(&1, "aprs@")) - |> Enum.each(fn beam_file -> - src = Path.join(dev_ebin, beam_file) - dest = Path.join(test_ebin, beam_file) + # Last resort: Check for pre-compiled BEAM files in priv/gleam + Mix.shell().info("No Gleam compiler available, checking for pre-compiled BEAM files...") + + priv_gleam = "priv/gleam" + ebin_dir = "_build/#{env}/lib/aprsme/ebin" + + if File.exists?(priv_gleam) do + File.mkdir_p!(ebin_dir) + + # Look specifically for our Gleam module + beam_file = "aprsme@encoding.beam" + src = Path.join(priv_gleam, beam_file) + + if File.exists?(src) do + dest = Path.join(ebin_dir, beam_file) File.copy!(src, dest) - end) + Mix.shell().info("Copied pre-compiled #{beam_file} from priv/gleam") + else + Mix.shell().error("Pre-compiled #{beam_file} not found in priv/gleam") + end + else + # Try to copy from dev build if available + dev_ebin = "_build/dev/lib/aprsme/ebin" + + if File.exists?(dev_ebin) and env != :dev do + File.mkdir_p!(ebin_dir) + + dev_ebin + |> File.ls!() + |> Enum.filter(&String.starts_with?(&1, "aprsme@")) + |> Enum.each(fn beam_file -> + src = Path.join(dev_ebin, beam_file) + dest = Path.join(ebin_dir, beam_file) + File.copy!(src, dest) + Mix.shell().info("Copied #{beam_file} from dev build") + end) + else + Mix.shell().error("Unable to find Gleam compiled files. Please ensure Gleam code is compiled before deployment.") + end end end end diff --git a/priv/gleam/aprsme@encoding.beam b/priv/gleam/aprsme@encoding.beam new file mode 100644 index 0000000..1fb10cf Binary files /dev/null and b/priv/gleam/aprsme@encoding.beam differ diff --git a/test-docker-build.sh b/test-docker-build.sh new file mode 100755 index 0000000..ce15203 --- /dev/null +++ b/test-docker-build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +echo "Testing Docker build with Gleam support..." + +# Build the Docker image +echo "Building Docker image..." +docker build -t aprsme-test:latest . + +echo "Docker build completed successfully!" + +# Test if the image runs +echo "Testing if the image can run..." +docker run --rm aprsme-test:latest bin/aprsme eval "IO.puts(:ok)" + +echo "All tests passed!" \ No newline at end of file