Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env*
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SQL_GENERATE_URL=postgres://sql-url
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,3 @@ jobs:
- uses: oven-sh/setup-bun@v2
- run: bun prepare:deploy:web
- run: test `ls web/.next | wc -l` != 0

deploy-test-server:
name: Deploy Test (server)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun prepare:deploy:server
17 changes: 17 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Deploy
on:
push:
branches:
- main

jobs:
deploy:
name: Deploy Server to Fly.io
runs-on: ubuntu-latest
env:
SQL_GENERATE_URL: ${{ secrets.DATABASE_URL_FOR_PRISMA_SQL_GENERATION }}

steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL --access-token "${{ secrets.FLY_DEPLOY_TOKEN }}"
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# syntax = docker/dockerfile:1

ARG BUN_VERSION=1.2.2
FROM oven/bun:${BUN_VERSION} AS base
LABEL fly_launch_runtime="Bun/Prisma"
ENV NODE_ENV="production"

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

WORKDIR /build
ARG SQL_GENERATE_URL
RUN test -n "${SQL_GENERATE_URL}"
ENV DATABASE_URL=$SQL_GENERATE_URL
ENV DIRECT_URL=$SQL_GENERATE_URL
COPY . .
RUN --mount=type=cache,target=~/.bun/install bun install --frozen-lockfile --ignore-scripts
RUN cd server; bun prisma generate --sql
RUN cd server; bun run :build


# Final stage for app image
FROM base AS runner
WORKDIR /srv

# Copy built application
COPY --from=build /build/server/target/index.js /srv/index.js
COPY --from=build /build/node_modules/.prisma/client /node_modules/.prisma/client
COPY --from=build /build/node_modules/@img /node_modules/@img

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "./index.js" ]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ make prepare-deploy-web`

server:
```sh
make prepare-deploy-server
make deploy-server
# prisma がビルド時に DATABASE_URL を要求するため、 root に .env を作って、 .env.sample に従って埋めよう。
bun deploy:server
```
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
packages =
(with pkgs; [
nix # HACK: to fix the side effect of the hack below, installing two instances of nix
flyctl
gnumake
nodejs
biome
Expand Down
24 changes: 24 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# fly.toml app configuration file generated for coursemate on 2025-03-06T14:33:10+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'coursemate'
primary_region = 'nrt'

[build]

[deploy]

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

[[vm]]
memory = '512mb'
cpu_kind = 'shared'
cpus = 1
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
"watch:server": "cd server; bun run dev",
"seed": "cd server; bun prisma db seed",
"prepare:deploy:web": "bun install && bun run build:web",
"prepare:deploy:server": "bun install",
"deploy:web": "cd web; bun run start --port $PORT",
"deploy:server": "cd server; bun run src/index.ts",
"deploy:server": "bun run --env-file=.env :deploy:server",
":deploy:server": "fly deploy --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL",
"docker:server": "docker build . --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL",
"dev-db": "make dev-db",
"test": "make test",
"spell": "bunx cspell --quiet ."
Expand Down
4 changes: 1 addition & 3 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ node_modules

# WARNING: DELETE THIS IF YOU FIND THIS
.env

.env.dev
# deprecated, delete /dist if you have one
/dist

/target
13 changes: 0 additions & 13 deletions server/Dockerfile

This file was deleted.

6 changes: 4 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"scripts": {
"prepare": "bun --env-file=./.env.dev prisma generate --sql || (echo 'please set DATABASE_URL in server/.env.dev' && exit 1)",
"dev": "bun --watch src/index.ts",
"build": "tsc",
"serve": "bun target/main.js"
"check": "tsc",
"clean": "rm target -r || true",
"build": "bun clean && bun check && bun run :build",
":build": "bun build ./src/index.ts --target bun --outfile target/index.js --minify"
},
"prisma": {
"seed": "bun src/seeds/seed-test.ts"
Expand Down
10 changes: 5 additions & 5 deletions server/prisma.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
(prisma-utils.lib.prisma-factory
{
inherit pkgs;
prisma-fmt-hash = "sha256-atD5GZfmeU86mF1V6flAshxg4fFR2ews7EwaJWZZzbc=";
query-engine-hash = "sha256-8FTZaKmQCf9lrDQvkF5yWPeZ7TSVfFjTbjdbWWEHgq4=";
libquery-engine-hash = "sha256-USIdaum87ekGY6F6DaL/tKH0BAZvHBDK7zjmCLo//kM=";
schema-engine-hash = "sha256-k5MkxXViEqojbkkcW/4iBFNdfhb9PlMEF1M2dyhfOok=";
prisma-fmt-hash = "sha256-iZuomC/KaLF0fQy6RVHwk2qq4DRaG3xj+sWmtLofiMU=";
query-engine-hash = "sha256-Pl/YpYu326qqpbVfczM5RxB8iWXZlewG9vToqzSPIQo=";
libquery-engine-hash = "sha256-ETwMIJMjMgZmjH6QGD7GVwYYlyx9mo2ydEeunFViCjQ=";
schema-engine-hash = "sha256-rzzzPHOpUM3GJvkhU08lQ7rNspdq3RKxMRRW9YZtvhU=";
})
.fromBunLock
./bun.lock;
../bun.lock;
inherit (prisma) package;
in {
inherit (prisma) shellHook;
Expand Down
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "es2016",
"noEmit": true,
"module": "commonjs",
"rootDir": "./src",
"outDir": "./target",
Expand Down