Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RaspberryPiで動かせるようにする #159

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
100 changes: 100 additions & 0 deletions config/environments/pi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {URL} from 'url';
import {Config} from '../config';

const CONNECT_URL = process.env.URL || 'localhost';

const config: Config = {
environment: 'production-pi',

host: new URL(`http://${CONNECT_URL}`),

cateiruSSOEndpoint: new URL('https://sso.cateiru.com/sso/login'),
cateiruSSOTokenEndpoint: new URL(
'https://api.sso.cateiru.com/v1/oauth/token'
),
cateiruSSOPublicKeyEndpoint: new URL(
'https://api.sso.cateiru.com/v1/oauth/jwt/key'
),
cateiruSSOClientSecret: process.env.CATEIRU_SSO_CLIENT_SECRET || '',
cateiruSSOClientId: process.env.CATEIRU_SSO_CLIENT_ID || '',

sessionTokenLen: 64,
sessionCookieName: 'noratomo-session',
sessionPeriodDay: 1,
sessionCookieOptions: () => {
return {
domain: CONNECT_URL,
sameSite: 'strict',
secure: false, // httpで接続するためfalse
httpOnly: true,
path: '/',
};
},

refreshTokenLen: 128,
refreshCookieName: 'noratomo-refresh',
refreshPeriodDay: 30,
refreshCookieOptions: () => {
const date = new Date(Date.now());
date.setDate(date.getDate() + config.refreshPeriodDay);

return {
domain: CONNECT_URL,
expires: date,
maxAge: config.refreshPeriodDay * 86400,
sameSite: 'strict',
secure: false, // httpで接続するためfalse
httpOnly: true,
path: '/',
};
},

otherCookieName: 'noratomo-options',
otherCookieOptions: () => {
const date = new Date(Date.now());
date.setDate(date.getDate() + config.refreshPeriodDay);

return {
domain: CONNECT_URL,
expires: date,
maxAge: config.refreshPeriodDay * 86400,
sameSite: 'strict',
secure: false, // httpで接続するためfalse
httpOnly: false,
path: '/',
};
},

db: {
host: '127.0.0.1',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
host: '127.0.0.1',
host: 'db',

user: 'docker',
password: 'docker',
database: 'noratomo',
},

// Cloud Storage
storageOptions: {
apiEndpoint: 'http://localhost:4443',
projectId: 'local',
},
publicStorageHost: new URL(`http://${CONNECT_URL}:4443`),
bucketName: 'noratomo',

// hotpepper api
hotpepperApiKey: process.env.HOTPEPPER_API_KEY || '',
hotpepperGourmetSearchEndpoint: new URL(
'http://webservice.recruit.co.jp/hotpepper/gourmet/v1'
),
hotpepperShopSearchEndpoint: new URL(
'http://webservice.recruit.co.jp/hotpepper/shop/v1'
),

searchCount: 20,

noraQuestionLimit: 5,
noraQuestionAllowScore: 300,

discordWebhookURL: process.env.DISCORD_CONTACT_URL || '',
};

export default config;
7 changes: 7 additions & 0 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import localConfig from './environments/local';
import piConfig from './environments/pi';
import productionConfig from './environments/production';
import testConfig from './environments/tests';

const config = () => {
const environment = process.env.NODE_ENV;

// pi mode
const piMode = process.env.PI_MODE;
if (typeof piMode !== 'undefined') {
return piConfig;
}

console.log(`ENV: ${environment}`);

switch (environment) {
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ services:
build: .
container_name: next
ports:
- 3000:3000
- 80:3000
environment:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restart: alwaysがほしい

PORT: 3000
NODE_ENV: production
PI_MODE: "true"
CATEIRU_SSO_CLIENT_ID: hogehoge
CATEIRU_SSO_CLIENT_SECRET: hogehoge
Comment on lines 13 to 14
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CATEIRU_SSO_CLIENT_ID: hogehoge
CATEIRU_SSO_CLIENT_SECRET: hogehoge

59 changes: 59 additions & 0 deletions documents/env.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# 環境変数

```env
NODE_ENV=
PI_MODE=

# 全て
URL=
HOTPEPPER_API_KEY=
NEXT_PUBLIC_GOOGLE_MAP_KEY=
DISCORD_CONTACT_URL=

# piとproduction
CATEIRU_SSO_CLIENT_SECRET=
CATEIRU_SSO_CLIENT_ID=

# Productionのみ
DB_SOCKET_PATH=
DB_USER=
DB_PASSWORD=
INSTANCE_CONNECTION_NAME=
```

# PI_MODE

RaspberryPiで動かすときのモード。boolean

## URL

ローカルでカスタムURLを使用して検証できます。SSHなどでリモート接続している場合、そのIPアドレスを入力することでcookieやGASが使用できます。
Expand All @@ -23,3 +42,43 @@ NEXT_PUBLIC_GOOGLE_MAP_KEY=
Google MapsのAPI KEYを設定します。

[詳しくは公式ドキュメントを参照してください](https://developers.google.com/maps/documentation/android-sdk/get-api-key?hl=ja)

## DISCORD_CONTACT_URL

お問い合わせをDiscordのWebhookに送信するためのWebhook URL

## CATEIRU_SSO_CLIENT_SECRET

**piとproduction**のみ

CateiruSSOのClientSecret

## CATEIRU_SSO_CLIENT_ID

**piとproduction**のみ

CateiruSSOのClientID

## DB_SOCKET_PATH

**production**のみ

CloudSQLのSocket path

## DB_USER

**production**のみ

DBにアクセスできるユーザ

## DB_PASSWORD

**production**のみ

DBのパスワード

## INSTANCE_CONNECTION_NAME

**production**のみ

CloudRunでCloudSQLにアクセスする際に必要だった。