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

Migrate to Fly.io #35

Merged
merged 7 commits into from
Aug 27, 2022
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy

on:
push:
branches: [ master ]

jobs:
deploy-gh-pages:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn workspace @kenrick95/c4-browser run build-gh-pages
- name: Deploy
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: app/dist

deploy-fly:

runs-on: ubuntu-latest
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
5 changes: 1 addition & 4 deletions .github/workflows/nodejs.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Test

on:
Expand All @@ -16,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16]

steps:
- uses: actions/checkout@v3
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16-alpine
WORKDIR /usr/src/app

COPY .yarn .yarn/
COPY .yarnrc.yml yarn.lock package.json ./
COPY browser/package.json ./browser/
COPY core/package.json ./core/
COPY server/package.json ./server/


RUN yarn install --frozen-lockfile
COPY . .
RUN yarn workspaces foreach --verbose --topological run build

EXPOSE ${PORT}
CMD [ "yarn", "workspace", "@kenrick95/c4-server", "start"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

6 changes: 3 additions & 3 deletions browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
"build": "yarn clean && parcel build src/index.html",
"build-gh-pages": "yarn clean && parcel build src/index.html --public-url \"https://kenrick95.github.io/c4/dist/\"",
"prettier": "prettier --write \"./**/*.?(ts|html|scss|css)\"",
"clean": "shx rm -rf dist/",
"clean": "rimraf dist/",
"test": "echo 'OK'"
},
"dependencies": {
"@kenrick95/c4": "4.0.0",
"@kenrick95/c4": "workspace:^",
"es6-promise": "^4.2.8",
"url-search-params-polyfill": "^8.1.1"
},
"devDependencies": {
"@types/node": "^16.9.6",
"parcel-bundler": "^1.12.4",
"prettier": "^2.4.1",
"shx": "^0.3.3",
"rimraf": "^3.0.2",
"typescript": "^4.4.3"
}
}
6 changes: 3 additions & 3 deletions browser/src/board/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BoardBase, BoardPiece } from '@kenrick95/c4/src/board'
import { Player } from '@kenrick95/c4/src/player'
import { onresize, animationFrame } from '@kenrick95/c4/src/utils'
import { BoardBase, BoardPiece } from '@kenrick95/c4'
import { Player } from '@kenrick95/c4'
import { onresize, animationFrame } from '@kenrick95/c4'
import { drawMask, drawCircle, clearCanvas } from './utils'

export class Board extends BoardBase {
Expand Down
4 changes: 2 additions & 2 deletions browser/src/game/game-local-2p.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BoardPiece } from '@kenrick95/c4/src/board'
import { PlayerHuman } from '@kenrick95/c4/src/player'
import { BoardPiece } from '@kenrick95/c4'
import { PlayerHuman } from '@kenrick95/c4'
import { GameLocal, initGameLocal } from './game-local'

class GameLocal2p extends GameLocal {}
Expand Down
4 changes: 2 additions & 2 deletions browser/src/game/game-local-ai.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BoardPiece } from '@kenrick95/c4/src/board'
import { PlayerAi } from '@kenrick95/c4/src/player'
import { BoardPiece } from '@kenrick95/c4'
import { PlayerAi } from '@kenrick95/c4'
import { GameLocal, initGameLocal } from './game-local'

class GameLocalAi extends GameLocal {}
Expand Down
12 changes: 4 additions & 8 deletions browser/src/game/game-local.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { Board } from '../board'
import { BoardBase, BoardPiece } from '@kenrick95/c4/src/board'
import { GameBase } from '@kenrick95/c4/src/game'
import { Player, PlayerHuman, PlayerAi } from '@kenrick95/c4/src/player'
import {
showMessage,
animationFrame,
getColumnFromCoord,
} from '@kenrick95/c4/src/utils'
import { BoardBase, BoardPiece } from '@kenrick95/c4'
import { GameBase } from '@kenrick95/c4'
import { Player, PlayerHuman, PlayerAi } from '@kenrick95/c4'
import { showMessage, animationFrame, getColumnFromCoord } from '@kenrick95/c4'

const statusbox = document.querySelector('.statusbox')
const statusboxBodyGame = document.querySelector('.statusbox-body-game')
Expand Down
10 changes: 5 additions & 5 deletions browser/src/game/game-online-2p.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Board } from '../board'
import { BoardBase, BoardPiece } from '@kenrick95/c4/src/board'
import { BoardBase, BoardPiece } from '@kenrick95/c4'
import {
GameBase,
MESSAGE_TYPE,
constructMessage,
parseMessage,
GameOnlineMessage,
} from '@kenrick95/c4/src/game'
import { Player, PlayerHuman, PlayerShadow } from '@kenrick95/c4/src/player'
import { showMessage, getColumnFromCoord } from '@kenrick95/c4/src/utils'
} from '@kenrick95/c4'
import { Player, PlayerHuman, PlayerShadow } from '@kenrick95/c4'
import { showMessage, getColumnFromCoord } from '@kenrick95/c4'

enum GAME_MODE {
FIRST = BoardPiece.PLAYER_1,
Expand All @@ -26,7 +26,7 @@ const C4_SERVER_ENDPOINT =
process.env.NODE_ENV === 'production'
? process.env.C4_SERVER_ENDPOINT
? process.env.C4_SERVER_ENDPOINT
: `wss://c4-server.herokuapp.com/`
: `wss://c4-server.fly.dev/`
: `ws://${location.hostname}:8080`

export class GameOnline2p extends GameBase {
Expand Down
2 changes: 1 addition & 1 deletion browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"target": "es5",
"lib": ["es2015", "dom", "dom.iterable"]
},
"include": ["src/", "@kenrick95/c4"],
"include": ["src/"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
7 changes: 4 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
"connect-four",
"game"
],
"main": "./dist/lib.ts",
"main": "./dist/lib.js",
"types": "./src/lib.ts",
"source": "./src/lib.ts",
"files": [
"src/",
"dist/"
],
"scripts": {
"build": "yarn clean && parcel build ./src/lib.ts",
"clean": "shx rm -rf dist/",
"clean": "rimraf dist/",
"prettier": "prettier --write \"./**/*.?(ts|html|scss|css)\"",
"test": "jest"
},
Expand All @@ -38,7 +39,7 @@
"jest": "^27.2.1",
"parcel-bundler": "^1.12.4",
"prettier": "^2.4.1",
"shx": "^0.3.3",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
}
Expand Down
16 changes: 0 additions & 16 deletions deploy.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# Deployment notes

