Skip to content

Commit

Permalink
* Fix occasional "missing car" for /carsized
Browse files Browse the repository at this point in the history
* Improved README.md
* Improve build process
* Updated dependencies
  • Loading branch information
danthonywalker committed Dec 17, 2023
1 parent 60d6caf commit 43c3194
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 400 deletions.
34 changes: 7 additions & 27 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
/.env
/LICENSE
/README.md
/build
/dump.sql
/flyway

# Docker
/.dockerignore
/Dockerfile
/docker-compose.yml

# Git
/.git
/.gitignore

# GitHub
/.github

# JetBrains
/.idea

# Node.js
/node_modules

# Prettier
/.prettierignore
# Ignore everything
**
# except
!/src
!/.eslint*
!/package*.json
!/tsconfig.json
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# ESLint
/.eslintrc.js
**/*.js
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
"plugin:sonarjs/recommended",
"plugin:unicorn/recommended",
],
ignorePatterns: ["/build/*"],
parserOptions: {
ecmaVersion: "latest",
parser: "@typescript-eslint/parser",
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.env
/.env*
/build
/dump.sql

Expand Down
12 changes: 0 additions & 12 deletions .prettierignore

This file was deleted.

28 changes: 16 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
FROM node:20.8.0

FROM node:20.8.0 as base
WORKDIR /pedestrian

# Express port
EXPOSE 8080

# Install Chrome dependencies for puppeteer
RUN apt-get update \
&& apt-get install -y wget gnupg \
Expand All @@ -20,17 +15,26 @@ RUN apt-get update \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /pedestrian

# Run everything after as puppeteer
# Use puppeteer user for Chrome sandbox
USER pptruser

COPY package*.json ./

FROM base as build
# Install runtime and build dependencies
RUN npm ci

# Copy source code into current image
COPY . .

RUN npm run check \
# Test source code
RUN npm test \
# Build source code
&& npm run build

FROM base
# Install runtime dependencies
RUN npm ci --omit=dev
# Copy built source code into current image
COPY --from=build /pedestrian/build ./build
# Expose port used by Express
EXPOSE 8080

CMD npm run production
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ A custom bot designed for [The Anti-Car Collective](https://discord.gg/anticar)

## Development

[Node.js](https://nodejs.org) and [docker-compose](https://docs.docker.com/compose) is required for development.
### Requirements

Required [environment variables](#environment-variables) must be configured in a `.env` file at the project's root to start (`npm run start`).

It is recommended to dump (`npm run dump`) the database before migrating (`npm run migrate`) in case restoring (`npm run restore`) is required.

Code must pass minimum quality standards checks (`npm run check`) to be merged:

- [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) must not emit any errors
- [ESLint](https://eslint.org) must not emit any errors
- Must be formatted with [Prettier](https://prettier.io) (`npm run prettier`)
- [Node.js](https://nodejs.org)
- [docker-compose](https://docs.docker.com/compose)

### Environment Variables

Required environment variables must be configured in a `.env` file at the project's root. While [debugging](#debugging), additional environment variables can be configured in a `.env.debug` file at the project's root; for example, setting `REDIS_HOST` and `POSTGRESQL_HOST` to `localhost` is a common debug requirement.

| Environment Variable | Required | Default Value | Notes |
| -------------------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------ |
| BOT_GUILD_ID || | Guild ID to enable `/bot` |
| DISCORD_TOKEN || | [Create Discord Token](https://discord.com/developers/docs/getting-started#configuring-your-bot) |
| ENABLE_CARSIZED || false | IIF value is "true" then `/carsized` is enabled |
| ENABLE_CARSIZED || | IIF value is `true` then `/carsized` is enabled |
| EXPRESS_PORT || 8080 | |
| POSTGRESQL_HOST || postgres | |
| POSTGRESQL_PORT || 5432 | |
Expand All @@ -32,7 +27,32 @@ Code must pass minimum quality standards checks (`npm run check`) to be merged:
| PROJECT_NAME || Pedestrian | |
| REDIS_HOST || redis | |
| REDIS_PORT || 6379 | |
| REDIS_CLUSTER || false | IIF value is "true" then Redis will run in [cluster mode](https://redis.io/docs/management/scaling/) |
| REDIS_CLUSTER || | IIF value is `true` then Redis will run in [cluster mode](https://redis.io/docs/management/scaling/) |
| REDIS_USERNAME || | |
| REDIS_PASSWORD || | |
| YOUTUBE_API_KEY || | [Create YouTube API Key](https://console.cloud.google.com/apis/api/youtube.googleapis.com/credentials) |

### Quick Start

Simply run `npm start`! Assuming the above requirements are met, the project will automatically be built and deployed locally along with required dependencies and services.

### Debugging

Steps 1-3 is not required if the ask is already installed, updated, and/or running.

1. Run third-party services (`npm run services`)
2. Install dependencies (`npm install`)
3. Build project (`npm run build`)
4. Attach debugger while running `npm run debug`

### Database Migration

It is recommended to dump (`npm run dump`) the database before migrating (`npm run migrate`) in case restoring (`npm run restore`) is required.

### Pull Requests

Tests (`npm test`) must pass for any changes to be merged:

- [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) must not emit any errors
- [ESLint](https://eslint.org) must not emit any errors
- Must be formatted with [Prettier](https://prettier.io) (`npm run prettier`)
Loading

0 comments on commit 43c3194

Please sign in to comment.