• Stars
    star
    111
  • Rank 303,304 (Top 7 %)
  • Language
    JavaScript
  • Created about 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dockerfile generator for Node.js

Overview

Provides a Node.js generator to produce Dockerfiles and related files. It is intended to support any framework that lists its dependencies, includes a start script in package.json, and optionally includes a build script.

See test for a list of frameworks and examples of Dockerfiles produced based on the associated package.json and lock files.

See blog post for more information.

Usage

To run once:

npx --yes @flydotio/dockerfile@latest

Or install it with your favorite package manager:

bun add -d @flydotio/dockerfile
npm install @flydotio/dockerfile --save-dev
pnpm add -D @flydotio/dockerfile
yarn add @flydotio/dockerfile --dev

Once installed, you can run and re-run using npx dockerfile for Node.js applications or bunx dockerfile for Bun applications.

Options are saved between runs into package.json. To invert a boolean options, add or remove a no- prefix from the option name.

Options:

  • --alpine - use alpine as base image
  • --build=CMD - command to be used to build your application.
  • --cache - use build caching to speed up builds
  • --cmd=CMD - CMD to use in Dockerfile
  • --defer-build - may be needed when your build step requires access to secrets that are not available at image build time. Results in larger images and slower deployments.
  • --dev - include devDependencies in the production image.
  • --distroless - use distroless base image to reduce image size
  • --entrypoint - ENTRYPOINT to use in Dockerfile
  • --ignore-scripts - do not execute any scripts defined in the project package.json and its dependencies.
  • --force - overwrite existing files
  • --legacy-peer-deps - ignore peer dependencies.
  • --litefs - configure and enable litefs.
  • --nginxRoot=DIR - serve static files from given directory via nginx.
  • --no-link - don't add --link to COPY statements. Some tools (like at the moment, buildah) don't yet support this feature.
  • --port=n - expose port (default may vary based on framework, but otherwise is 3000)
  • --swap=n - allocate swap space. See falloc options for suffixes
  • --windows - make Dockerfile work for Windows users that may have set git config --global core.autocrlf true.

Add a package/environment variable/build argument:

Not all of your needs can be determined by scanning your application. For example, I like to add vim and procps.

  • --add package... - add one or more debian packages
  • --arg=name:value - add a build argument
  • --env=name:value - add an environment variable
  • --remove package... - remove package from "to be added" list

Args and environment variables can be tailored to a specific build phase by adding -base, -build, or -deploy after the flag name (e.g --add-build freetds-dev --add-deploy freetds-bin). If no such suffix is found, the default for arg is -base, and the default for env is -deploy. Removal of an arg or environment variable is done by leaving the value blank (e.g --env-build=PORT:).

Build secrets

Techniques such as static site generation using databases may require access to secrets at build time. To enable this you will need to mount the secret:

  • --mount-secret=name - add name to the list of secrets to mount when running the build script
  • --unmount-secret-name - remove name from the list of secrets to mount when running the build script

See Secret to expose to the build for examples on how to pass secrets to a docker build.

Advanced customization

There may be times where feature detection plus flags just aren't enough. As an example, you may wish to configure and run multiple processes.

  • --instructions=path - a dockerfile fragment to be inserted into the final document.

Like with environment variables, packages, and build args, --instructions can be tailored to a specific build phase by adding -base, -build, or -deploy after the flag name, with the default being -deploy.

Platform specific processing

In addition to creating Dockerfiles and associated artifacts, dockerfile-node can run platform specific processing. At the present time the first and only platform taking advantage of this is naturally fly.io.

If, and only if, flyctl is installed, part of the path, and there exists a valid fly.toml file in the current directory, dockerfile-node will:

  • configure and create volume(s) for sqlite3
  • set swapfile size if that option is selected
  • attach consul for litefs
  • set secrets for remix and adonis apps
  • initialize git
  • define a staging app if one is mentioned in .github/workflows/deploy.yml

Testing

A single invocation of npm test will run all of the tests defined. Additionally npm run eslint will run eslint.

The current integration testing strategy is to run the dockerfile generator against various configurations and compare the generated artifacts with expected results. ARG values in Dockerfiles are masked before comparison.

To assis with this process, outputs of tests can be captured automatically. This is useful when adding new tests and when making a change that affects many tests. Be sure to inspect the output (e.g., by using git diff) before committing.

npm run test:capture

To run a single test (or tests maching a pattern), run mocha directly with the grep option.

