Skip to content

Commit

Permalink
WIP: upgrade to pylon and remove unused code
Browse files Browse the repository at this point in the history
The commit removes unused files and code. It also updates the `.dockerignore` file to exclude unnecessary files and directories. Additionally, the commit deletes the `users.ts` file, `sfi.ts` file, `user.repository.ts` file, and `user.service.ts` file, as they are no longer needed.
  • Loading branch information
kleberbaum committed May 23, 2024
1 parent 43b0026 commit 7e0daff
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 179 deletions.
23 changes: 15 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

.git
node_modules
*Dockerfile*
yarn.lock
package-lock.json

# SPDX-License-Identifier: (EUPL-1.2)
# Copyright © 2019-2022 snek.at
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
key.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ package-lock.json
.env.*

# snek-function
.sf
.pylon
key.json


# SPDX-License-Identifier: (EUPL-1.2)
Expand Down
66 changes: 54 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,62 @@
FROM --platform=linux/amd64 node:18.8.0-alpine
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base

LABEL description="This container serves as an entry point for our future Snek Function projects."
LABEL org.opencontainers.image.source="https://github.com/snek-functions/template"
LABEL maintainer="opensource@snek.at"
LABEL org.opencontainers.image.source="https://github.com/cronitio/pylon-template"
LABEL maintainer="opensource@netsnek.com"

WORKDIR /app
WORKDIR /usr/src/pylon

COPY .sf/ ./.sf
COPY package.json .
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
ARG NODE_VERSION=20
RUN apt update \
&& apt install -y curl
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

RUN yarn install --production
RUN yarn sf build
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
COPY prisma /temp/dev/prisma

CMD ["sh", "-c", "yarn sf-server"]
RUN cd /temp/dev && bun install --frozen-lockfile
RUN cd /temp/dev && bun prisma generate

EXPOSE 3000
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
COPY prisma /temp/prod/prisma

# SPDX-License-Identifier: (EUPL-1.2)
# Copyright © 2022 snek.at
RUN cd /temp/prod && bun install --frozen-lockfile --production
RUN cd /temp/prod && bun prisma generate

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

# [optional] tests & build
ENV NODE_ENV=production

# Create .pylon folder (mkdir)
RUN mkdir .pylon
# RUN bun test
RUN bun run pylon build

# copy production dependencies and asource code into final image
FROM base AS release
RUN apt-get update -y && apt-get install -y openssl
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/pylon/.pylon .pylon
COPY --from=prerelease /usr/src/pylon/package.json .
COPY --from=prerelease /usr/src/pylon/prisma prisma

# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "./node_modules/.bin/pylon-server" ]
Binary file added bun.lockb
Binary file not shown.
47 changes: 21 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
{
"name": "@snek-functions/template",
"baseURL": "https://schettn-special-umbrella-q66979jv7gh4w59-3000.preview.app.github.dev",
"name": "@cronitio/pylon-template",
"version": "0.0.1",
"type": "module",
"description": "Generated with `sf new`",
"author": "snek-at",
"exports": {
"./client": "./src/client/index.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"./client": [
"./src/client/index.ts"
]
}
"author": "Netsnek <[email protected]>",
"pylon": {
"external": [
"@cronitio/pylon"
]
},
"files": [
"src/client",
"package.json"
],
"config": {
"commitizen": {
"path": "git-cz"
}
},
"dependencies": {
"@snek-at/function": "*",
"@snek-at/function-cli": "*",
"@snek-at/function-server": "*"
"@cronitio/pylon": "*",
"@cronitio/pylon-builder": "*",
"@cronitio/pylon-server": "*",
"@netsnek/prisma-repository": "^0.0.41",
"joi": "^17.13.1",
"jszip": "^3.10.1",
"slugify": "^1.6.6",
"validator": "^13.11.0"
},
"devDependencies": {
"commitizen": "^4.2.5",
"git-cz": "^4.9.0",
"snek-query": "^0.0.53"
"@cronitio/pylon-cli": "*",
"@types/validator": "^13.11.5"
},
"scripts": {
"develop": "yarn sf develop",
"build": "yarn sf build"
"develop": "mkdir -p .pylon && bun run pylon develop",
"build": "mkdir -p .pylon && bun run pylon build"
},
"prisma": {
"schema": "prisma/schema.prisma"
}
}
18 changes: 0 additions & 18 deletions src/data/users.ts

This file was deleted.

37 changes: 37 additions & 0 deletions src/errors/general.errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ServiceError } from "@cronitio/pylon";

export class InvalidInputError extends ServiceError {
constructor(message: string) {
super(message, {
code: "INVALID_INPUT",
statusCode: 400,
});
}
}

export class NotFoundError extends ServiceError {
constructor(message: string) {
super(message, {
code: "NOT_FOUND",
statusCode: 404,
});
}
}

export class AuthorizationError extends ServiceError {
constructor(message: string) {
super(message, {
code: "AUTHORIZATION_ERROR",
statusCode: 403,
});
}
}

export class EmailOrUsernameAlreadyExistsError extends ServiceError {
constructor(message: string) {
super(message, {
code: "EMAILORUSERNAMEALREADYEXISTS_ERROR",
statusCode: 403,
});
}
}
14 changes: 12 additions & 2 deletions src/errors/user.errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// errors/user.errors.ts
import { ServiceError } from "@snek-at/function";
import { ServiceError } from "@cronitio/pylon";

export class UserNotFoundError extends ServiceError {
constructor(id: string) {
Expand All @@ -8,7 +8,17 @@ export class UserNotFoundError extends ServiceError {
super(message, {
statusCode: 404,
code: "USER_NOT_FOUND",
message,
});
}
}

export class EmailOrUsernameAlreadyExistsError extends ServiceError {
constructor(loginName: string) {
const message = `Email or username'${loginName}' already exists.`;

super(message, {
code: "EMAILORUSERNAMEALREADYEXISTS_ERROR",
statusCode: 403,
});
}
}
59 changes: 59 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { auth, defineService, logger, PylonAPI } from "@cronitio/pylon";
//import { createBunWebSocket } from "hono/bun";

import { UserService } from "./user.service";

//const { upgradeWebSocket, websocket } = createBunWebSocket();

export default defineService(
{
Query: {
hello() {
return "Hello, World!";
},
},
Mutation: {
getIsUnique: UserService.getIsUnique,
userCreate: UserService.userCreate,
},
},
{
context: (c) => {
return c;
},
}
);

export const configureApp: PylonAPI["configureApp"] = (app) => {
logger.info("Configuring app");

app.use("*", auth.initialize());

// app.get(
// "/transcribe",
// auth.require({
// roles: ["admin"],
// }),
// upgradeWebSocket((c) => {
// return {
// async onMessage(event, ws) {
// const blob = new Blob([event.data], { type: "audio/wav" });
// const file = new File([blob], "speech.wav");

// try {
// const text = await SpeechToText.convert(file);

// ws.send(text);
// } catch (e) {
// logger.error(e);
// }
// },
// onClose: () => {},
// };
// })
// );
};

// export const configureWebsocket: PylonAPI["configureWebsocket"] = () => {
// return websocket;
// };
43 changes: 0 additions & 43 deletions src/repositories/user.repository.ts

This file was deleted.

Loading

0 comments on commit 7e0daff

Please sign in to comment.