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:
parent
3e6d73b553
commit
8cc2cf0a5e
6 changed files with 75 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
BIN
build/dev/erlang/aprsme/ebin/aprsme@encoding.beam
Normal file
BIN
build/dev/erlang/aprsme/ebin/aprsme@encoding.beam
Normal file
Binary file not shown.
|
|
@ -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
|
||||
|
|
|
|||
BIN
priv/gleam/aprsme@encoding.beam
Normal file
BIN
priv/gleam/aprsme@encoding.beam
Normal file
Binary file not shown.
16
test-docker-build.sh
Executable file
16
test-docker-build.sh
Executable 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!"
|
||||
Loading…
Add table
Reference in a new issue