npx mocha --grep swap

Additionally, each the outputs in each test directory can be directly tested to ensure that they can be successfully built by running docker buildx directory passing in the necessary build arguments. For example:

docker buildx build . --build-arg NODE_VERSION=18

More Repositories

1

dockerfile-rails

Provides a Rails generator to produce Dockerfiles and related files.
Dockerfile
422
star
2

postgres-ha

Postgres + Stolon for HA clusters as Fly apps.
Go
287
star
3

litefs-js

JavaScript utilities for working with LiteFS on Fly.io
TypeScript
154
star
4

nginx-cluster

A horizontally scalable NGINX caching cluster
Shell
125
star
5

terraform-provider-fly

Terraform provider for the Fly.io API
Go
114
star
6

edge-apollo-cache

Run and cache results from your Apollo GraphQL server on the edge with Fly
JavaScript
91
star
7

redis-geo-cache

A global Redis cache
Shell
81
star
8

bun

Bun JS app doing basically nothing
TypeScript
76
star
9

redis

Launch a Redis server on Fly
Shell
70
star
10

fly-run-this-function-on-another-machine

This is a simple example on how to spawn a Fly.io machine and run a function from there.
JavaScript
63
star
11

hello-rust

Rust example app on Fly.io
Dockerfile
62
star
12

nats-cluster

Global messaging for apps that need to talk to each other.
Go
44
star
13

postgres-flex

Postgres HA setup using repmgr
Go
44
star
14

tailscale-router

Go
40
star
15

rds-connector

Trivial Terraform example for a WireGuard peer to RDS
HCL
38
star
16

docker-daemon

A Docker daemon to run in Fly and access via a WireGuard peer.
Shell
38
star
17

fly-laravel

Run your Laravel apps on Fly
PHP
38
star
18

hello_elixir

An example for building and deploying an Elixir application to Fly using a Dockerfile
Elixir
38
star
19

litestream-base

A base Docker image for adding Litestream to apps
Dockerfile
33
star
20

smokescreen

An example of deploying Smokescreen on Fly.io
Go
31
star
21

go-example

A minimal Go application for tutorials
Go
29
star
22

python-hellofly-flask

A Pythonic version of the Hellofly example
Python
29
star
23

laravel-docker

Base Docker images for use with Laravel on Fly.io
Shell
28
star
24

cockroachdb

Shell
27
star
25

nginx

A fly app nginx config
Dockerfile
23
star
26

supercronic

Run periodic jobs on Fly with supercronic
Dockerfile
21
star
27

hello-fly-langchain

A minimal example of how to deploy LangChain to Fly.io using Flask
Python
21
star
28

hellonode-builtin

A minimal Fly example Node application for use in tutorials
JavaScript
20
star
29

vscode-remote

Shell
19
star
30

privatenet

Examples around querying 6PN private networking on Fly
JavaScript
18
star
31

node-demo

Fly.io Node.js demo
JavaScript
18
star
32

puppeteer-js-renderer

A service to render js for web scraping hosted on fly.io
JavaScript
17
star
33

hello-static

Create a static website with Fly - HTML from the example
HTML
16
star
34

ghost-litestream

Ghost + Litestream for global sqlite blogging
Dockerfile
16
star
35

wordpress-sqlite

Wordpress on SQLite
PHP
16
star
36

coredns

Authoritative CoreDNS on Fly.io
DIGITAL Command Language
15
star
37

ichabod

serf + headless chromium && CDP
Dockerfile
14
star
38

nix-base

Nix overlays for supporting Nix deployments on Fly.io
Nix
14
star
39

fly-log-local

Store Fly app logs locally.
Dockerfile
13
star
40

terraformed-machines

Example of Fly.io machines orchestration with Terraform and DNSimple
HCL
13
star
41

elixir_opentel_and_grafana

Project that goes with a Fly.io Phoenix Files article
Elixir
13
star
42

dockerfile-laravel

PHP
13
star
43

fastify-functions

Example Fastify server
JavaScript
12
star
44

postgres-migrator

Fly app that works to streamline Postgres migrations.
Dockerfile
12
star
45

pdf-appliance

Auto start machines that will generate PDFs for your application
TypeScript
12
star
46

hellodeno

A version of the Hellodeno example that uses flyctl's builtin deno builder
TypeScript
11
star
47

whisper-example

