Can I `deploy.release_command` with Machines?

I’m trying Apps V2 Machines.

Then it doesn’t use a fly.toml. And I still need to migrate DB.
How do I do this with Machines?

I need to run bin/migrate then bin/server in the Docker CMD directive. So I tried copy-pasting.

#!/bin/sh
cd -P -- "$(dirname -- "$0")"
# bin/migrate part
exec ./feder eval Feder.Release.migrate
# bin/server part
PHX_SERVER=true exec ./feder start

It runs the migrate part but it wouldn’t start.
Is it supposed to work? or the code is wrong?

# Start a builder.
FROM elixir:alpine AS builder

# Set environment variable for production.
ENV MIX_ENV="prod"

# Get basic tools.
RUN apk add --no-cache build-base git

# Work in /app directory.
WORKDIR /app

# Get package managers.
RUN mix local.hex --force && \
    mix local.rebar --force

# Get dependencies.
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV

# Copy configurations.
RUN mkdir config

COPY config/config.exs config/$MIX_ENV.exs config/

# Compile the dependencies.
RUN mix deps.compile

# Copy the app and digest its assets.
COPY lib lib
COPY priv priv
COPY assets assets
RUN mix assets.deploy

# Compile the app.
RUN mix compile

# Setup runtime.
COPY config/runtime.exs config/
COPY rel rel
RUN mix release

# Start a runner.
FROM alpine:3.16 AS runner

# Set environment variable for production.
ENV MIX_ENV="prod"

# Enable IPv6 network for Fly.io.
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"

# Get basic tools.
RUN apk add --no-cache libstdc++ ncurses-libs openssl

# Work in /app directory.
WORKDIR /app

# Copy the app.
COPY --from=builder /app/_build/${MIX_ENV}/rel/feder ./

# Start a container.
CMD bin/migrate && bin/server

Release commands don’t work on machines yet. In Fly Apps, the release command runs in a throwaway VM.

To emulate this with machines, you’d need to create a new machine, run the command, then destroy it.

You can also use fly ssh -C "<cmd>" to run one off commands after you’ve updated a machine.

1 Like

Thanks for the explanation!

As for my problem, I simply did CMD bin/migrate && bin/server