Skip to content

Commit 70142b5

Browse files
committed
build(fly): Add fly.io deploy
1 parent 78e449a commit 70142b5

7 files changed

Lines changed: 525 additions & 2 deletions

File tree

.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
21+
# debug
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# local env files
27+
.env.local
28+
.env.development.local
29+
.env.test.local
30+
.env.production.local
31+
32+
.vercel
33+
34+
# Typescript
35+
*.tsbuildinfo
36+
.env*.local

.github/workflows/fly-deploy.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Adjust NODE_VERSION as desired
4+
ARG NODE_VERSION=24.9.0
5+
FROM node:${NODE_VERSION}-slim AS base
6+
7+
LABEL fly_launch_runtime="Next.js"
8+
9+
# Next.js app lives here
10+
WORKDIR /app
11+
12+
# Set production environment
13+
ENV NODE_ENV="production"
14+
ARG YARN_VERSION=1.22.19
15+
RUN npm install -g yarn@$YARN_VERSION --force
16+
17+
18+
# Throw-away build stage to reduce size of final image
19+
FROM base AS build
20+
21+
# Install packages needed to build node modules
22+
RUN apt-get update -qq && \
23+
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
24+
25+
# Install node modules
26+
COPY .yarnrc.yml package.json yarn.lock ./
27+
RUN yarn install --frozen-lockfile --production=false
28+
29+
# Copy application code
30+
COPY . .
31+
32+
# Build application
33+
RUN npx next build --experimental-build-mode compile
34+
35+
# Remove development dependencies
36+
RUN yarn install --production=true
37+
38+
39+
# Final stage for app image
40+
FROM base
41+
42+
# Copy built application
43+
COPY --from=build /app /app
44+
45+
# Entrypoint sets up the container.
46+
ENTRYPOINT [ "/app/docker-entrypoint.js" ]
47+
48+
# Start the server by default, this can be overwritten at runtime
49+
EXPOSE 3000
50+
CMD [ "yarn", "run", "start" ]

docker-entrypoint.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
const { spawn } = require('node:child_process')
4+
5+
const env = { ...process.env }
6+
7+
;(async() => {
8+
// If running the web server then prerender pages
9+
if (process.argv.slice(-3).join(' ') === 'yarn run start') {
10+
await exec('npx next build --experimental-build-mode generate')
11+
}
12+
13+
// launch application
14+
await exec(process.argv.slice(2).join(' '))
15+
})()
16+
17+
function exec(command) {
18+
const child = spawn(command, { shell: true, stdio: 'inherit', env })
19+
return new Promise((resolve, reject) => {
20+
child.on('exit', code => {
21+
if (code === 0) {
22+
resolve()
23+
} else {
24+
reject(new Error(`${command} failed rc=${code}`))
25+
}
26+
})
27+
})
28+
}

fly.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# fly.toml app configuration file generated for podcst on 2025-12-20T23:37:09+01:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'podcst'
7+
primary_region = 'ams'
8+
9+
[build]
10+
11+
[env]
12+
HOSTNAME = "0.0.0.0"
13+
14+
[http_service]
15+
internal_port = 3000
16+
force_https = true
17+
auto_stop_machines = 'suspend'
18+
auto_start_machines = true
19+
min_machines_running = 0
20+
processes = ['app']
21+
22+
[[vm]]
23+
memory = '1gb'
24+
cpus = 1
25+
memory_mb = 1024

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"zustand": "5.0.2"
4848
},
4949
"devDependencies": {
50+
"@flydotio/dockerfile": "^0.7.10",
5051
"@types/chromecast-caf-sender": "1.0.11",
5152
"@types/eslint": "9.6.1",
5253
"@types/eslint-config-prettier": "6.11.3",

0 commit comments

Comments
 (0)