Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
78 changes: 39 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
FROM node:18-alpine AS deps
ENV NEXT_TELEMETRY_DISABLED 1

RUN apk add --no-cache libc6-compat make clang build-base python3
RUN npm i -g pnpm

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1-alpine as base
WORKDIR /usr/src/micro
ENV NODE_ENV=production

COPY pnpm-lock.yaml pnpm-workspace.yaml ./
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm fetch




FROM node:18-alpine AS builder
ENV NEXT_TELEMETRY_DISABLED 1
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install

WORKDIR /usr/src/micro
RUN mkdir -p /temp/dev
COPY ./packages/api/package.json /temp/dev/packages/api/
COPY ./packages/web/package.json /temp/dev/packages/web/
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

RUN apk add --no-cache git
RUN npm i -g pnpm
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY ./packages/api/package.json /temp/prod/packages/api/
COPY ./packages/web/package.json /temp/prod/packages/web/
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --production

COPY --from=deps /usr/src/micro .
COPY . .

# install all deps
RUN pnpm install --offline --frozen-lockfile
# build everthing
RUN pnpm build

# use "pnpm deploy" to prune the api into a smaller package
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
cd packages/api && pnpm --filter @ryanke/micro-api --prod deploy pruned


# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS build
COPY --from=install /temp/dev/node_modules node_modules

COPY ./packages/web ./packages/web
RUN cd ./packages/web && bun run build

COPY ./packages/api ./packages/api
RUN cd ./packages/api && bun run build

FROM node:18-alpine AS runner
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

WORKDIR /usr/src/micro

RUN apk add --no-cache ffmpeg

# copy file dependencies
COPY --from=builder /usr/src/micro/packages/web/public ./packages/web/public
COPY --from=builder /usr/src/micro/packages/web/next.config.js ./packages/web/next.config.js

# copy web
COPY --from=builder --chown=node:node /usr/src/micro/packages/web/.next/standalone/ ./
COPY --from=builder --chown=node:node /usr/src/micro/packages/web/.next/static ./packages/web/.next/static/

# copy api
COPY --from=builder --chown=node:node /usr/src/micro/packages/api/pruned ./packages/api
# copy production dependencies and source code into final image
FROM base AS release
# necessary for sharp, apparently
RUN apk add --no-cache libstdc++

COPY --from=install /temp/prod/node_modules node_modules
COPY --from=build /usr/src/micro/packages/api/dist ./packages/api/dist
COPY --from=build /usr/src/micro/packages/api/package.json ./packages/api/
COPY --from=build /usr/src/micro/packages/web/.next/standalone ./packages/web/

COPY wrapper.sh .
RUN chmod +x ./wrapper.sh

USER node

ENTRYPOINT ["./wrapper.sh"]
# run the app
USER bun
EXPOSE 3000/tcp
CMD [ "./wrapper.sh" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>

<p align="center">
<img src="https://skillicons.dev/icons?i=next,tailwind,nest,typescript,docker,graphql" />
<img src="https://skillicons.dev/icons?i=typescript,bun,next,tailwind,nest,docker,graphql" />
<br/>
<a href="https://discord.gg/VDMX6VQRZm"><kbd>🔵 discord</kbd></a> <a href="https://micro.sylo.digital"><kbd>🟢 hosted instance</kbd></a>
</p>
Expand Down
Binary file added bun.lockb
Binary file not shown.
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
"repository": "https://github.com/sylv/micro.git",
"author": "Ryan <ryan@sylver.me>",
"private": true,
"engines": {
"node": ">=16",
"pnpm": ">=7"
},
"workspaces": [
"./packages/*"
],
"scripts": {
"build": "turbo run build",
"clean": "rm -rf ./packages/*/{tsconfig.tsbuildinfo,lib,dist,yarn-error.log,.next}",
"lint": "turbo run lint",
"sync": "syncpack format && syncpack fix-mismatches",
"test": "turbo run test"
"test": "turbo run test",
"clean": "rm -rf ./packages/*/{tsconfig.tsbuildinfo,lib,dist,yarn-error.log,.next}",
"sync": "syncpack format && syncpack fix-mismatches"
},
"devDependencies": {
"syncpack": "^12.3.0",
"turbo": "1.11.3"
},
"packageManager": "pnpm@7.0.0"
}
}
24 changes: 0 additions & 24 deletions packages/api/convert.mjs

This file was deleted.