## To GitHub Pages
```
git checkout gh-pages
git merge master
yarn
yarn workspace @kenrick95/c4-browser run build-gh-pages
rm index.html
rm -rf dist/
mv browser/dist/ dist/
mv dist/index.html index.html
```

## To Heroku

No action needed. Automatically deployed on master branch

## To npm

Publishing [@kenrick95/c4](https://www.npmjs.com/package/@kenrick95/c4)
Expand Down
42 changes: 42 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# fly.toml file generated for c4-server on 2022-08-27T10:18:06+08:00

app = "c4-server"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
dockerfile = "Dockerfile"

[env]
PORT = "8080"

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"url": "https://github.com/kenrick95/c4/issues"
},
"engines": {
"node": "^16"
"node": "16.x",
"yarn": "3.x"
},
"packageManager": "[email protected]",
"homepage": "https://github.com/kenrick95/c4",
Expand All @@ -39,7 +40,7 @@
"scripts": {
"start": "concurrently --handle-input \"yarn:start-server\" \"yarn:start-browser\"",
"start-browser": "yarn workspace @kenrick95/c4-browser start",
"start-server": "yarn workspace @kenrick95/c4-server start-dev"
"start-server": "yarn workspace @kenrick95/c4-server start-dev-watch"
},
"devDependencies": {
"concurrently": "^6.2.1"
Expand Down
12 changes: 8 additions & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
"files": [
"src/"
],
"main": "./dist/index.js",
"source": "./src/index.ts",
"scripts": {
"start": "ts-node src/index.ts",
"start-dev": "nodemon --watch src --ignore 'src/**/*.spec.ts' --exec yarn start",
"build": "echo 'OK'",
"start": "yarn node ./dist/index.js",
"start-dev": "ts-node src/index.ts",
"start-dev-watch": "nodemon --watch src --ignore 'src/**/*.spec.ts' --exec yarn start",
"build": "yarn clean && tsc --outDir dist/",
"clean": "rimraf dist/",
"prettier": "prettier --write \"./**/*.?(ts|html|scss|css)\"",
"test": "echo 'OK'"
},
Expand All @@ -38,11 +41,12 @@
"@types/ws": "^7.4.7",
"nodemon": "^2.0.13",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
},
"dependencies": {
"@kenrick95/c4": "4.0.0",
"@kenrick95/c4": "workspace:^",
"redux": "^4.1.1",
"redux-thunk": "^2.3.0",
"uuid": "^8.3.2",
Expand Down
4 changes: 2 additions & 2 deletions server/src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { v4 as uuidV4 } from 'uuid'
import { PlayerId, MatchId, RenewLastSeenAction, AppThunk } from './types'
import * as WebSocket from 'ws'
import { BoardBase, BoardPiece } from '@kenrick95/c4/src/board'
import { BoardBase, BoardPiece } from '@kenrick95/c4'
import {
MESSAGE_TYPE,
constructMessage,
} from '@kenrick95/c4/src/game/game-online/shared'
} from '@kenrick95/c4'

export enum ACTION_TYPE {
NEW_PLAYER_CONNECTION = 'NEW_PLAYER_CONNECTION',
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/board.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { BoardBase } from '@kenrick95/c4/src/board'
import { BoardBase } from '@kenrick95/c4'

export class ServerBoard extends BoardBase {}
4 changes: 2 additions & 2 deletions server/src/game/game.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ServerBoard } from './board'
import { GameBase } from '@kenrick95/c4/src/game'
import { GameBase } from '@kenrick95/c4'
import { ServerPlayer } from './player'
import { MatchId } from '../types'
import { BoardPiece } from '@kenrick95/c4/src/board'
import { BoardPiece } from '@kenrick95/c4'
import { store } from '..'
import { gameEnded } from '../actions'

Expand Down
4 changes: 2 additions & 2 deletions server/src/game/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BoardPiece } from '@kenrick95/c4/src/board'
import { PlayerShadow } from '@kenrick95/c4/src/player'
import { BoardPiece } from '@kenrick95/c4'
import { PlayerShadow } from '@kenrick95/c4'
import { PlayerId } from '../types'

export class ServerPlayer extends PlayerShadow {
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MatchId, State, ActionTypes } from './types'
import {
MESSAGE_TYPE,
parseMessage,
} from '@kenrick95/c4/src/game/game-online/shared'
} from '@kenrick95/c4'

const port = parseInt(process.env.PORT || '') || 8080
const wss = new WebSocket.Server({ port: port })
Expand Down
2 changes: 1 addition & 1 deletion server/src/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { State, ActionTypes } from './types'
import { ACTION_TYPE } from './actions'
import { BoardPiece } from '@kenrick95/c4/src/board'
import { BoardPiece } from '@kenrick95/c4'
import { ServerGame } from './game/game'
import { ServerPlayer } from './game/player'
import { ServerBoard } from './game/board'
Expand Down
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"target": "es2017",
"strict": true
},
"include": ["@kenrick95/c4", "src/"],
"include": ["src/"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Loading