Deploying an app with a private dependency on GitHub

Hi everyone! I’m starting out Fly.io 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: "git@github.com:my_user_username/private_dep.git"},

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

Hi!
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 git@github.com:myorg/my_private_lib.git vendor_deps/my_private_lib
# git submodule update — init — recursive
def deps do
  [
    ...
    {:my_private_lib, path: "./vendor_deps/my_private_lib"},
  ]
end

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.

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

# Mix artifacts
_build
deps
*.ez
releases

# Generate on crash by the VM
erl_crash.dump

# Static artifacts
node_modules

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.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
#
# This file is based on these images:
#
#   - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
#   - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
#   - https://pkgs.org/ - 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
WORKDIR /app

# 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 https://purgecss.com/,
# 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
FROM ${RUNNER_IMAGE}

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

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

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 ECTO_IPV6 true
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