Deploying an app with a private dependency on GitHub

Hi everyone! I’m starting out and I need a bit of help with my deployment.

I want to deploy a Phoenix app that has a dependency hosted on private GitHub repo. I followed the getting started guide but, as expected, it fails when attempting to pull the dependency.

Are there any guides that show how I can set this up? Is there an easier way to do this?

# Example mix.exs 
{:private_dep, git: ""},

PS: I can’t use mix release since I’m on an M1 machine.

So your best bet for this would be to just vendor the dependency in your package. A git submodule would work for this, or you could just copy it to vendor_deps/ and update the package reference.
For instance:

# git submodule add vendor_deps/my_private_lib
# git submodule update — init — recursive
def deps do
    {:my_private_lib, path: "./vendor_deps/my_private_lib"},

Thanks for your help. For some reason, mix won’t pick up on the submodule when deploying. From the deploy log:

#18 6.658 ** (Mix) Cannot compile dependency :my_dep because it isn't available, please ensure the dependency is at "lib/vendor/my_dep"

I tried at the root level and inside of lib. It works on my local machine, but it doesn’t work when deploying.

Maybe mix has some configuration that needs to be set.

Can you check your .dockerignore file? Since it is working locally, it could be that the files aren’t getting sent to the build properly.

Here are the contents. There is no reference to the submodule there.

# there are valid reasons to keep the .git, namely so that you can get the
# current commit hash

# Mix artifacts

# Generate on crash by the VM

# Static artifacts

I’m assuming that vendor/dep isn’t getting pushed to the server when I run fly launch. Why would that be the case?

can you open your dockerfile and make sure that the vendor stuff is being added before the build?

Thanks zee. I’m not familiar with docker, to be honest, so I’m not sure what I should be looking for. Here are the contents:

# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
# Alpine to avoid DNS resolution issues in production.
# This file is based on these images:
#   - - for the build image
#   - - for the release image
#   - - resource for finding needed packages
#   - Ex: hexpm/elixir:1.13.3-erlang-24.2.1-debian-bullseye-20210902-slim
ARG BUILDER_IMAGE="hexpm/elixir:1.13.3-erlang-24.2.1-debian-bullseye-20210902-slim"
ARG RUNNER_IMAGE="debian:bullseye-20210902-slim"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

# note: if your project uses a tool like,
# which customizes asset compilation based on what it finds in
# your Elixir templates, you will need to move the asset compilation
# step down so that `lib` is available.
COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
COPY lib lib

RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen


WORKDIR "/app"
RUN chown nobody /app

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/prod/rel/my_app ./

USER nobody

CMD ["/app/bin/server"]

# Appended by flyctl
ENV ERL_AFLAGS "-proto_dist inet6_tcp"

FYI: I’m following this guide and I can confirm it works with a barebones Phoenix app.

Before RUN mix deps.compile try:

COPY vendor vendor
1 Like

That did the trick. Thank you both for your help.

1 Like