Skip to content

Latest commit

 

History

History
136 lines (87 loc) · 4.21 KB

deployment.md

File metadata and controls

136 lines (87 loc) · 4.21 KB

Deployment

Without SSR With SSR

Without SSR

The following steps are needed to deploy to Fly.io. This guide assumes that you'll be using Fly Postgres as your database. Further guidance on how to deploy to Fly.io can be found here.

  1. Generate a Dockerfile:
mix phx.gen.release --docker
  1. Modify the generated Dockerfile to install curl, which is used to install nodejs (version 19 or greater), and also add a step to install our npm dependencies:
# ./Dockerfile

...

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

+ # install nodejs for build stage
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && apt-get install -y nodejs

...

COPY assets assets

+ # install all npm packages in assets directory
+ RUN cd /app/assets && npm install

Note: nodejs is installed in the build stage. This is because we need nodejs to install our npm dependencies.

  1. Launch your app with the Fly.io CLI:
fly launch
  1. When prompted to tweak settings, choose y:
? Do you want to tweak these settings before proceeding? (y/N) y

This will launch a new window where you can tweak your launch settings. In the database section, choose Fly Postgres and enter a name for your database. You may also want to change your database to the development configuration to avoid extra costs. You can leave the rest of the settings as-is unless you want to change them.

Deployment will continue once you hit confirm.

  1. Once the deployment completes, run the following command to see your deployed app!
fly apps open

With SSR

See the SSR guide first to setup your project.

The following steps are needed to deploy to Fly.io. This guide assumes that you'll be using Fly Postgres as your database. Further guidance on how to deploy to Fly.io can be found here.

  1. Generate a Dockerfile:
mix phx.gen.release --docker
  1. Modify the generated Dockerfile to install curl, which is used to install nodejs (version 19 or greater), and also add a step to install our npm dependencies:
# ./Dockerfile

...

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

+ # install nodejs for build stage
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && apt-get install -y nodejs

...

COPY assets assets

+ # install all npm packages in assets directory
+ RUN cd /app/assets && npm install

...

# 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 ca-certificates \
+  apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates curl \
   && apt-get clean && rm -f /var/lib/apt/lists/*_*

+ # install nodejs for production environment
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && apt-get install -y nodejs

...

Note: nodejs is installed BOTH in the build stage and in the final image. This is because we need nodejs to install our npm dependencies and also need it when running our app.

  1. Launch your app with the Fly.io CLI:
fly launch
  1. When prompted to tweak settings, choose y:
? Do you want to tweak these settings before proceeding? (y/N) y

This will launch a new window where you can tweak your launch settings. In the database section, choose Fly Postgres and enter a name for your database. You may also want to change your database to the development configuration to avoid extra costs. You can leave the rest of the settings as-is unless you want to change them.

Deployment will continue once you hit confirm.

  1. Once the deployment completes, run the following command to see your deployed app!
fly apps open