Skip to content

Commit 87ab970

Browse files
committed
Generate Dockerfile and fly.toml for Fly.io deployment
Generate Dockerfile and fly.toml with fly launch: fly launch --build-only --no-deploy --name jts Clean up the Dockerfile and fly.toml: Comment out the DB stuff in the Dockerfile and change the `CMD` - this is needed since running as `npm run start` prevents from the node processes from receiving the `SIGINT` or `SIGTERM` signals, more at: http://medium.com/@becintec/building-graceful-node-applications-in-docker-4d2cd4d5d392 Leave the app name empty and remove all but region in the fly.toml
1 parent d8496f6 commit 87ab970

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
db.sqlite3
3+
.envrc

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Adjust NODE_VERSION as desired
4+
ARG NODE_VERSION=21.7.1
5+
FROM node:${NODE_VERSION}-slim as base
6+
7+
LABEL fly_launch_runtime="Node.js"
8+
9+
# Node.js app lives here
10+
WORKDIR /app
11+
12+
# Set production environment
13+
ENV NODE_ENV="production"
14+
15+
16+
# Throw-away build stage to reduce size of final image
17+
FROM base as build
18+
19+
# Install packages needed to build node modules
20+
RUN apt-get update -qq && \
21+
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
22+
23+
# Install node modules
24+
COPY --link package-lock.json package.json ./
25+
RUN npm ci
26+
27+
# Copy application code
28+
COPY --link . .
29+
30+
31+
# Final stage for app image
32+
FROM base
33+
34+
# Copy built application
35+
COPY --from=build /app /app
36+
37+
# Setup sqlite3 on a separate volume
38+
# RUN mkdir -p /data
39+
# VOLUME /data
40+
41+
# Start the server by default, this can be overwritten at runtime
42+
EXPOSE 3000
43+
# ENV DATABASE_URL="file:///data/sqlite.db"
44+
CMD [ "node", "server.js" ]

fly.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# fly.toml app configuration file generated for jts on 2024-03-28T10:26:54+01:00
2+
#
3+
# See http://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = '' # change this for deploy!
7+
primary_region = 'waw'
8+

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"devDependencies": {
3+
"@flydotio/dockerfile": "^0.5.4",
34
"@flydotio/node-demo": "^0.2.1"
45
},
56
"dependencies": {

0 commit comments

Comments
 (0)