Skip to content

Commit 548e146

Browse files
authored
deploy (#676)
- **fix flake** - **deployed** # PRの概要 ## 具体的な変更内容 ## 影響範囲 ## 動作要件 ## 補足 ## レビューリクエストを出す前にチェック! - [ ] 改めてセルフレビューしたか - [ ] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 -->
1 parent c53cd65 commit 548e146

File tree

14 files changed

+94
-35
lines changed

14 files changed

+94
-35
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env*

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SQL_GENERATE_URL=postgres://sql-url

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,3 @@ jobs:
9797
- uses: oven-sh/setup-bun@v2
9898
- run: bun prepare:deploy:web
9999
- run: test `ls web/.next | wc -l` != 0
100-
101-
deploy-test-server:
102-
name: Deploy Test (server)
103-
runs-on: ubuntu-latest
104-
steps:
105-
- uses: actions/checkout@v4
106-
- uses: oven-sh/setup-bun@v2
107-
- run: bun prepare:deploy:server

.github/workflows/deploy.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
deploy:
9+
name: Deploy Server to Fly.io
10+
runs-on: ubuntu-latest
11+
env:
12+
SQL_GENERATE_URL: ${{ secrets.DATABASE_URL_FOR_PRISMA_SQL_GENERATION }}
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: superfly/flyctl-actions/setup-flyctl@master
17+
- run: flyctl deploy --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL --access-token "${{ secrets.FLY_DEPLOY_TOKEN }}"

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# syntax = docker/dockerfile:1
2+
3+
ARG BUN_VERSION=1.2.2
4+
FROM oven/bun:${BUN_VERSION} AS base
5+
LABEL fly_launch_runtime="Bun/Prisma"
6+
ENV NODE_ENV="production"
7+
8+
# Throw-away build stage to reduce size of final image
9+
FROM base AS build
10+
11+
WORKDIR /build
12+
ARG SQL_GENERATE_URL
13+
RUN test -n "${SQL_GENERATE_URL}"
14+
ENV DATABASE_URL=$SQL_GENERATE_URL
15+
ENV DIRECT_URL=$SQL_GENERATE_URL
16+
COPY . .
17+
RUN --mount=type=cache,target=~/.bun/install bun install --frozen-lockfile --ignore-scripts
18+
RUN cd server; bun prisma generate --sql
19+
RUN cd server; bun run :build
20+
21+
22+
# Final stage for app image
23+
FROM base AS runner
24+
WORKDIR /srv
25+
26+
# Copy built application
27+
COPY --from=build /build/server/target/index.js /srv/index.js
28+
COPY --from=build /build/node_modules/.prisma/client /node_modules/.prisma/client
29+
COPY --from=build /build/node_modules/@img /node_modules/@img
30+
31+
# Start the server by default, this can be overwritten at runtime
32+
EXPOSE 3000
33+
CMD [ "bun", "run", "./index.js" ]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ make prepare-deploy-web`
7272

7373
server:
7474
```sh
75-
make prepare-deploy-server
76-
make deploy-server
75+
# prisma がビルド時に DATABASE_URL を要求するため、 root に .env を作って、 .env.sample に従って埋めよう。
76+
bun deploy:server
7777
```

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
packages =
4040
(with pkgs; [
4141
nix # HACK: to fix the side effect of the hack below, installing two instances of nix
42+
flyctl
4243
gnumake
4344
nodejs
4445
biome

fly.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# fly.toml app configuration file generated for coursemate on 2025-03-06T14:33:10+09:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'coursemate'
7+
primary_region = 'nrt'
8+
9+
[build]
10+
11+
[deploy]
12+
13+
[http_service]
14+
internal_port = 3000
15+
force_https = true
16+
auto_stop_machines = 'stop'
17+
auto_start_machines = true
18+
min_machines_running = 0
19+
processes = ['app']
20+
21+
[[vm]]
22+
memory = '512mb'
23+
cpu_kind = 'shared'
24+
cpus = 1

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
"watch:server": "cd server; bun run dev",
2929
"seed": "cd server; bun prisma db seed",
3030
"prepare:deploy:web": "bun install && bun run build:web",
31-
"prepare:deploy:server": "bun install",
3231
"deploy:web": "cd web; bun run start --port $PORT",
33-
"deploy:server": "cd server; bun run src/index.ts",
32+
"deploy:server": "bun run --env-file=.env :deploy:server",
33+
":deploy:server": "fly deploy --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL",
34+
"docker:server": "docker build . --build-arg SQL_GENERATE_URL=$SQL_GENERATE_URL",
3435
"dev-db": "make dev-db",
3536
"test": "make test",
3637
"spell": "bunx cspell --quiet ."

server/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ node_modules
22

33
# WARNING: DELETE THIS IF YOU FIND THIS
44
.env
5-
65
.env.dev
7-
# deprecated, delete /dist if you have one
8-
/dist
6+
97
/target

0 commit comments

Comments
 (0)