Skip to content

Latest commit

 

History

History

nx-fly-deployment-action


codeware sthlm logo

Nx Fly Deployment Action

GitHub action that brings automatic Fly.io deployments to your Nx workspace.

@cdwr/nx-fly-deployment-action npm   MIT

Description

This action will manage deployments to Fly.io of your Nx workspace applications.

Required Application Setup

To have the choice of deciding which apps to deploy, you need to setup those apps with two opnionated files.

  1. The obvious file for Fly deployments is fly.toml, which is the blueprint for the deployment.
    This file location is defined in the github.json file.

  2. The other file is github.json, where the deployment can be customized for the application. This file can be saved anywhere in the application, but it's recommended to be in the root path.
    The JSON schema file can be found here.

When any of these files are missing, or misplaced, the application will be skipped from deployment.

Tip

The github.json allows for disabling the deployment for the application. This is useful for skipping deployments for applications that are not ready for deployment for any reason.

Usage

Important

Using the action is currently limited to cloning this repository since the package isn't deployed according to action best practices.

We have a monorepo and are considering other options to make the action available to other repositories.

- uses: actions/checkout@v4
  with:
    fetch-depth: 0

# Install dependencies and tools...
# Build 'fly-deployment-action' package...

# Fly CLI must be installed
- name: Install Fly CLI
  uses: superfly/flyctl-actions/setup-flyctl@master
  with:
    version: 0.3.45

# Let Nx analyze which projects are affected and hence will be deployed
- name: Analyze affected projects to deploy
  uses: nrwl/nx-set-shas@v4
  with:
    set-environment-variables-for-job: true

- name: Run Nx Fly Deployment
  uses: ./packages/nx-fly-deployment-action
  with:
    fly-api-token: ${{ secrets.FLY_API_TOKEN }}
    token: ${{ secrets.GITHUB_TOKEN }}

Determine environment

The environment to deploy to is determined by the event type and branch name.

Pull requests are deployed to a preview environment.

Push events on the main branch are deployed to the production environment.

Tip

The environment is provided in environment variable DEPLOY_ENV for the deployed applications, together with some opinionated values:

  • APP_NAME - The name of the app
  • PR_NUMBER - The pull request number (otherwise empty)

Inputs

See action.yaml for descriptions of the inputs.

Additional input details

postgres-preview

When a Fly Postgres cluser has been created, you can attach the application to a postgres database automatically on deployment to the preview environment.

Provide the name of the postgres application. Fly will provide DATABASE_URL as a secret to the application to be able to connect to the database.

Before the application gets destroyed, the Postgres cluster will detach the application from the database.

Read more about attach or detach a Fly app.

secrets

The secrets are passed to the deployed applications as Fly secrets. All secrets are passed to all applications.

Provide the secrets as multiline key/value strings.

- uses: ./packages/nx-fly-deployment-action
  with:
    secrets: |
      SECRET_KEY1=secret-value1
      SECRET_KEY2=secret-value2

Note

The same pattern also applies to env input.

Outputs

See action.yaml for descriptions of the outputs.