Fly GPU Machines transcribing an mp3 file with Whisper
Dockerfile
11
star
48

hello_elixir_sqlite

An example for building and deploying an Elixir application to Fly using a Dockerfile and SQLite!
Elixir
10
star
49

keydb

KeyDB server on Fly
Shell
9
star
50

fly-app-with-multiple-internal-ports

Example of how to deploy an app that has multiple ports listened to
JavaScript
9
star
51

fly-varnish

Dockerfile
9
star
52

grafana

Run Grafana on Fly
8
star
53

ollama-demo

@jmorganca's ollama.ai demo app on Fly.io
8
star
54

postgres-importer

Shell
8
star
55

nodejs-planetscale-read-replicas

A sample Node.js app that uses a Planetscale database with additional read-only regions
JavaScript
7
star
56

kong-api-gateway

Dockerfile
7
star
57

hostnamesapi

JavaScript examples for working with the new hostnames API on Fly
JavaScript
7
star
58

appkata-minio

MinIO S3-compatible storage on Fly
Dockerfile
7
star
59

autoscale-to-zero-demo

TypeScript
7
star
60

live-elements-demo

Live Elements Demo
Ruby
6
star
61

6pn-demo-chat

A Node-based websockets and NATS chat app which uses Fly 6PN networking
JavaScript
6
star
62

rqlite

Shell
6
star
63

deno-apollo

TypeScript
6
star
64

hello-fly

JavaScript
6
star
65

ssh-app

Run an SSH server to connect your privately networked Database apps to things like BI tools
Dockerfile
6
star
66

global-apollo-server

Fly global deployment with Apollo Server and Prisma
TypeScript
6
star
67

rails-nix

Deploy Rails apps on Fly.io with Nix
Ruby
5
star
68

code-server-dev-environment

Dockerfile
5
star
69

hello-flask

Example project demonstrating how to deploy a Flask app to Fly.io.
HTML
5
star
70

postgres

Deploy a Postgres database on Fly, ready for your Fly apps.
4
star
71

appkata-mqtt

An MQTT server app (with Mosquitto) with TLS+passwords
Dockerfile
4
star
72

global-rails

Ruby
4
star
73

globe-request-mapper

Elixir
4
star
74

buildkite-agent

Run a Buildkite agent on Fly with disk caching
Dockerfile
4
star
75

openresty-basic

Dockerfile
4
star
76

flydictionary

A light crud example for database examples
JavaScript
4
star
77

grpc-service

Running gRPC services on Fly.io
JavaScript
4
star
78

elixir_prom_ex_example

Elixir
4
star
79

hello-create-react-app

JavaScript
4
star
80

hello-remix

Sample Remix app setup for deployment on Fly.io
JavaScript
3
star
81

tcp-echo

TCP echo service for testing things that TCP
Go
3
star
82

rails-on-fly

Ruby
3
star
83

laravel-worker

Auto-scaled Laravel queue workers on Fly.io
PHP
3
star
84

pi-hole

Dockerfile
3
star
85

fly-nestjs

Example NestJS application configured for deployment on Fly.io
TypeScript
3
star
86

view-component-playground

Various view components tried in Rails
Ruby
3
star
87

python_gpu_example

A setup with Jupyter for GPU-enabled ML tinkering
Shell
3
star
88

hello-django

Example project demonstrating how to deploy a Django app to Fly.io.
Python
3
star
89

localai-demo

LocalAI demo app on Fly.io
Shell
3
star
90

rails-statics

Rails application to test the performance of Rails static assets
Ruby
3
star
91

hello-django-postgres

Python
2
star
92

fly-laravel-litefs

Guide on deploying multiple instances of a Laravel Fly app and integrating LiteFS and fly-replay to allow syncing SQLite database across the instances.
PHP
2
star
93

ollama-webui-demo

Shell
2
star
94

udp-echo-

Sample TCP/UDP Echo Service
Go
2
star
95

replicache-websocket

TypeScript
2
star
96

rails-machine-workers

A demonstration of how to use Fly Machines for "scale-to-0" ActiveJob background workers
Ruby
2
star
97

flygreeting

An example app for other examples to use.
Go
2
star
98

postgres-standalone

Standalone Postgres on Fly
Go
2
star
99

flychat-ws

A chat example using raw websockets, tested on Fly.io
JavaScript
2
star
100

fly-lucky

Crystal Lucky Framework app for Fly.io deployment
Crystal
2
star