Skip to content

Commit

Permalink
Merge pull request #54 from oystersjp/flyio
Browse files Browse the repository at this point in the history
  • Loading branch information
mii288 committed May 3, 2023
2 parents 829a139 + ace0a61 commit 98adcb3
Show file tree
Hide file tree
Showing 10 changed files with 730 additions and 638 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fly.toml
Dockerfile
.dockerignore
node_modules
.git
22 changes: 0 additions & 22 deletions .github/workflows/deploy-to-heroku.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Fly Deploy

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.15.4
node-version: 18.16.0
- run: npm ci
- run: npm run lint
- run: npm run build
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.16.0
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.16.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="NodeJS"

# NodeJS app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV=production


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

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

# Install node modules
COPY --link package.json package-lock.json .
RUN npm ci --production=false

# Copy application code
COPY --link . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --production


# Final stage for app image
FROM base

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

# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,43 @@ Discord のサーバーにあるボイスチャンネルに誰かが入室した

## セルフホスティング方法

1. heroku のアカウントを作る
1. この repository を fork する
1. fork した repository の github secret に HEROKU_API_KEY, HEROKU_EMAIL, DISCORD_TOKEN, SLACK_WEBHOOK を設定する
1. heroku_app_name(https://github.com/oystersjp/gohan-dekitayo/blob/c8dbf9937f954baf3d832408751527b1b9e089dc/.github/workflows/deploy-to-heroku.yml#L16)を変更する
1. 変更を master へ push し、deploy の github action を実行させる
2. [Fly.io](https://fly.io) のアカウントを作る
3. Local PC で flyctl コマンドを使ってアプリの設定を行う(FYI: [Hands-on with Fly.io](https://fly.io/docs/hands-on/install-flyctl/))

```sh
$ brew install flyctl
$ flyctl auth login
$ flyctl launch
Creating app in /Users/misato/ghq/github.com/oystersjp/gohan-dekitayo
An existing fly.toml file was found for app gohan-dekitayo
? Would you like to copy its configuration to the new app? Yes
Scanning source code
Detected a Dockerfile app
? Choose an app name (leaving blank will default to 'gohan-dekitayo')
? Select Organization: oysters (oysters)
App will use 'nrt' region as primary
Created app 'gohan-dekitayo' in organization 'oysters'
Admin URL: https://fly.io/apps/gohan-dekitayo
Hostname: gohan-dekitayo.fly.dev
? Would you like to set up a Postgresql database now? No
? Would you like to set up an Upstash Redis database now? No
Wrote config file fly.toml
? Would you like to deploy now? No
Validating /Users/misato/ghq/github.com/oystersjp/gohan-dekitayo/fly.toml
Platform: machines
✓ Configuration is valid
Your app is ready! Deploy with `flyctl deploy`
$ flyctl secrets set DISCODE_TOKEN=<your-discord-token>
$ flyctl secrets set SLACK_WEBHOOK=<your-slack-webhook>
$ flyctl scale count 1 # 通知が二重で届く場合は実行してください
$ flyctl deploy
```

4. 以下のコマンドを実行して、Deploy Token を発行する。この値を fork した repository の GitHub Actions secrets に `FLY_API_TOKEN` として保存する

```sh
$ flyctl tokens create deploy -x 999999h | pbcopy
```

5. 変更を `master` へ push し、deploy の github action を実行させる
13 changes: 13 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# fly.toml app configuration file generated for gohan-dekitayo on 2023-05-02T19:00:42+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "gohan-dekitayo"
primary_region = "nrt"

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false
auto_start_machines = false
Loading

0 comments on commit 98adcb3

Please sign in to comment.