Skip to content

Commit

Permalink
chore: setup TS + Rust monorepo (#146)
Browse files Browse the repository at this point in the history
* refactor: rename runtime to old-runtime

* refactor: rename cli to old-cli

* refactor: rename serverless to old-serverless

* refactor: update lockfile

* refactor: rename rust packages

* feat: update turborepo

* chore: remove useless log file

* chore: update lockfile

* refactor: remove useless baseBranch field

* refactor: ignore old-* packages

* feat: add test pipeline

* refactor: migrate common & prisma to website

* fix: add missing prisma postinstall

* fix(runtime): set methods public to self

* fix(runtime: increase memory_reached timeout

* chore: add changesets

* refactor(runtime): replace reqwest by hyper

* feat: add js-runtime package

* fix: ci

* refactor: migrate serverless dockerfile to rust

* fix(serverless): create deployments folder when not exists

* fix: docker start command
  • Loading branch information
QuiiBz authored Sep 23, 2022
1 parent c78ee99 commit e8175ef
Show file tree
Hide file tree
Showing 181 changed files with 1,361 additions and 1,595 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-islands-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/www': patch
---

Use PostHog instead of Splitbee
5 changes: 5 additions & 0 deletions .changeset/fluffy-dolphins-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/website': patch
---

Move common & prisma packages to website
7 changes: 7 additions & 0 deletions .changeset/itchy-balloons-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@lagon/cli': patch
'@lagon/runtime': patch
'@lagon/serverless': patch
---

Move from Node.js to Rust
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
target
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dist/
packages/old-*/**/*
runtime.js

*.log
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run ESLint
- name: Lint
run: pnpm lint
test:
runs-on: ubuntu-20.04
Expand All @@ -35,9 +35,9 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Build needed packages
run: pnpm turbo run build build:runtime --filter="@lagon/common" --filter="@lagon/runtime" --filter="@lagon/serverless"
- name: Run Vitest
- name: Build runtime
run: pnpm turbo build --filter=@lagon/js-runtime
- name: Test
run: pnpm test
typecheck:
runs-on: ubuntu-20.04
Expand All @@ -53,7 +53,7 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run TSC
- name: Typecheck
run: pnpm typecheck
build:
runs-on: ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ coverage/
.turbo/
ssl/
target/
packages/rust-serverless/deployments/
packages/serverless/deployments/
.vercel/

.eslintcache
.DS_Store
.env
tsconfig.tsbuildinfo
.vercel
21 changes: 6 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"packages/rust-runtime",
"packages/rust-serverless",
"packages/rust-cli",
"packages/runtime",
"packages/serverless",
"packages/cli",
]
35 changes: 8 additions & 27 deletions docker/serverless.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
FROM node:16-slim as builder
FROM rust:1.63 as builder

RUN apt update
RUN apt install -y python3 make g++ openssl

RUN npm install -g pnpm
WORKDIR /app
COPY . .

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/runtime/package.json ./packages/runtime/package.json
COPY packages/serverless/package.json ./packages/serverless/package.json
COPY packages/prisma/package.json ./packages/prisma/package.json
COPY packages/common/package.json ./packages/common/package.json

RUN pnpm install --frozen-lockfile

COPY packages/runtime/ ./packages/runtime/
COPY packages/serverless/ ./packages/serverless/
COPY packages/prisma/ ./packages/prisma/
COPY packages/common/ ./packages/common/

WORKDIR /app/packages/runtime
RUN pnpm build
RUN pnpm build:runtime
WORKDIR /app/packages/serverless
RUN cargo build --release

WORKDIR /app/packages/prisma
RUN pnpm prisma generate
# TODO: use a smaller image
FROM rust:1.63

WORKDIR /app/packages/serverless
RUN pnpm build
COPY --from=builder /app/target/release/lagon-serverless /usr/local/bin/lagon-serverless

EXPOSE 4000
ENV NODE_ENV=production
CMD [ "pnpm", "start" ]
CMD ["lagon-serverless"]
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
"description": "Deploy Serverless Functions at the Edge",
"private": true,
"scripts": {
"test": "vitest run",
"test:update": "pnpm test -- -u",
"test:watch": "vitest",
"build": "turbo run build --continue",
"lint": "eslint --cache --ignore-pattern dist .",
"typecheck": "turbo run typecheck --continue",
"test": "turbo test --continue --filter=!@lagon/example-* --filter=!@lagon/old-*",
"build": "turbo build --continue --filter=!@lagon/example-* --filter=!@lagon/old-*",
"lint": "turbo lint --filter=!@lagon/old-*",
"typecheck": "turbo typecheck --continue --filter=!@lagon/old-*",
"docker:build:serverless": "docker build -t lagon/serverless -f docker/serverless.Dockerfile .",
"docker:start:serverless": "docker run --rm -p 4000:4000 lagon/serverless",
"docker:start:serverless": "docker run --rm -p 4000:4000 --env-file packages/serverless/.env --network host lagon/serverless",
"docker:build:nginx": "docker build -t lagon/nginx -f docker/nginx.Dockerfile ./docker/nginx",
"docker:start:nginx": "docker run --rm -p 80:80 lagon/nginx",
"release": "pnpm build && pnpm changeset publish",
Expand Down Expand Up @@ -43,7 +41,7 @@
"nodemon": "^2.0.16",
"prettier": "^2.6.2",
"tsup": "^6.0.1",
"turbo": "^1.3.1",
"turbo": "^1.5.2",
"typescript": "^4.6.4",
"vite-tsconfig-paths": "^3.5.0",
"vitest": "^0.15.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/rust-cli/Cargo.toml → packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ version = "0.1.0"
edition = "2021"

[dependencies]
lagon-runtime = { path = "../rust-runtime" }
lagon-runtime = { path = "../runtime" }
clap = { version = "3.2", features = ["derive"] }
dialoguer = "0.10.2"
indicatif = "0.17.1"
colored = "2.0.0"
dirs = "4.0.0"
webbrowser = "0.8.0"
tokio = { version = "1", features = ["full"] }
hyper = { version = "0.14", features = ["full"] }
hyper = { version = "0.14", features = ["client", "http1", "http2", "tcp"] }
multipart = "0.18.0"
mime = "0.3.16"
serde = { version = "1.0", features = ["derive"] }
Expand Down
31 changes: 2 additions & 29 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
{
"name": "@lagon/cli",
"version": "0.0.11",
"version": "0.1.0",
"description": "CLI for Lagon",
"type": "module",
"files": [
"dist"
],
"bin": {
"lagon": "dist/index.js"
},
"scripts": {
"watch": "tsup src/index.ts --format=esm --watch",
"build": "tsup src/index.ts --format=esm --define.process.env.NODE_ENV \\\"production\\\"",
"lint": "eslint --cache --ignore-pattern dist .",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@lagon/runtime": "workspace:0.0.6",
"@trpc/client": "^9.25.3",
"chalk": "^5.0.1",
"commander": "^9.3.0",
"esbuild": "^0.14.41",
"fastify": "^3.29.0",
"inquirer": "^9.0.0",
"node-fetch": "^3.2.6",
"open": "^8.4.0",
"update-notifier": "^6.0.1"
},
"devDependencies": {
"@lagon/common": "workspace:0.0.2",
"@types/inquirer": "^8.2.1",
"@types/update-notifier": "^5.1.0"
"build": "cargo build"
}
}
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.
18 changes: 18 additions & 0 deletions packages/js-runtime/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@lagon/js-runtime",
"version": "0.1.0",
"description": "JavaScript Runtime",
"private": true,
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "vitest --run",
"build": "tsup src/index.ts --format=esm --dts",
"lint": "eslint --cache --ignore-pattern dist .",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"web-streams-polyfill": "^3.2.1"
}
}
12 changes: 12 additions & 0 deletions packages/js-runtime/src/__tests__/base64.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, it, expect } from 'vitest';
import { atob, btoa } from '../runtime/base64';

describe('base64', () => {
it('should encode with atob', async () => {
expect(atob('Hello World')).toEqual('\x1Dée¡j+\x95');
});

it('should decode with btoa', async () => {
expect(btoa('\x1Dée¡j+\x95')).toEqual('HelloWorlQ==');
});
});
31 changes: 31 additions & 0 deletions packages/js-runtime/src/__tests__/encoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, it, expect } from 'vitest';
import { TextEncoder, TextDecoder } from '../runtime/encoding';

describe('encoding', () => {
it('should encode', async () => {
expect(new TextEncoder().encode('Hello World')).toEqual(
new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]),
);
});

it('should decode', async () => {
expect(new TextDecoder().decode(new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]))).toEqual(
'Hello World',
);
});

it('should encode and decode', async () => {
const encoded = new TextEncoder().encode('Hello World');
const decoded = new TextDecoder().decode(encoded);

expect(decoded).toEqual('Hello World');
});

it('should have encoding field on TextEncoder', async () => {
expect(new TextEncoder().encoding).toEqual('utf-8');
});

it('should have encoding field on TextDecoder', async () => {
expect(new TextDecoder().encoding).toEqual('utf-8');
});
});
Loading

0 comments on commit e8175ef

Please sign in to comment.