49 changes: 23 additions & 26 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
"author": "Ryan <ryan@sylver.me>",
"type": "module",
"private": true,
"engines": {
"node": ">=20"
},
"scripts": {
"build": "tsc --noEmit && tsup",
"build": "tsc --noEmit && rm -rf ./dist/* && bun run ./src/build.ts",
"lint": "eslint src --fix --cache",
"test": "vitest run",
"watch": "tsup --watch --onSuccess \"node dist/main.js\""
"watch": "bun run --watch ./src/main.ts"
},
"dependencies": {
"sharp": "^0.33.1"
},
"devDependencies": {
"@atlasbot/configs": "^10.5.14",
"@fastify/cookie": "^9.2.0",
"@fastify/helmet": "^11.1.1",
"@fastify/multipart": "^8.1.0",
"@jenyus-org/graphql-utils": "^1.5.0",
"@mercuriusjs/gateway": "^2.2.0",
"@mikro-orm/cli": "^5.9.7",
"@mikro-orm/core": "^5.9.7",
"@mikro-orm/migrations": "^5.9.7",
"@mikro-orm/nestjs": "^5.2.3",
Expand All @@ -34,50 +36,45 @@
"@nestjs/platform-fastify": "^10.3.0",
"@nestjs/schedule": "^4.0.0",
"@ryanke/venera": "^1.0.5",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"fastify": "^4.25.2",
"fluent-ffmpeg": "^2.1.2",
"graphql": "^16.8.1",
"mercurius": "^13.3.3",
"mime-types": "^2.1.35",
"nodemailer": "^6.9.8",
"otplib": "^12.0.1",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"rxjs": "^7.8.1",
"sharp": "^0.33.1",
"stream-size": "^0.0.6"
},
"devDependencies": {
"@atlasbot/configs": "^10.5.14",
"@mikro-orm/cli": "^5.9.7",
"@swc/core": "^1.3.102",
"@types/bcryptjs": "^2.4.6",
"@types/bun": "^1.0.0",
"@types/bytes": "^3.1.4",
"@types/dedent": "^0.7.2",
"@types/fluent-ffmpeg": "^2.1.24",
"@types/luxon": "^3.4.0",
"@types/mime-types": "^2.1.4",
"@types/ms": "^0.7.34",
"@types/node": "^20.10.6",
"@types/nodemailer": "^6.4.14",
"@types/passport-jwt": "^4.0.0",
"bcryptjs": "^2.4.3",
"bytes": "^3.1.2",
"chalk": "^5.3.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"content-range": "^2.0.2",
"dedent": "^1.5.1",
"escape-string-regexp": "^5.0.0",
"fastify": "^4.25.2",
"file-type": "^18.7.0",
"fluent-ffmpeg": "^2.1.2",
"graphql": "^16.8.1",
"handlebars": "^4.7.8",
"istextorbinary": "^9.5.0",
"luxon": "^3.4.4",
"mercurius": "^13.3.3",
"mime-types": "^2.1.35",
"ms": "^3.0.0-canary.1",
"nanoid": "^5.0.4",
"nodemailer": "^6.9.8",
"normalize-url": "^8.0.0",
"otplib": "^12.0.1",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"pretty-bytes": "^6.1.1",
"reflect-metadata": "^0.2.1",
"rxjs": "^7.8.1",
"stream-size": "^0.0.6",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
Expand All @@ -86,7 +83,7 @@
"zod-validation-error": "^2.1.0"
},
"mikro-orm": {
"useTsNode": true,
"alwaysAllowTs": true,
"configPaths": [
"./src/orm.config.ts"
]
Expand Down
44 changes: 44 additions & 0 deletions packages/api/src/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { readdirSync } from 'fs';
import { join } from 'path';

const external = [
'@nestjs/microservices',
'@nestjs/platform-express',
'@nestjs/websockets',
'@fastify/view',
'ts-morph',
'@mikro-orm/seeder',
'@apollo/subgraph',
'@mikro-orm/entity-generator',
'@mikro-orm/mongodb',
'@mikro-orm/mysql',
'@mikro-orm/mariadb',
'@mikro-orm/sqlite',
'@mikro-orm/better-sqlite',
'sqlite3',
'mysql',
'class-transformer/storage',
'better-sqlite3',
'mysql2',
'pg-query-stream',
'oracledb',
'tedious',
];

const migrationsDir = join(import.meta.dir, 'migrations');
const migrationNames = readdirSync(migrationsDir).map((file) => join('./src/migrations', file));

const result = await Bun.build({
entrypoints: ['./src/main.ts', ...migrationNames],
root: import.meta.dir,
target: 'node',
external: external,
outdir: './dist',
splitting: true,
define: {
'process.env.NODE_ENV': '"production"',
'process.env.FLUENTFFMPEG_COV': 'false',
},
});

for (const log of result.logs) console.log(log);
2 changes: 1 addition & 1 deletion packages/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const schema = strictObject({
allowTypes: z
.union([array(string()), string()])
.optional()
.transform((value) => new Set(value ? expandMime(value) : [])),
.transform((value) => (value ? new Set(expandMime(value)) : null)),
storagePath: string(),
restrictFilesToHost: boolean().default(true),
purge: strictObject({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/helpers/get-stream-type.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fileTypeFromBuffer } from 'file-type';
import * as mimeType from 'mime-types';
import path from 'path';
import type { PassThrough } from 'stream';
// @ts-expect-error type error? i guess?
import { isBinary } from 'istextorbinary';

const DEFAULT_TYPE = 'application/octet-stream';
Expand Down
Loading