-
Notifications
You must be signed in to change notification settings - Fork 27
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
Set up Docker env for local development #27
base: master
Are you sure you want to change the base?
Changes from 4 commits
673ef86
2a1ea84
3f3a915
bb2fc45
f4b316c
564ff3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Include any files or directories that you don't want to be copied to your | ||
# container here (e.g., local build artifacts, temporary files, etc.). | ||
# | ||
# For more help, visit the .dockerignore file reference guide at | ||
# https://docs.docker.com/go/build-context-dockerignore/ | ||
|
||
**/.build | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/.next | ||
**/.cache | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/charts | ||
**/docker-compose* | ||
**/compose.y*ml | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
**/build | ||
**/dist | ||
LICENSE | ||
README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
.dist | ||
.eslintcache | ||
config/* | ||
.DS_Store | ||
.DS_Store | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Comments are provided throughout this file to help you get started. | ||
# If you need more help, visit the Dockerfile reference guide at | ||
# https://docs.docker.com/go/dockerfile-reference/ | ||
|
||
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 | ||
|
||
ARG NODE_VERSION=20.10.0 | ||
|
||
################################################################################ | ||
# Use node image for base image for all stages. | ||
FROM node:${NODE_VERSION}-alpine as base | ||
|
||
# Set working directory for all build stages. | ||
WORKDIR /usr/src/app | ||
|
||
|
||
################################################################################ | ||
# Create a stage for installing production dependecies. | ||
FROM base as deps | ||
|
||
# Download dependencies as a separate step to take advantage of Docker's caching. | ||
# Leverage a cache mount to /root/.npm to speed up subsequent builds. | ||
# Leverage bind mounts to package.json and package-lock.json to avoid having to copy them | ||
# into this layer. | ||
RUN --mount=type=bind,source=package.json,target=package.json \ | ||
--mount=type=bind,source=package-lock.json,target=package-lock.json \ | ||
--mount=type=cache,target=/root/.npm \ | ||
npm ci --omit=dev | ||
|
||
################################################################################ | ||
# Create a stage for building the application. | ||
FROM deps as build | ||
|
||
# Download additional development dependencies before building, as some projects require | ||
# "devDependencies" to be installed to build. If you don't need this, remove this step. | ||
RUN --mount=type=bind,source=package.json,target=package.json \ | ||
--mount=type=bind,source=package-lock.json,target=package-lock.json \ | ||
--mount=type=cache,target=/root/.npm \ | ||
npm ci | ||
|
||
# Copy the rest of the source files into the image. | ||
COPY . . | ||
|
||
# Run the build script. | ||
RUN npm run build | ||
|
||
################################################################################ | ||
# Create a new stage to run the application with minimal runtime dependencies | ||
# where the necessary files are copied from the build stage. | ||
FROM base as final | ||
|
||
# Use production node environment by default. | ||
ENV NODE_ENV production | ||
|
||
# Run the application as a non-root user. | ||
USER node | ||
|
||
# Copy package.json so that package manager commands can be used. | ||
COPY package.json . | ||
|
||
# Copy the production dependencies from the build stage and also | ||
# the built application from the build stage into the image. | ||
COPY --from=build /usr/src/app/node_modules ./node_modules | ||
COPY --from=build /usr/src/app/.dist ./.dist | ||
|
||
# Use default configuration files for loginserver | ||
ADD config/pm2-example.js ./config/pm2.config.js | ||
ADD config/config-example.js ./config/config.js | ||
|
||
# Add some necessary source files | ||
ADD src/public ./src/public | ||
|
||
# Expose the port that the application listens on. | ||
EXPOSE 8080 | ||
|
||
# Run the application. | ||
CMD npm run start-on-docker && npx pm2 logs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM cockroachdb/cockroach:latest as base | ||
COPY src/schemas/replays.sql /docker-entrypoint-initdb.d/0_replays.sql | ||
COPY src/schemas/dummydata/replays.sql /docker-entrypoint-initdb.d/1_replays.sql | ||
COPY src/schemas/dummydata/replays.csv src/schemas/dummydata/replays.csv | ||
CMD ["start-single-node", "--insecure"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
### Building and running your application | ||
|
||
When you're ready, start your application by running: | ||
`docker compose up --build`. | ||
|
||
Your application will be available at http://localhost:8080. | ||
|
||
### Deploying your application to the cloud | ||
|
||
First, build your image, e.g.: `docker build -t myapp .`. | ||
If your cloud uses a different CPU architecture than your development | ||
machine (e.g., you are on a Mac M1 and your cloud provider is amd64), | ||
you'll want to build the image for that platform, e.g.: | ||
`docker build --platform=linux/amd64 -t myapp .`. | ||
|
||
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. | ||
|
||
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) | ||
docs for more detail on building and pushing. | ||
|
||
### References | ||
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
services: | ||
pokemon-showdown-loginserver: | ||
build: | ||
context: . | ||
environment: | ||
NODE_ENV: production | ||
ports: | ||
- 8080:8080 | ||
depends_on: | ||
replay-db: | ||
condition: service_healthy | ||
develop: | ||
watch: | ||
- action: rebuild | ||
path: . | ||
replay-db: | ||
restart: always | ||
hostname: replaysdb | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.replays | ||
healthcheck: | ||
test: curl --request GET --url 'http://localhost:8080/api/v2/health/?ready=True' | ||
interval: 1m30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 40s | ||
start_interval: 5s | ||
develop: | ||
watch: | ||
- action: rebuild | ||
path: src/schemas |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -904,7 +904,16 @@ export const actions: {[k: string]: QueryHandler} = { | |||||
} | ||||||
return {password: pw}; | ||||||
}, | ||||||
|
||||||
async 'replays/batch.json'(params) { | ||||||
if (!params.ids) { | ||||||
throw new ActionError("Invalid batch replay request, must provide ids"); | ||||||
} | ||||||
const ids: string[] = params.ids.split(','); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably this should be programatically capped in length here in addition to the query. |
||||||
const results = await Replays.getBatch(ids); | ||||||
console.log(params, ids, results); | ||||||
this.response.setHeader('Content-Type', 'application/json'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is already handled by the loginserver under the hood. |
||||||
return JSON.stringify(results); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is also handled by the loginserver under the hood. |
||||||
}, | ||||||
// sent by ps server | ||||||
async 'smogon/validate'(params) { | ||||||
if (this.getIp() !== Config.restartip) { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -233,6 +233,18 @@ | |||||||||
SQL`uploadtime, id, format, players, rating` | ||||||||||
)`WHERE private = 0 ORDER BY uploadtime DESC LIMIT 51`.then(this.toReplays); | ||||||||||
} | ||||||||||
|
||||||||||
Check failure on line 236 in src/replays.ts GitHub Actions / build (16.x)
|
||||||||||
getBatch(ids: string[]) { | ||||||||||
let idsForQuery = ''; | ||||||||||
for (var i = 0; i < ids.length; i++) { | ||||||||||
Check failure on line 239 in src/replays.ts GitHub Actions / build (16.x)
|
||||||||||
const id = ids[i]; | ||||||||||
idsForQuery += `'${id}'`; | ||||||||||
if (i !== ids.length - 1) idsForQuery += ","; | ||||||||||
} | ||||||||||
return replays.selectAll( | ||||||||||
SQL`*` | ||||||||||
)`WHERE private = 0 AND id IN (${idsForQuery}) LIMIT 51`.then(this.toReplays); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is only necessary if you're not selecting |
||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
export default Replays; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strike the .json from the name, for loginserver APIs we don't use that.