Elixir Getting Started Guide

I currently think it’s related to the Windows environment. Unfortunately I don’t have an easy way to test that right now. I’m away from my home base and I don’t have a Windows VM available. Sorry for the difficulty.

The thing I found odd about the error was that it was trying to pull in the _build folder. Try adding that to the .dockerignore file. Like this: “_build/”

@Mark Just borrowed a colleague’s Mac for the morning and confirmed that the deploy worked perfectly so there’s something going on with Windows (and a different issue with WSL).

Adding _build/ to the .dockerignore didn’t change anything; next idea to try?

Got a working deploy! Inspired by the Mac approach working, I spun up a plain Docker Linux container, copied my files in (private repo so easier than cloning for a proof of concept) and went through the deployment process.
Definitely would be easier to not have to go through that process very often but good to confirm again that Windows is the problem.

Thanks for the feedback and follow-up! We’ll look into it some more.

@Mark Any update on deploying from Windows? At the moment I’m on Heroku because it’s just so much easier

@samw we’re working on automated full stack tests from Windows, we’ll make sure we get this one in there first thing.

1 Like

For Phoenix 1.6+ the example Dockerfile needs an update to exclude installation of npm dependencies and npm build assets. Else the build will fail.

It would be great if some examples on how to properly include npm dependencies for Phoenix 1.6+ would be givin.

Ah! Good catch! Until I can get that updated, here is a resource that I hope helps! It’s a demo project by Jose Valim showing how to setup Phoenix with esbuild:

https://github.com/josevalim/phx_esbuild_demo/commit/0546034f26ac5d58d12867e5843037ce1b2d4dd1

Is there any guide on how to run multi-region Postgres with a Phoenix app ? I have been looking for different solutions but nothing seems to work properly.

@aswinmohanme I’ve been working on that actually! I’m going to be presenting at ElixirConf2021 showing a few ways to go about it. I don’t have anything ready to publish on the topic at the moment, do you have any specific questions I can try and help with?

3 Likes

Great! I’ll stick with single region deployment in the meantime and concentrate on getting some users, you don’t need multi-region Postgres deployments if no one is using your app :sweat_smile:.

1 Like

Thanks for the awesome guide @Mark ! This kind of content has been crucial for me to jump on the Fly train!

The migration doesn’t work for me. I’m not sure what I do wrong, even without anything to do in the migration the deploy fails:
First I make sure there are no migrations to run:

$ fly ssh console
Connecting to xxx-xxx-2877.internal... complete
/ # /app/bin/xxx eval XXX.Release.migrate
14:34:39.171 [info] Migrations already up
/ # echo "$?"
0
/ #

Notice the exit code is 0 here.

Then I do a fly deploy without any new migrations to run:

$ fly deploy
Deploying xxx-xxx-2877
==> Validating app configuration
                                                                                                                                                                                                                 
...

==> Creating release
Release v31 created
Release command detected: this new release will not be available until the command succeeds.

You can detach the terminal anytime without stopping the deployment
==> Release command
Command: /app/bin/xxx eval Creators.Release.migrate
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Setting up volume 'xxx'

Error Release command failed, deployment aborted

This is my fly.toml:

[deploy]
  release_command = "/app/bin/xxx eval XXX.Release.migrate"

I thought it was maybe the exit code of the migration command, but as seen in the manual migration example above, it’s 0.

Is it working for someone else?

I’m able to get the sample app working with migrations, both first time and repeated deploys (with no migrations to run) in MAA, but there are complaints of the release command failing Error Release command failed, deployment aborted - #12 by sudhir.j (in GRU) as well.

There’s a DNS error in the logs reported there, might be the issue.

1 Like

Awesome! I’m glad!

As for the problem you reported, yes, it’s working for me. Is this still a problem for you or was it lik @sudhir.j mentioned might be the case and it was a temporary regional issue?

The conference presentation is up! You can find it here: https://www.youtube.com/watch?v=IqnZnFpxLjI&list=PLqj39LCvnOWZna91xJ_i44g3rx4Brbpnv&index=29

I’m making some changes to the fly_rpc and fly_postgres libraries. I expect that will be ready tomorrow (2021-10-26).

3 Likes

Just tried again: it works now in the fra region!

2 Likes

The Elixir Getting Started Guide was updated! @jsierles helped bring it up-to-date. It was updated for Phoenix 1.6, it includes a new Dockerfile, the linked hello_elixir github repo was updated too.

Thanks all for the feedback that helped make this better!

2 Likes

Hi,

I have been following the guide and have an issue. I am using esbuiild and also npm. I am using npm to run a deploy script to minify my css and tailwindcss.

In the `package.json’ I have


"deploy": "NODE_ENV=production tailwindcss --postcss --minify --input=css/app.css --output=../priv/static/assets/app.css"

In my mix.exs I have

"assets.deploy": [
        "cmd --cd assets npm run deploy",
        "esbuild default --minify",
        "phx.digest"
      ]

When I run fly deploy I get the error

sh: 1: npm: not found
** (exit) 127
    (mix 1.12.3) lib/mix/tasks/cmd.ex:64: Mix.Tasks.Cmd.run/1
    (mix 1.12.3) lib/mix/task.ex:394: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.12.3) lib/mix/task.ex:452: Mix.Task.run_alias/5
    (mix 1.12.3) lib/mix/cli.ex:84: Mix.CLI.run_task/2

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

Initially I thought I could add nodejs and nodejs-npm to the Dockerfile

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

I re-ran fly launch but get the same error. Does anyone know how I can change the config to work?

UPDATE: I had the install of node and npm on the RUNNER image instead of the builder image. so now I have updated theDockerfile

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

This now works but does not build the minified css (i.e. no tailwindcss on the running application).

I will keep debugging but if anyone has any guidance it will be appreciated.

Thanks,

Andrew

UPDATE: See below

I have worked it out (Should have read the Dockerfile comments a bit earlier). The first change I had to make was to install npm and nodejs packages on the BUILDER container:

Dockerfile

...

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

...

The next change was based on the comments that I missed the first time:

# 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.

This meant I needed to change the order so the Tailwind purge would work.

Dockerfile

COPY lib lib

COPY priv priv

COPY assets assets

RUN mix assets.deploy

RUN mix compile

This was the order that I finally settled on. The last piece of the puzzle was my final error which was that TailwindCSS was unavailable. so I added in the following line before RUN mix assets.deploy

...


RUN cd assets && npm install

RUN mix assets.deploy

...

With these changes deployment worked.

Andrew

6 Likes

Thanks for sharing your troubleshooting and solution! I’m sure it will be helpful to others as well. :smile: