Fix Docker deployment with Gleam integration

- Update gleam_compile task to handle missing mix_gleam/gleam binary
- Add fallback to use pre-compiled BEAM files from priv/gleam
- Include pre-compiled aprsme@encoding.beam for Docker builds
- Update both Dockerfiles to ensure priv/gleam directory exists
- Fix module name filter from "aprs@" to "aprsme@" in fallback logic

This ensures Docker builds work without requiring gleam or mix_gleam
to be installed in the production container.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-18 14:06:36 -05:00
parent 3e6d73b553
commit 8cc2cf0a5e
No known key found for this signature in database
6 changed files with 75 additions and 14 deletions

View file

@ -21,6 +21,9 @@ WORKDIR /app
# Install Hex and Rebar # Install Hex and Rebar
RUN mix local.hex --force && mix local.rebar --force 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 # Set build environment
ENV MIX_ENV="prod" ENV MIX_ENV="prod"
@ -37,6 +40,12 @@ COPY priv priv
COPY lib lib COPY lib lib
COPY assets assets COPY assets assets
COPY rel rel 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 # Compile assets
RUN mix assets.deploy RUN mix assets.deploy

View file

@ -26,11 +26,16 @@ WORKDIR /app
RUN mix local.hex --force && \ RUN mix local.hex --force && \
mix local.rebar --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 # set build ENV
ENV MIX_ENV="prod" ENV MIX_ENV="prod"
# install mix dependencies # install mix dependencies
COPY mix.exs mix.lock ./ COPY mix.exs mix.lock ./
# Copy vendor directory for local dependencies
COPY vendor vendor
RUN mix deps.get --only $MIX_ENV RUN mix deps.get --only $MIX_ENV
RUN mkdir config RUN mkdir config
@ -46,6 +51,13 @@ COPY lib lib
COPY assets assets 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 # compile assets
RUN mix assets.deploy RUN mix assets.deploy

Binary file not shown.

View file

@ -79,21 +79,45 @@ defmodule Mix.Tasks.GleamCompile do
Mix.shell().info("Gleam output directory #{gleam_output} does not exist") Mix.shell().info("Gleam output directory #{gleam_output} does not exist")
end end
else else
# Last resort: try to copy from dev build if available # Last resort: Check for pre-compiled BEAM files in priv/gleam
dev_ebin = "_build/dev/lib/aprsme/ebin" Mix.shell().info("No Gleam compiler available, checking for pre-compiled BEAM files...")
test_ebin = "_build/#{env}/lib/aprsme/ebin"
if File.exists?(dev_ebin) and env != :dev do priv_gleam = "priv/gleam"
File.mkdir_p!(test_ebin) ebin_dir = "_build/#{env}/lib/aprsme/ebin"
dev_ebin if File.exists?(priv_gleam) do
|> File.ls!() File.mkdir_p!(ebin_dir)
|> Enum.filter(&String.starts_with?(&1, "aprs@"))
|> Enum.each(fn beam_file -> # Look specifically for our Gleam module
src = Path.join(dev_ebin, beam_file) beam_file = "aprsme@encoding.beam"
dest = Path.join(test_ebin, beam_file) src = Path.join(priv_gleam, beam_file)
if File.exists?(src) do
dest = Path.join(ebin_dir, beam_file)
File.copy!(src, dest) 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 end
end end

Binary file not shown.

16
test-docker-build.sh Executable file
View file

@ -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!"