mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:40:44 +00:00
add preprod, prod & dev config
This commit is contained in:
+4
-6
@@ -1,23 +1,21 @@
|
||||
# Use an official Node runtime as the base image
|
||||
FROM node:18
|
||||
|
||||
# Add environment variable
|
||||
ARG GAME_ENV=preprod
|
||||
ENV GAME_ENV=$GAME_ENV
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy package.json and package-lock.json
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy the rest of the application code
|
||||
COPY . .
|
||||
|
||||
# Build the client-side application
|
||||
RUN npm run build-prod
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 3000
|
||||
|
||||
# Define the command to run the app
|
||||
CMD ["npm", "run", "start:server"]
|
||||
+7
-6
@@ -1,12 +1,15 @@
|
||||
steps:
|
||||
# Build the Docker image
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: ['build', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/openfrontio/game-server:${TAG_NAME}-${SHORT_SHA}', '.']
|
||||
|
||||
args: [
|
||||
'build',
|
||||
'-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/openfrontio/game-server:${TAG_NAME}-${SHORT_SHA}',
|
||||
'--build-arg', 'GAME_ENV=${_GAME_ENV}',
|
||||
'.'
|
||||
]
|
||||
# Push the image to Artifact Registry
|
||||
- name: 'gcr.io/cloud-builders/docker'
|
||||
args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/openfrontio/game-server:${TAG_NAME}-${SHORT_SHA}']
|
||||
|
||||
# Update the GCE instance with the new container image
|
||||
- name: 'gcr.io/cloud-builders/gcloud'
|
||||
args:
|
||||
@@ -17,14 +20,12 @@ steps:
|
||||
- '--container-image'
|
||||
- 'us-central1-docker.pkg.dev/$PROJECT_ID/openfrontio/game-server:${TAG_NAME}-${SHORT_SHA}'
|
||||
- '--zone=us-central1-a'
|
||||
|
||||
substitutions:
|
||||
_INSTANCE_NAME: 'openfrontio-dev-instance'
|
||||
_GAME_ENV: 'preprod' # Default to preprod
|
||||
TAG_NAME: 'dev'
|
||||
|
||||
options:
|
||||
substitutionOption: 'ALLOW_LOOSE'
|
||||
logging: CLOUD_LOGGING_ONLY
|
||||
|
||||
images:
|
||||
- 'us-central1-docker.pkg.dev/$PROJECT_ID/openfrontio/game-server:${TAG_NAME}-${SHORT_SHA}'
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
"build-dev": "webpack --config webpack.config.js --mode development",
|
||||
"build-prod": "webpack --config webpack.config.js --mode production",
|
||||
"start:client": "webpack serve --open --node-env development",
|
||||
"start:server": "GAME_ENV=prod node --loader ts-node/esm --experimental-specifier-resolution=node src/server/Server.ts",
|
||||
"start:server": "node --loader ts-node/esm --experimental-specifier-resolution=node src/server/Server.ts",
|
||||
"start:server-dev": "GAME_ENV=dev node --loader ts-node/esm --experimental-specifier-resolution=node src/server/Server.ts",
|
||||
"dev": "GAME_ENV=dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
|
||||
"tunnel": "npm run build-prod && npm run start:server",
|
||||
@@ -94,4 +94,4 @@
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import { Colord, colord } from "colord";
|
||||
import { devConfig } from "./DevConfig";
|
||||
import { defaultConfig } from "./DefaultConfig";
|
||||
import { GameID } from "../Schemas";
|
||||
import { preprodConfig } from "./PreprodConfig";
|
||||
import { prodConfig } from "./ProdConfig";
|
||||
|
||||
export enum GameEnv {
|
||||
Dev,
|
||||
@@ -10,13 +12,18 @@ export enum GameEnv {
|
||||
}
|
||||
|
||||
export function getConfig(): Config {
|
||||
// TODO: 'prod' not found in prod env
|
||||
if (process.env.GAME_ENV == 'dev') {
|
||||
console.log('Using dev config')
|
||||
return devConfig
|
||||
} else {
|
||||
console.log('Using prod config')
|
||||
return defaultConfig
|
||||
switch (process.env.GAME_ENV) {
|
||||
case 'dev':
|
||||
console.log('using dev config')
|
||||
return devConfig
|
||||
case 'preprod':
|
||||
console.log('using preprod config')
|
||||
return preprodConfig
|
||||
case 'prod':
|
||||
console.log('using prod config')
|
||||
return prodConfig
|
||||
default:
|
||||
throw Error(`unsupported server configuration: ${process.env.GAME_ENV}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +32,7 @@ export function getGameEnv(): GameEnv {
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
discordBotSecret(): string
|
||||
theme(): Theme;
|
||||
percentageTilesOwnedToWin(): number
|
||||
turnIntervalMs(): number
|
||||
|
||||
@@ -6,7 +6,9 @@ import { pastelTheme } from "./PastelTheme";
|
||||
|
||||
|
||||
|
||||
export class DefaultConfig implements Config {
|
||||
export abstract class DefaultConfig implements Config {
|
||||
abstract discordBotSecret(): string
|
||||
|
||||
difficultyModifier(difficulty: Difficulty): number {
|
||||
switch (difficulty) {
|
||||
case Difficulty.Easy:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { DefaultConfig } from "./DefaultConfig";
|
||||
|
||||
export const preprodConfig = new class extends DefaultConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { DefaultConfig } from "./DefaultConfig";
|
||||
|
||||
export const prodConfig = new class extends DefaultConfig {
|
||||
|
||||
}
|
||||
+5
-6
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the --env flag is provided
|
||||
if [[ "$1" != "--env" ]]; then
|
||||
echo "Usage: $0 --env [dev|prod]"
|
||||
@@ -19,20 +18,22 @@ fi
|
||||
if [[ "$ENV" == "dev" ]]; then
|
||||
INSTANCE_NAME="openfrontio-dev-instance"
|
||||
TAG="dev"
|
||||
GAME_ENV="preprod" # Set game environment to preprod for dev
|
||||
echo "[DEV] Deploying to openfront.dev"
|
||||
else
|
||||
INSTANCE_NAME="openfrontio-instance"
|
||||
TAG="latest"
|
||||
GAME_ENV="prod" # Set game environment to prod for prod
|
||||
echo "[PROD] Deploying to openfront.io"
|
||||
fi
|
||||
|
||||
# Ensure you're authenticated with Google Cloud
|
||||
gcloud auth configure-docker us-central1-docker.pkg.dev
|
||||
|
||||
# Build the new Docker image
|
||||
docker build -t openfrontio .
|
||||
# Build the new Docker image with GAME_ENV build argument
|
||||
docker build --build-arg GAME_ENV=$GAME_ENV -t openfrontio .
|
||||
|
||||
# Tag the new image (use a version number or 'latest')
|
||||
# Tag the new image
|
||||
docker tag openfrontio us-central1-docker.pkg.dev/openfrontio/openfrontio/game-server:$TAG
|
||||
|
||||
# Push the new image to Google Container Registry
|
||||
@@ -40,9 +41,7 @@ docker push us-central1-docker.pkg.dev/openfrontio/openfrontio/game-server:$TAG
|
||||
|
||||
# Prune Docker system on the instance
|
||||
gcloud compute ssh $INSTANCE_NAME --zone us-central1-a --command 'docker system prune -f -a'
|
||||
|
||||
gcloud compute ssh $INSTANCE_NAME --zone us-central1-a --command 'docker kill $(docker ps -q)'
|
||||
|
||||
gcloud compute ssh $INSTANCE_NAME --zone us-central1-a --command 'docker rmi $(docker images -q) -f'
|
||||
|
||||
# Update the GCE instance with the new container image
|
||||
|
||||
Reference in New Issue
Block a user