Skip to content

Commit

Permalink
chore: deploy to fly
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Sep 20, 2024
1 parent a41a5de commit 3015b35
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Dependency directory
node_modules

# Env
.env

# Build output
.turbo
chunk
output
dist
functions
*.ps1
*.sqlite3

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
20 changes: 20 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- remix
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4

- uses: superfly/flyctl-actions/setup-flyctl@master

- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
69 changes: 69 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.10.0
ARG PNPM_VERSION=9.10.0


# Base Image
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"

# Install pnpm
RUN npm install -g pnpm@$PNPM_VERSION


# Throw-away build stage to reduce size of final image
FROM base as build

# Build app
ENV SERVER_PROTOCOL=http \
SERVER_HOST=garden-api.breadio.wiki \
APP_HOST=garden.breadio.wiki

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json .npmrc .node-version ./
COPY ./packages/animegarden/package.json ./packages/animegarden/
COPY ./packages/app/package.json ./packages/app/
COPY ./packages/cli/package.json ./packages/cli/
COPY ./packages/database/package.json ./packages/database/
COPY ./packages/scraper/package.json ./packages/scraper/
COPY ./packages/server/package.json ./packages/server/
COPY ./packages/worker/package.json ./packages/worker/
COPY ./apps/frontend/web/package.json ./apps/frontend/web/
RUN pnpm install --frozen-lockfile --prod=false

# Copy application code
COPY --link . .

# Build application
RUN pnpm run build && pnpm run build:web && pnpm run build:app

# Remove development dependencies
RUN pnpm prune --prod


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Listen on 3000
ENV HOST=0.0.0.0 PORT=3000

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000

CMD [ "node", "packages/app/dist/server/entry.mjs" ]
26 changes: 26 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# fly.toml app configuration file generated for animegarden-production on 2024-09-20T21:22:27+08:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'animegarden-production'
primary_region = 'hkg'

[build]
dockerfile = "Dockerfile"

[processes]
app = "node packages/app/dist/server/entry.mjs"

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"animegarden": "tsx packages/cli/src/cli.ts",
"build": "turbo run build",
"build:app": "turbo run build --filter @animegarden/app...",
"build:cli": "turbo run build --filter @animegarden/cli...",
"build:server": "turbo run build --filter @animegarden/server...",
"build:web": "turbo run build --filter @animegarden/web...",
Expand All @@ -25,6 +26,7 @@
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240909.0",
"@flydotio/dockerfile": "^0.5.8",
"@total-typescript/ts-reset": "^0.6.1",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.16.5",
Expand Down
Loading

0 comments on commit 3015b35

Please sign in to comment.