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/.github/workflows/test.yml b/.github/workflows/test.yml index 968afa2..1c263fc 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 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/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. - diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..05a69c7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +# 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} + REDIS_URL: redis://redis:6379 + +services: + dev: + build: . + command: npm run start:dev + ports: + - "4000:4000" + depends_on: + - redis + environment: + <<: *common-server-environment + volumes: + - .:/usr/src/app + + app-integration-test: + build: . + command: npm run start:dev integration-testing + ports: + - "4000:4000" + depends_on: + - redis + environment: + <<: *common-server-environment + + volumes: + - .:/usr/src/app + + test: + build: . + command: npm run test + depends_on: + - redis + environment: + <<: *common-server-environment + + volumes: + - .:/usr/src/app + redis: + image: redis:alpine + ports: + - "6379:6379" 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 bd50fbd..d8ef7ca 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", @@ -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() {