generated from snek-functions/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: upgrade to pylon and remove unused code
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
1 parent
43b0026
commit 7e0daff
Showing
14 changed files
with
408 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ package-lock.json | |
.env.* | ||
|
||
# snek-function | ||
.sf | ||
.pylon | ||
key.json | ||
|
||
|
||
# SPDX-License-Identifier: (EUPL-1.2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.