fix parser version check

This commit is contained in:
Graham McIntire 2025-07-07 14:54:52 -05:00
parent ba80e414d8
commit 9dd7ca8f56
No known key found for this signature in database
2 changed files with 12 additions and 46 deletions

View file

@ -24,14 +24,11 @@ RUN mix local.hex --force && mix local.rebar --force
# Set build environment
ENV MIX_ENV="prod"
# Capture APRS parser git hash from GitHub API during build
RUN curl -s https://api.github.com/repos/aprsme/aprs/commits/main | grep -o '"sha":"[^\"]*"' | head -1 | cut -d'"' -f4 | cut -c1-7 > /tmp/parser_hash.txt
# Install dependencies
COPY mix.exs mix.lock ./
# Extract the hash from mix.lock and write to a file
RUN grep -oE 'aprs.*ref,\\s*"([a-f0-9]+)"' mix.lock | grep -oE '[a-f0-9]{7,}' | head -1 > /tmp/aprs_hash.txt
RUN mix deps.get --only $MIX_ENV
# Extract the APRS parser hash from the fetched GitHub dependency
RUN cd deps/aprs && git rev-parse HEAD | cut -c1-7 > /tmp/aprs_hash.txt
RUN mix deps.compile
# Copy application code
@ -66,16 +63,11 @@ RUN mkdir -p /app
# Set deployment timestamp to current time during runtime container build
RUN date -u +"%Y-%m-%dT%H:%M:%SZ" > /app/deployed_at.txt
# Copy parser hash from builder stage
COPY --from=builder /tmp/parser_hash.txt /app/parser_hash.txt
# Set parser git hash environment variable for runtime
RUN PARSER_HASH=$(cat /app/parser_hash.txt) && echo "PARSER_GIT_HASH=$PARSER_HASH" >> /etc/environment
# In the runtime stage, after WORKDIR /app
# Copy APRS parser hash from builder stage
COPY --from=builder /tmp/aprs_hash.txt /app/aprs_hash.txt
RUN echo "APRS_PARSER_HASH=$(cat /app/aprs_hash.txt)" >> /etc/environment
ENV APRS_PARSER_HASH="unknown"
# Set APRS parser hash environment variable for runtime
RUN APRS_HASH=$(cat /app/aprs_hash.txt) && echo "APRS_PARSER_HASH=$APRS_HASH" >> /etc/environment
# Copy release from builder
COPY --from=builder --chown=nobody:root /app/release ./

View file

@ -3,44 +3,18 @@ defmodule Aprsme.DependencyInfo do
Provides information about dependencies, particularly for production builds.
"""
@aprs_hash (
mix_lock_path = Path.join([File.cwd!(), "mix.lock"])
if File.exists?(mix_lock_path) do
case File.read(mix_lock_path) do
{:ok, content} ->
case Regex.run(
~r/aprs:\s*\{:git,\s*"https:\/\/github\.com\/aprsme\/aprs",\s*\{:ref,\s*"([a-f0-9]+)"\}/,
content
) do
[_, hash] ->
String.slice(hash, 0, 7)
_ ->
case Regex.run(
~r/aprs:\s*\{:git,\s*"https:\/\/github\.com\/aprsme\/aprs",\s*"([a-f0-9]+)"\}/,
content
) do
[_, hash] -> String.slice(hash, 0, 7)
_ -> "unknown"
end
end
_ ->
"unknown"
end
else
"unknown"
end
)
@doc """
Gets the SHA1 hash of the aprs library currently being used.
In development: reads from vendor/aprs directory
In production: uses the hash captured at compile time
"""
def get_aprs_library_sha do
System.get_env("APRS_PARSER_HASH") || "unknown"
# First try environment variable (production)
case System.get_env("APRS_PARSER_HASH") do
nil -> get_aprs_sha_from_vendor()
"unknown" -> get_aprs_sha_from_vendor()
hash -> hash
end
end
defp get_aprs_sha_from_vendor do