Migrating a Phoenix app from Heroku to Render

Hi!

I’m migrating a big Phoenix project from Heroku to Render and I’d like to know if someone has done it before.

We’ll use a custom Dockerfile because we need to install a bunch of dependencies. Do you know of any good Docker image that I can use?

I came across this Medium tutorial (paywall) but it uses Docker Compose which we won’t need.

Also I’m evaluating potential unknowns. What gotchas should I be aware of?

Thank you.

I’ve ran an app on Render for some time, but I’ve moved to Digital Ocean’s App Platform and I’m happy with it so far. It has the same features as Render, but the console and logs feel snappier. You get some basic charts (RAM, CPU usage) out of the box for free. Other than that both do Docker + ENV and they handle HTTPS for you, which is really nice.

The advantage of Docker is that once you’re happy with your Dockerfile, you can run the same image on any platform (Heroku, Render, Digital Ocean).

Either way, here’s what Phoenix guides suggest for the Dockerfile. And here’s mine:

FROM hexpm/elixir:1.11.3-erlang-23.3.2-alpine-3.13.3 AS builder

# Install build tools.
RUN apk add --no-cache build-base nodejs=14.16.1-r1 npm=14.16.1-r1

# Prepare build directory.
WORKDIR /app

# Copy the sources.
COPY . ./

# Install Hex and Rebar.
RUN mix local.hex --force && \
    mix local.rebar --force

# Build in prod env.
ENV MIX_ENV=prod

# Get and build dependencies.
RUN mix deps.get && \
    mix deps.compile

# Build assets.
RUN cd assets && \
    npm install && \
    npm run build

# Prepare assets.
RUN mix phx.digest

# Assemble the release.
RUN mix release

# Prepare the release image.
FROM alpine:3.11.3 AS release

# Install dependencies:
# - Erlang requires ncurses-libs
# - the :ssl module dynamically links to openssl
RUN apk add --no-cache openssl ncurses-libs

WORKDIR /app
COPY --from=builder --chown=nobody:nobody /app/_build/prod/rel/app ./

# Use the user with minimal permissions.
RUN chown -R nobody:nobody /app
USER nobody:nobody
ENV HOME=/app

CMD ["sh", "-c", "bin/app eval MyApp.Release.migrate && bin/app start"]

One thing I’m doing differently is that I control the files I copy to the builder image with .dockerignore.

1 Like

Thank you for your answer :slight_smile:

I agree that Render logs and charts aren’t perfect but with (paid?) addons you can have them.

Thanks I missed this part of the documentation.

We’ll stick with Render for now and I’ll update this thread if I run in any issue.