Skip to content

Commit

Permalink
mv app to apps/ dir (#499)
Browse files Browse the repository at this point in the history
* mv app to apps/ dir

* migrate tooling to support apps/ dir

* start script to run migrations

* remove build:lib from ci

* appease ci

* add setup-test script, adjust ci

* rm build:lib patch

* fix local server build, load dotenv
  • Loading branch information
josefaidt authored Oct 14, 2023
1 parent c8782ce commit 5dfd86e
Show file tree
Hide file tree
Showing 169 changed files with 219 additions and 278 deletions.
4 changes: 0 additions & 4 deletions .git-hooks/commit-msg

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cypress.env.json
notes.md

/prisma/data
/.svelte-kit
/build

packages/**/build
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
/build
/.svelte-kit
build
.svelte-kit
/package
.env
.env.*
Expand Down
88 changes: 44 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
#syntax=docker/dockerfile:1.4
FROM --platform=linux/amd64 alpine as builder
# Download the static build of Litestream directly into the path & make it executable.
# This is done in the builder and copied as the chmod doubles the size.
ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.8/litestream-v0.3.8-linux-amd64-static.tar.gz /tmp/litestream.tar.gz
RUN tar -C /usr/local/bin -xzf /tmp/litestream.tar.gz
ARG NODE_VERSION="18.15.0"
ARG ALPINE_VERSION="3.17"
FROM --platform=linux/amd64 node:${NODE_VERSION}-alpine${ALPINE_VERSION} as base
ENV CI=true
# for turbo - https://turbo.build/repo/docs/handbook/deploying-with-docker#example
RUN apk add --no-cache libc6-compat curl
RUN apk update
WORKDIR /workspace
# enable corepack for pnpm
RUN corepack enable

FROM --platform=linux/amd64 node:18-alpine
WORKDIR /usr/src

# @todo - remove this after upgrading prisma to ~4.8.0
# https://github.com/prisma/prisma/issues/16553#issuecomment-1353302617
RUN apk add --update --no-cache openssl1.1-compat

# Copy executable & Litestream from builder.
COPY --from=builder /usr/local/bin/litestream /usr/local/bin/litestream
# Copy litestream config
COPY scripts/litestream.yml /etc/litestream.yml

# add bash
RUN apk add bash

# Create data directory (although this will likely be mounted too)
RUN mkdir -p /data

# Install pnpm
ARG PNPM_VERSION=7.9.5
RUN npm install --global pnpm@${PNPM_VERSION}
FROM base as fetcher
# pnpm fetch only requires lockfile, but we'll need to build workspaces
COPY pnpm*.yaml ./
# RUN pnpm fetch
# add project source to build
ADD . .
# install dependencies
RUN pnpm install --frozen-lockfile
# expose arguments for VITE environment variables
ARG VITE_HOST=http://localhost:3000
ARG VITE_NEXTAUTH_URL=http://localhost:3000
ARG VITE_DISCORD_GUILD_ID=976838371383083068
ARG DATABASE_URL="file:/data/sqlite.db"
# expose necessary env vars
ENV PORT=3000
# run build
RUN pnpm run build:lib && pnpm run build
# install production dependencies
RUN pnpm install --frozen-lockfile --prod --ignore-scripts
COPY patches ./patches
# mount pnpm store as cache & fetch dependencies
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm-store \
pnpm fetch --ignore-scripts

FROM fetcher as builder
ARG APP_NAME="@aws-amplify/discord-bot-frontend"
ENV APP_NAME=${APP_NAME}
WORKDIR /workspace
COPY . .
RUN --mount=type=secret,id=env,required=true,target=/workspace/.env \
pnpm install --frozen-lockfile --offline --loglevel=error
# build workspace
RUN --mount=type=secret,id=env,required=true,target=/workspace/.env \
--mount=type=cache,target=/workspace/node_modules/.cache \
pnpm run build

FROM builder as deployer
WORKDIR /workspace
# deploy app
RUN pnpm --filter ${APP_NAME} deploy --prod --ignore-scripts ./out

EXPOSE 3000
CMD ["./scripts/start.sh"]
FROM base as runner
WORKDIR /workspace
# Don't run production as root
RUN addgroup --system --gid 1001 amplifygroup
RUN adduser --system --uid 1001 amplifyuser
USER amplifyuser
# copy files needed to run the app
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/package.json .
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/node_modules/ ./node_modules
COPY --chown=amplifyuser:amplifygroup --from=deployer /workspace/out/build/ ./build
# start the app
CMD pnpm run start
2 changes: 2 additions & 0 deletions apps/discord-bot-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.svelte-kit
build
84 changes: 84 additions & 0 deletions apps/discord-bot-frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "@aws-amplify/discord-bot-frontend",
"version": "1.5.0-next.5",
"type": "module",
"scripts": {
"start": "sh ./scripts/start.sh",
"start-server": "node ./build/index.js",
"dev": "vite",
"build": "pnpm run build-app && pnpm run build-server",
"build-app": "vite build",
"build-server": "node scripts/build-server.cjs",
"test": "playwright test",
"setup-dev": "prisma db push",
"setup-test": "DATABASE_URL=\"file:data/test.db\" prisma db push",
"postinstall": "prisma generate; playwright install",
"preview": "vite preview --port 3000",
"seed": "vite-node ./scripts/seed.ts",
"prepare": "svelte-kit sync"
},
"dependencies": {
"@auth/core": "^0.15.2",
"@auth/sveltekit": "^0.3.6",
"@aws-crypto/sha256-js": "^2.0.1",
"@carbon/styles": "^1.11.0",
"@discordjs/builders": "^1.1.0",
"@discordjs/rest": "^1.0.1",
"@faker-js/faker": "^7.4.0",
"@next-auth/prisma-adapter": "^1.0.4",
"@octokit/auth-app": "^4.0.5",
"@octokit/graphql": "^5.0.1",
"@octokit/rest": "^19.0.4",
"@prisma/client": "^4.5.0",
"cookie": "^0.5.0",
"discord-api-types": "^0.37.10",
"discord.js": "^14.8.0",
"express": "^4.18.1",
"fast-glob": "^3.2.11",
"prisma": "^4.5.0",
"svelte": "4.2.1",
"uuid": "^8.3.2",
"zod": "^3.19.1"
},
"devDependencies": {
"@carbon/charts": "^1.5.2",
"@carbon/charts-svelte": "^1.5.2",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@faker-js/faker": "^7.3.0",
"@hey-amplify/scripts": "workspace:*",
"@hey-amplify/support": "workspace:*",
"@hey-amplify/tsconfig": "workspace:*",
"@playwright/test": "^1.37.1",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.23.0",
"@types/cookie": "^0.5.1",
"@types/express": "^4.17.13",
"@types/node": "^18.7.13",
"@types/prettier": "^2.7.0",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"@vitest/ui": "^0.22.1",
"carbon-components-svelte": "^0.70.1",
"carbon-icons-svelte": "^11.2.0",
"carbon-preprocess-svelte": "^0.9.1",
"d3": "^7.6.1",
"esbuild": "^0.19.2",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte3": "^4.0.0",
"jsdom": "^20.0.0",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"supertest": "^6.2.4",
"svelte-check": "^3.5.0",
"tasuku": "^2.0.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-node": "^0.34.3",
"vitest": "^0.22.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ process.env.IS_TEST = 'true'

const config: PlaywrightTestConfig = {
webServer: {
command: 'pnpm run build:app && pnpm run preview',
command: 'pnpm run build-app && pnpm run preview',
port: 3000,
},
testDir: 'tests',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
if (!process.env.CI) {
// local builds require env vars
const path = require('node:path')
const { loadEnv } = require('vite')
const env = loadEnv('', path.relative(process.cwd(), '../../'), [
'VITE_',
'DISCORD_',
'NEXTAUTH_',
])
Object.assign(process.env, env)
}

require('esbuild').build({
entryPoints: ['src/server.ts'],
bundle: true,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fi
echo "Finish existing database prep"
cd -

pnpm start
pnpm run start-server
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions vite.config.ts → apps/discord-bot-frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function relative(path) {
export function loadEnvVars(mode = 'development') {
Object.assign(
process.env,
loadEnv(mode, relative('.'), [
loadEnv(mode, relative('../..'), [
'DISCORD_',
'GITHUB_',
'DATABASE_',
Expand All @@ -29,7 +29,7 @@ export default defineConfig({
build: {
target: 'esnext',
},
envDir: '.',
envDir: '../..',
define: {
'import.meta.vitest': 'undefined',
},
Expand Down
17 changes: 0 additions & 17 deletions docker-compose.yml

This file was deleted.

Loading

0 comments on commit 5dfd86e

Please sign in to comment.