Skip to content
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

feat: add initial setup for config, GraphQL, Prisma, TypeScript, ESLint and Jest #1

Merged
merged 17 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
HTTP_PORT=3000
PG_USER=
PG_PASSWORD=
PG_DB=

HTTP_PORT=
HTTP_DOMAIN=
HTTP_SCHEME=https
HTTP_SCHEME=

GRAPHQL_INTROSPECTION_ENABLED=
35 changes: 35 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Validate TypeScript & check code formatting

# Triggered when code is pushed to any branch in a repository
on:
push:
workflow_dispatch:

# https://twitter.com/adamchainz/status/1485572084617121796?s=21
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"

- name: Install Dependencies
run: npm ci # npm ci is a CI environment specific installer https://stackoverflow.com/a/53325242

- name: Validate TypeScript
run: npm run ts:lint

- name: ESLint
run: npm run lint
27 changes: 0 additions & 27 deletions .github/workflows/lint.yml

This file was deleted.

31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:16-alpine as base

WORKDIR /var/app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build
RUN npx prisma generate

# Production step

FROM node:16-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /var/app

COPY package*.json ./

RUN npm install --production

COPY . .

COPY --from=base /var/app/dist ./dist

ENTRYPOINT ["nodemon", "/var/app/dist/server.js"]
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Sample Project]
# Fueled Assignment

[@TODO: add project description here]
This repo contains the starter code for Fueled Assignment in NodeJS + TypeScript. Using Postgres as the primary database.

## Requirements

Expand All @@ -19,9 +19,45 @@

## Get Started

The following will install all necessary packages and run the app under development mode which uses `nodemon` for reloading the build when changes are made.

```
npm install
npm run start
npm run dev
```

## Docker Local

A Dockerfile is available to run the backend services in a container exposed through ports. The Docker container
includes the hot reloading Node application, PostgresSQL database, and Redis for caching.

The three services are available under the following:

```
app: fueled_assignment
fueled_assignment_app // Node application
fueled_assignment_redis // Redis server
fueled_assignment_postgres // PostgreSQL database
```

To build and run the Docker container, ensure you have the Docker CLI available, and optionally Docker Desktop.

To build the Docker container:

```
docker compose build
```

To start the Docker container:

```
docker compose up
```

To stop the Docker container:

```
docker compose down
```

## ESLint
Expand All @@ -44,3 +80,4 @@ npm run lint // runs only ESLint
Notice that ESLint is not a part of the main watch task.

If you are interested in seeing ESLint feedback as soon as possible, I strongly recommend the [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: "3.9"

services:
app:
build:
context: .
dockerfile: ./Dockerfile
target: base
volumes:
- ".:/var/app"
expose:
- "8000"
ports:
- "8000:8000"
depends_on:
- postgres
environment:
- DATABASE_URL=postgres://postgres:${PG_USER}@${PG_PASSWORD}/${PG_DB}

postgres:
image: postgres:14
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${PG_DB}
- POSTGRES_USER=${PG_USER}
- POSTGRES_PASSWORD=${PG_PASSWORD}
ports:
- "5432:5432"
networks:
- app_network

redis:
image: redis:latest
networks:
- app_network

networks:
app_network:

volumes:
pgdata:
Loading