Deployment Phoenix 1.6 app with github action doesn't build app.js

When I use fly deploy on a phoenix 1.6 app locally there is no problem, but when deploying through a github action it fails to create/copy? the app.js file.

This is the Dockerfile used:

FROM hexpm/elixir:1.12.3-erlang-24.0.5-alpine-3.13.5 AS build

# install build dependencies
RUN apk add --no-cache build-base npm

# prepare build dir
WORKDIR /app

# extend hex timeout
ENV HEX_HTTP_TIMEOUT=20

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

# set build ENV as prod
ENV MIX_ENV=prod
ENV SECRET_KEY_BASE=nokey

# Copy over the mix.exs and mix.lock files to load the dependencies. If those
# files don't change, then we don't keep re-fetching and rebuilding the deps.
COPY mix.exs mix.lock ./
COPY config config

RUN mix deps.get --only prod && \
    mix deps.compile

# install npm dependencies
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error

COPY priv priv
COPY assets assets

# NOTE: If using TailwindCSS, it uses a special "purge" step and that requires
# the code in `lib` to see what is being used. Uncomment that here before
# running the npm deploy script if that's the case.
COPY lib lib

# build assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest

# copy source here if not using TailwindCSS
# COPY lib lib

# compile and build release
COPY rel rel
RUN mix do compile, release

###
### Second Stage - Setup the Runtime Environment
###

# prepare release docker image
FROM alpine:3.13.5 AS app
RUN apk add --no-cache libstdc++ openssl ncurses-libs

WORKDIR /app

RUN chown nobody:nobody /app

USER nobody:nobody

COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/myapp ./

ENV HOME=/app
ENV MIX_ENV=prod
ENV SECRET_KEY_BASE=nokey
ENV PORT=4000

CMD ["bin/myapp", "start"]

This is the github action (the default from the example in the docs):

name: Fly Deploy
on: push
env:
  FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

jobs:
  deploy:
    name: Deploy app
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: superfly/flyctl-actions@1.1
        with:
          args: "deploy"

Replace with this. Phoenix 1.6 used esbuild.

# build assets
# RUN npm run --prefix ./assets deploy
# RUN mix phx.digest
RUN mix assets.deploy

Is it possible the Github Action deploy worked but hung showing the output? We’re troubleshooting this issue right now, we shipped a new method for monitoring logs from flyctl and it seems a little flakey on Github actions.

In my original setup the deploy used to work, but produced the result I described. The last try yesterday though the Github Action indeed hung: “The job running on runner Hosted Agent has exceeded the maximum execution time of 360 minutes.”

Now when I try the suggested change RUN mix assets.deploy I get:

Generated myapp app

[272](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:272)** (RuntimeError) FLY_APP_NAME not available

[273](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:273) (stdlib 3.15.2) erl_eval.erl:685: :erl_eval.do_apply/6

[274](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:274) (stdlib 3.15.2) erl_eval.erl:446: :erl_eval.expr/5

[275](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:275) (stdlib 3.15.2) erl_eval.erl:123: :erl_eval.exprs/5

[276](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:276) (elixir 1.12.3) lib/code.ex:656: Code.eval_string_with_error_handling/3

[277](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:277) (elixir 1.12.3) lib/config.ex:258: Config.__eval__!/3

[278](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:278) (elixir 1.12.3) lib/config/reader.ex:86: Config.Reader.read!/2

[279](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:279)

[280](https://github.com/myname/myapp/runs/3863081721?check_suite_focus=true#step:4:280)Error error building: error rendering build status stream: The command '/bin/sh -c mix assets.deploy' returned a non-zero code: 1

I think the deploy monitor is hanging, but the deploy is happening successfully in the background. This is the bug we’ve been tracking today, we’ll hopefully have a workaround soon.

Alright, I’ll wait for that so I can test it. Thanks!

If I use RUN mix assets.deploy, I get the next error, both deploying locally and through the Github Action:

** (RuntimeError) FLY_APP_NAME not available
    (stdlib 3.15.2) erl_eval.erl:685: :erl_eval.do_apply/6
    (stdlib 3.15.2) erl_eval.erl:446: :erl_eval.expr/5
    (stdlib 3.15.2) erl_eval.erl:123: :erl_eval.exprs/5
    (elixir 1.12.3) lib/code.ex:656: Code.eval_string_with_error_handling/3
    (elixir 1.12.3) lib/config.ex:258: Config.__eval__!/3
    (elixir 1.12.3) lib/config/reader.ex:86: Config.Reader.read!/2

Error error building: error rendering build status stream: The command '/bin/sh -c mix assets.deploy' returned a non-zero code: 1

To fix that last error required updating esbuild to 0.3. Thanks @aswinmohanme !

1 Like