Skip to content

Commit

Permalink
some more v0.2.0 (#19)
Browse files Browse the repository at this point in the history
* deleted v1 desktop + api v1

* api v2 + integrated google auth + toasters

* added tests + logout implementation

* fix for build

* add infisical + some contributions stuff

* add ci

* implemented create task and list tasks in api + app

* implemented update task

* implemented delete task

* implemented toggle complete task

* use pnpm in ci

* correctly use pnpm in ci

* install types for passport

* some fixes + create task placeholder for ease of use

* added dockerfile

* added railway.toml + some logging

* remove tests in CI for now
  • Loading branch information
vuvincent authored Sep 16, 2023
1 parent 74867ca commit 046f342
Show file tree
Hide file tree
Showing 281 changed files with 6,156 additions and 12,990 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/node_modules
node_modules/
fly.toml
Dockerfile
.dockerignore
.git
out
46 changes: 46 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CD

on:
push:
branches:
- main

jobs:
migrate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 7
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Run migrations to prod DB
run: pnpm db:migrate
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}

50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 7
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Lint code
run: pnpm lint

- name: Build
run: pnpm build
5 changes: 5 additions & 0 deletions .infisical.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workspaceId": "65009d2c9296eef8d1b241a6",
"defaultEnvironment": "",
"gitBranchToEnvironmentMapping": null
}
21 changes: 13 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,40 @@ To develop locally:

```sh
pnpm i
pnpm install:desktop
pnpm install:api
```

5. Create environment files

- For the API, you need to configure the `.env` file. You can copy the example file and edit it. Mostly you need to configure the database connection. Default values of those are in `apps/api/docker-compose.yml`:

```sh
cp .env.example .env
cp apps/api-v2/.env.example apps/api-v2/.env
// then edit .env for the database connection variables as specified
// see docker-compose.yml
```

6. Start developing and watch for code changes:

- For the API, you need to run infra pieces that the project depends locally (e.g the main MySQL database), then run the migrations on the database. Make sure you have Docker installed and running, then run:
- For the API, you need to run infra pieces that the project depends locally (e.g the main MySQL database), then run the migrations on the database. Make sure you have Docker installed and running, then at the project root, run:

```sh
pnpm db:start
pnpm db:migrate
pnpm db:setup
```

Then run the API:

```sh
pnpm run dev:api
pnpm dev:api
```

- For the desktop, just do:

```sh
pnpm dev:desktop
```

- or if you like both:

## Building

You can build the entire project with:
Expand All @@ -86,7 +91,7 @@ More info on how to add new tests coming soon.
To check the formatting of your code:

```sh
yarn lint
pnpm lint
```

If you get errors, be sure to fix them before committing.
Expand Down
5 changes: 5 additions & 0 deletions apps/api-v2/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
fly.toml
Dockerfile
.dockerignore
.git
4 changes: 4 additions & 0 deletions apps/api-v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
dist/
60 changes: 60 additions & 0 deletions apps/api-v2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM node:18-alpine AS base

RUN corepack enable && corepack prepare pnpm@latest --activate
# Enable `pnpm add --global` on Alpine Linux by setting
# home location environment variable to a location already in $PATH
# https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235
ENV PNPM_HOME=/usr/local/bin
ENV PATH="${PATH}:${PNPM_HOME}"
RUN pnpm add --global turbo

# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.

FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
COPY . .
RUN turbo prune --scope=api-v2 --docker
# remove all empty node_modules folder structure
RUN rm -rf /app/out/full/*/*/node_modules
RUN ls -l /app

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

# First install dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm i

# # Build the project and its dependencies
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json

# Uncomment and use build args to enable remote caching
# ARG TURBO_TEAM
# ENV TURBO_TEAM=$TURBO_TEAM

# ARG TURBO_TOKEN
# ENV TURBO_TOKEN=$TURBO_TOKEN

RUN turbo run build --filter=api-v2...

FROM base AS runner
WORKDIR /app

# Don't run production as root
RUN addgroup --system --gid 1001 expressjs
RUN adduser --system --uid 1001 expressjs
USER expressjs
COPY --from=installer /app .

CMD node apps/api-v2/dist/index.js
File renamed without changes.
10 changes: 10 additions & 0 deletions apps/api-v2/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
62 changes: 62 additions & 0 deletions apps/api-v2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "api-v2",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "jest --forceExit",
"pretest": "npm run setup",
"start": "node dist/index.js",
"build": "tsup src/index.ts --format cjs --minify --clean",
"prebuild": "npm run clean && npm run schema:generate",
"clean": "rm -rf dist",
"predev": "npm run db:start",
"dev": "NODE_ENV=development tsx src/index.ts",
"db:diff": "prisma migrate dev",
"db:migrate": "prisma migrate deploy",
"schema:generate": "prisma generate",
"db:start": "docker-compose up -d",
"db:setup": "npm run db:start && npm run db:migrate"
},
"keywords": [],
"author": "Vincent Vu <[email protected]>",
"license": "ISC",
"devDependencies": {
"@supernova/types": "workspace:*",
"@types/cookie-parser": "^1.4.4",
"@types/cors": "^2.8.14",
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.7",
"@types/jest": "^29.5.4",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "^20.6.0",
"@types/passport": "^1.0.12",
"@types/passport-google-oauth20": "^2.0.11",
"@types/supertest": "^2.0.12",
"jest": "^29.6.4",
"jest-express": "^1.12.0",
"prisma": "^5.2.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"tsup": "^7.2.0",
"tsx": "^3.12.8",
"typescript": "5.1.6"
},
"dependencies": {
"@axiomhq/pino": "^0.1.3",
"@prisma/client": "5.2.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-session": "^1.17.3",
"jsonwebtoken": "^9.0.2",
"passport": "^0.6.0",
"passport-google-oauth20": "^2.0.0",
"pino": "^8.15.1",
"pino-http": "^8.5.0",
"pino-pretty": "^10.2.0",
"redis": "^4.6.8",
"znv": "^0.4.0",
"zod": "^3.22.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE `User` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`email` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NULL,

UNIQUE INDEX `User_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
*/
-- AlterTable
ALTER TABLE `User` DROP PRIMARY KEY,
MODIFY `id` VARCHAR(191) NOT NULL,
ADD PRIMARY KEY (`id`);
15 changes: 15 additions & 0 deletions apps/api-v2/prisma/migrations/20230910052218_tasks/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- CreateTable
CREATE TABLE `Task` (
`id` VARCHAR(191) NOT NULL,
`title` VARCHAR(191) NOT NULL,
`description` VARCHAR(191) NULL,
`done` BOOLEAN NOT NULL DEFAULT false,
`startAt` DATETIME(3) NULL,
`expectedDurationSeconds` INTEGER NULL,
`userId` VARCHAR(191) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Task` ADD CONSTRAINT `Task_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE `Task` DROP FOREIGN KEY `Task_userId_fkey`;

-- RenameIndex
ALTER TABLE `Task` RENAME INDEX `Task_userId_fkey` TO `owner_id_idx`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `originalBuildText` to the `Task` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `Task` ADD COLUMN `originalBuildText` VARCHAR(191) NOT NULL;
3 changes: 3 additions & 0 deletions apps/api-v2/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
Loading

1 comment on commit 046f342

@vercel
Copy link

@vercel vercel bot commented on 046f342 Sep 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.