From 2dd91c98853cd0dab9ad065f2ce1ced86f4a1ee0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:31:12 -0700 Subject: [PATCH 01/15] add docker compose file and dockerignore --- .dockerignore | 4 ++++ docker-compose.yml | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .dockerignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bac6d50 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +Dockerfile +.dockerignore diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..01bc4cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + dev: + build: + context: . + dockerfile_inline: | + FROM node:20-alpine + WORKDIR /usr/src/app + COPY package*.json ./ + RUN npm install + COPY . . + EXPOSE 3000 + RUN npm run start:dev + ports: + - "3000:3000" + env_file: .env + depends_on: + - redis + volumes: + - .:/usr/src/app + redis: + image: redis:alpine + ports: + - "6379:6379" From f2a464d52d06a874a029da80ccee481e65a1e51b Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:45:26 -0700 Subject: [PATCH 02/15] fix the inline dockerfile to use cmd instead of run, and update port --- docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 01bc4cc..a256aab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,12 +6,12 @@ services: FROM node:20-alpine WORKDIR /usr/src/app COPY package*.json ./ - RUN npm install + RUN npm install --include=dev COPY . . - EXPOSE 3000 - RUN npm run start:dev + EXPOSE 4000 + CMD ["npm", "run", "start:dev"] ports: - - "3000:3000" + - "4000:4000" env_file: .env depends_on: - redis From 66642e7050c6ea3f4df0f2c5fef6a3e58732f732 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:50:47 -0700 Subject: [PATCH 03/15] simplify the dockerfile and move it to a separate file --- Dockerfile | 4 ++++ docker-compose.yml | 12 ++---------- 2 files changed, 6 insertions(+), 10 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ffcd621 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM node:20-alpine +WORKDIR /usr/src/app +COPY . . +EXPOSE 4000 diff --git a/docker-compose.yml b/docker-compose.yml index a256aab..8eb1f0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,7 @@ services: dev: - build: - context: . - dockerfile_inline: | - FROM node:20-alpine - WORKDIR /usr/src/app - COPY package*.json ./ - RUN npm install --include=dev - COPY . . - EXPOSE 4000 - CMD ["npm", "run", "start:dev"] + build: . + command: npm run start:dev ports: - "4000:4000" env_file: .env From 4990e65c3ef0a99045d4c512d7b0dce1df396d51 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:53:39 -0700 Subject: [PATCH 04/15] add testing workflow and update package.json --- docker-compose.yml | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8eb1f0a..3211f0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,14 @@ services: - redis volumes: - .:/usr/src/app + test: + build: . + command: npm run test + env_file: .env + depends_on: + - redis + volumes: + - .:/usr/src/app redis: image: redis:alpine ports: diff --git a/package.json b/package.json index bd50fbd..1addfcc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start:dev": "npm run build:dev && node ./dist/index.js", "start": "npm run build && node ./dist/index.js", "generate": "graphql-codegen --config codegen.ts", - "test": "jest" + "test": "npm run build:dev && jest" }, "devDependencies": { "@graphql-codegen/cli": "5.0.3", From 892ca7ec63747f2e71544b78f693596809093977 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:53:46 -0700 Subject: [PATCH 05/15] update github actions to use docker --- .github/workflows/test.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 968afa2..8060f4d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,21 +7,11 @@ on: branches: [ "main" ] jobs: - build: - + test: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [20.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm run build:dev - - run: npm run test + + - name: Build and test with Docker Compose + run: docker-compose run test From b442cdda21dc84280025afca18fe1265cd49131d Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 15:55:24 -0700 Subject: [PATCH 06/15] add app integration testing workflow --- docker-compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 3211f0f..a3153d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,18 @@ services: - redis volumes: - .:/usr/src/app + + app-integration-test: + build: . + command: npm run start:dev integration-testing + ports: + - "4000:4000" + env_file: .env + depends_on: + - redis + volumes: + - .:/usr/src/app + test: build: . command: npm run test From 299bcfcf188e899e064c2a3ac856253ed4eab745 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 16:00:03 -0700 Subject: [PATCH 07/15] update docker command for compose build --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8060f4d..2d8680b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,8 @@ jobs: runs-on: ubuntu-latest steps: + - - uses: actions/checkout@v4 - name: Build and test with Docker Compose - run: docker-compose run test + run: docker compose run test From e12a9817ffad9fd17f0b74bcba031ce87a8529e2 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 16:00:15 -0700 Subject: [PATCH 08/15] remove extra - --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d8680b..1c263fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,6 @@ jobs: runs-on: ubuntu-latest steps: - - - uses: actions/checkout@v4 - name: Build and test with Docker Compose From 25f9dd62b189a946e845af36375fc152f16ea195 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 26 Mar 2025 16:06:00 -0700 Subject: [PATCH 09/15] remove .env file from testing and app-integration-test flows --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a3153d6..d6d823c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,12 +10,14 @@ services: volumes: - .:/usr/src/app + # Note that neither app-integration-test or test modes require env variables, + # need to find a way to pass variables without .env if this changes + app-integration-test: build: . command: npm run start:dev integration-testing ports: - "4000:4000" - env_file: .env depends_on: - redis volumes: @@ -24,7 +26,6 @@ services: test: build: . command: npm run test - env_file: .env depends_on: - redis volumes: From 829b3f4ffd14ee24a15ab17fbeb41751a5fa3f4e Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:26:44 -0700 Subject: [PATCH 10/15] load each environment variable automatically from the env file --- docker-compose.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d6d823c..bdd0ec4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,29 @@ +# Note that .env file will automatically populate +# variables in this file. +# If these variables are also set on the host system, +# those will be used over the .env file. +# See https://vsupalov.com/docker-arg-env-variable-guide/ + +x-common-environment: &common-server-environment + APNS_IS_PRODUCTION: ${APNS_IS_PRODUCTION} + APNS_BUNDLE_ID: ${APNS_BUNDLE_ID} + APNS_TEAM_ID: ${APNS_TEAM_ID} + APNS_KEY_ID: ${APNS_KEY_ID} + APNS_PRIVATE_KEY: ${APNS_PRIVATE_KEY} + services: dev: build: . command: npm run start:dev ports: - "4000:4000" - env_file: .env depends_on: - redis + environment: + <<: *common-server-environment volumes: - .:/usr/src/app - # Note that neither app-integration-test or test modes require env variables, - # need to find a way to pass variables without .env if this changes - app-integration-test: build: . command: npm run start:dev integration-testing @@ -20,6 +31,9 @@ services: - "4000:4000" depends_on: - redis + environment: + <<: *common-server-environment + volumes: - .:/usr/src/app @@ -28,6 +42,9 @@ services: command: npm run test depends_on: - redis + environment: + <<: *common-server-environment + volumes: - .:/usr/src/app redis: From 83cf38ed916aa6464a686f3895b7cc2bb5f7da51 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:27:14 -0700 Subject: [PATCH 11/15] remove dotenv --- package-lock.json | 2 +- package.json | 1 - src/index.ts | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index d9b0220..4d485f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "dependencies": { "@apollo/server": "^4.11.2", - "dotenv": "^16.4.7", "graphql": "^16.10.0", "jsonwebtoken": "^9.0.2" }, @@ -4857,6 +4856,7 @@ "version": "16.4.7", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, "engines": { "node": ">=12" }, diff --git a/package.json b/package.json index 1addfcc..d8ef7ca 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "private": true, "dependencies": { "@apollo/server": "^4.11.2", - "dotenv": "^16.4.7", "graphql": "^16.10.0", "jsonwebtoken": "^9.0.2" } diff --git a/src/index.ts b/src/index.ts index 88f4c61..2bff64c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,12 +6,9 @@ import { ServerContext } from "./ServerContext"; import { UnoptimizedInMemoryRepository } from "./repositories/UnoptimizedInMemoryRepository"; import { TimedApiBasedRepositoryLoader } from "./loaders/TimedApiBasedRepositoryLoader"; import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler"; -import { configDotenv } from "dotenv"; import { loadTestData } from "./loaders/loadTestData"; import { AppleNotificationSender } from "./notifications/senders/AppleNotificationSender"; -configDotenv(); - const typeDefs = readFileSync("./schema.graphqls", "utf8"); async function main() { From bef93538fbe4f86f1895eaf53f65374a2b1b7867 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:28:52 -0700 Subject: [PATCH 12/15] test that failing test breaks ci --- test/sum.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sum.test.ts b/test/sum.test.ts index 5643f10..ec3d022 100644 --- a/test/sum.test.ts +++ b/test/sum.test.ts @@ -2,6 +2,6 @@ import { describe, expect, test } from "@jest/globals"; describe("sum", () => { test("adds 1 + 2 to equal 3", () => { - expect(1 + 2).toBe(3); + expect(1 + 2).toBe(4); }); -}); \ No newline at end of file +}); From cb65cd49f39cb790268ce6651d168991e2a2dc5c Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:30:23 -0700 Subject: [PATCH 13/15] Revert "test that failing test breaks ci" This reverts commit bef93538fbe4f86f1895eaf53f65374a2b1b7867. --- test/sum.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sum.test.ts b/test/sum.test.ts index ec3d022..5643f10 100644 --- a/test/sum.test.ts +++ b/test/sum.test.ts @@ -2,6 +2,6 @@ import { describe, expect, test } from "@jest/globals"; describe("sum", () => { test("adds 1 + 2 to equal 3", () => { - expect(1 + 2).toBe(4); + expect(1 + 2).toBe(3); }); -}); +}); \ No newline at end of file From e880830e0257a61c4c0b8eb8e005cb1f70ff135a Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:42:46 -0700 Subject: [PATCH 14/15] add redis URL to docker compose --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index bdd0ec4..05a69c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ x-common-environment: &common-server-environment APNS_TEAM_ID: ${APNS_TEAM_ID} APNS_KEY_ID: ${APNS_KEY_ID} APNS_PRIVATE_KEY: ${APNS_PRIVATE_KEY} + REDIS_URL: redis://redis:6379 services: dev: From de4cfaaa8d8d0fd74aaea271dbd624f5267dabcd Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 27 Mar 2025 08:46:53 -0700 Subject: [PATCH 15/15] update README --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4f65872..a5bb372 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -# Interchange Node.js Server +# Interchange Server -This is the server codebase for Interchange, an app for college -transit. +This is the server codebase for Interchange, an app for college transit. ## Setup -You'll need Node.js 20.x installed to run this project. -Clone this repository and run the following: +You'll need Docker + Compose installed to run this project. +Clone this repository and run one of the following: ```bash -$ npm start:dev +# run the standard Node development server and Redis +$ docker compose run dev + +# run with unit/server integration tests +$ docker compose run test + +# run with test data suitable for app integration tests +$ docker compose run app-integration-tests ``` - -This will run `npm install`, generate GraphQL type definitions, -and start the server in developer mode. -