Skip to content

Commit

Permalink
chore: workflows hono app (#1093)
Browse files Browse the repository at this point in the history
* chore: workflows app

* ci: apply automated fixes

* chore: add dofigen

* chore: fly.toml

* fix: docker

* fix: number coerce

* wip:

* fix: import

* ci: apply automated fixes

* chore: small stuff

* chore: create scripts folder for tb

* chore: cd

* chore: build

* chore: update key replace

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
mxkaske and autofix-ci[bot] authored Nov 26, 2024
1 parent 33091d2 commit 8f9b44d
Show file tree
Hide file tree
Showing 37 changed files with 1,471 additions and 584 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Fly Deploy Workflows
on:
push:
branches:
- main
paths:
- "apps/workflows/**"
- "packages/db/**"
- "packages/emails/**"
- "packages/utils/**"
- "packages/tsconfig/**"
jobs:
deploy-workflows:
name: Deploy Workflows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- working-directory: apps/workflows
name: Deploy Workflows
run: |
flyctl deploy --remote-only --wait-timeout=500
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
9 changes: 8 additions & 1 deletion apps/server/src/v1/pageSubscribers/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { and, eq } from "@openstatus/db";
import { db } from "@openstatus/db/src/db";
import { page, pageSubscriber } from "@openstatus/db/src/schema";
import { SubscribeEmail } from "@openstatus/emails";
import { sendEmail } from "@openstatus/emails/emails/send";
import { sendEmail } from "@openstatus/emails/src/send";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import type { pageSubscribersApi } from "./index";
Expand Down Expand Up @@ -42,9 +42,16 @@ const postRouteSubscriber = createRoute({
export function registerPostPageSubscriber(api: typeof pageSubscribersApi) {
return api.openapi(postRouteSubscriber, async (c) => {
const workspaceId = c.get("workspaceId");
const limits = c.get("limits");
const input = c.req.valid("json");
const { id } = c.req.valid("param");

if (!limits["status-subscribers"]) {
throw new HTTPException(403, {
message: "Upgrade for status page subscribers",
});
}

const _page = await db
.select()
.from(page)
Expand Down
19 changes: 8 additions & 11 deletions apps/server/src/v1/statusReportUpdates/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function registerPostStatusReportUpdate(
) {
return api.openapi(createStatusUpdate, async (c) => {
const workspaceId = c.get("workspaceId");
const workspacePlan = c.get("workspacePlan");
const input = c.req.valid("json");
const limits = c.get("limits");

const _statusReport = await db
.select()
Expand Down Expand Up @@ -80,7 +80,7 @@ export function registerPostStatusReportUpdate(

// send email

if (workspacePlan.limits.notifications && _statusReport.pageId) {
if (limits["status-subscribers"] && _statusReport.pageId) {
const subscribers = await db
.select()
.from(pageSubscriber)
Expand All @@ -98,18 +98,15 @@ export function registerPostStatusReportUpdate(
.where(eq(page.id, _statusReport.pageId))
.get();
if (pageInfo) {
const subscribersEmails = subscribers.map(
(subscriber) => subscriber.email,
);

// TODO: verify if we leak any email data here
await sendEmailHtml({
to: subscribersEmails,
const subscribersEmails = subscribers.map((subscriber) => ({
to: subscriber.email,
subject: `New status update for ${pageInfo.title}`,
html: `<p>Hi,</p><p>${pageInfo.title} just posted an update on their status page:</p><p>New Status : ${statusReportUpdate.status}</p><p>${statusReportUpdate.message}</p></p><p></p><p>Powered by OpenStatus</p><p></p><p></p><p></p><p></p><p></p>
`,
`,
from: "Notification OpenStatus <[email protected]>",
});
}));

await sendEmailHtml(subscribersEmails);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/v1/statusReports/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@openstatus/db/src/schema";

import { getLimit } from "@openstatus/db/src/schema/plan/utils";
import { sendBatchEmailHtml } from "@openstatus/emails/emails/send";
import { sendBatchEmailHtml } from "@openstatus/emails/src/send";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
import { isoDate } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/v1/statusReports/update/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
statusReportUpdate,
} from "@openstatus/db/src/schema";
import { getLimit } from "@openstatus/db/src/schema/plan/utils";
import { sendBatchEmailHtml } from "@openstatus/emails/emails/send";
import { sendBatchEmailHtml } from "@openstatus/emails/src/send";
import { HTTPException } from "hono/http-exception";
import { openApiErrorResponses } from "../../../libs/errors/openapi-error-responses";
import { StatusReportUpdateSchema } from "../../statusReportUpdates/schema";
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/app/(content)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export async function generateMetadata({
export default function PostPage({ params }: { params: { slug: string } }) {
const post = allPosts.find((post) => post.slug === params.slug);

if (!post) {
notFound();
}
if (!post) notFound();

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NextAuth from "next-auth";
import { analytics, trackAnalytics } from "@openstatus/analytics";
import { db, eq } from "@openstatus/db";
import { user } from "@openstatus/db/src/schema";
import { sendEmail } from "@openstatus/emails/emails/send";
import { sendEmail } from "@openstatus/emails/src/send";

import { identifyUser } from "@/providers/posthog";
import { WelcomeEmail } from "@openstatus/emails/emails/welcome";
Expand Down
15 changes: 15 additions & 0 deletions apps/workflows/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is generated by Dofigen v2.1.0
# See https://github.com/lenra-io/dofigen

node_modules
/apps/docs
/apps/screenshot-service
/apps/server
/apps/web
/packages/analytics
/packages/api
/packages/error
/packages/notifications
/packages/tinybird
/packages/tracker
/packages/upstash
2 changes: 2 additions & 0 deletions apps/workflows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# deps
node_modules/
42 changes: 42 additions & 0 deletions apps/workflows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax=docker/dockerfile:1.7
# This file is generated by Dofigen v2.1.0
# See https://github.com/lenra-io/dofigen

# install
FROM oven/bun@sha256:e2c0b11e277f0285e089ffb77ad831faeec2833b9c4b04d6d317f054e587ef4e AS install
WORKDIR /app/
RUN \
--mount=type=bind,target=package.json,source=package.json \
--mount=type=bind,target=apps/workflows/package.json,source=apps/workflows/package.json \
--mount=type=bind,target=packages/assertions/package.json,source=packages/assertions/package.json \
--mount=type=bind,target=packages/db/package.json,source=packages/db/package.json \
--mount=type=bind,target=packages/emails/package.json,source=packages/emails/package.json \
--mount=type=bind,target=packages/utils/package.json,source=packages/utils/package.json \
--mount=type=bind,target=packages/tsconfig/package.json,source=packages/tsconfig/package.json \
--mount=type=cache,target=/root/.bun/install/cache,sharing=locked \
bun install --production --ignore-scripts --frozen-lockfile --verbose

# build
FROM oven/bun@sha256:e2c0b11e277f0285e089ffb77ad831faeec2833b9c4b04d6d317f054e587ef4e AS build
ENV NODE_ENV="production"
WORKDIR /app/apps/workflows
COPY \
--link \
"." "/app/"
COPY \
--from=install \
--link \
"/app/node_modules" "/app/node_modules"
RUN bun build --compile --sourcemap src/index.ts --outfile=app

# runtime
FROM debian@sha256:610b4c7ad241e66f6e2f9791e3abdf0cc107a69238ab21bf9b4695d51fd6366a AS runtime
COPY \
--from=build \
--chown=1000:1000 \
--chmod=555 \
--link \
"/app/apps/workflows/app" "/bin/"
USER 1000:1000
EXPOSE 3000
ENTRYPOINT ["/bin/app"]
33 changes: 33 additions & 0 deletions apps/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Development

To install dependencies:
```sh
bun install
```

To run:
```sh
bun run dev
```

open http://localhost:3000


## Deploy

From root

```bash
flyctl deploy --config apps/workflows/fly.toml --dockerfile apps/workflows/Dockerfile
```

## Docker

The Dockerfile is generated thanks to [Dofigen](https://github.com/lenra-io/dofigen). To generate the Dockerfile, run the following command from the `apps/workflows` directory:

```bash
# Update the dependent image versions
dofigen update
# Generate the Dockerfile
dofigen gen
```
134 changes: 134 additions & 0 deletions apps/workflows/dofigen.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
effective: |
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/server
- /apps/web
- /packages/analytics
- /packages/api
- /packages/error
- /packages/notifications
- /packages/tinybird
- /packages/tracker
- /packages/upstash
builders:
install:
fromImage:
path: oven/bun
digest: sha256:e2c0b11e277f0285e089ffb77ad831faeec2833b9c4b04d6d317f054e587ef4e
workdir: /app/
run:
- bun install --production --ignore-scripts --frozen-lockfile --verbose
cache:
- target: /root/.bun/install/cache
bind:
- target: package.json
source: package.json
- target: apps/workflows/package.json
source: apps/workflows/package.json
- target: packages/assertions/package.json
source: packages/assertions/package.json
- target: packages/db/package.json
source: packages/db/package.json
- target: packages/emails/package.json
source: packages/emails/package.json
- target: packages/utils/package.json
source: packages/utils/package.json
- target: packages/tsconfig/package.json
source: packages/tsconfig/package.json
build:
fromImage:
path: oven/bun
digest: sha256:e2c0b11e277f0285e089ffb77ad831faeec2833b9c4b04d6d317f054e587ef4e
workdir: /app/apps/workflows
env:
NODE_ENV: production
copy:
- paths:
- .
target: /app/
- fromBuilder: install
paths:
- /app/node_modules
target: /app/node_modules
run:
- bun build --compile --sourcemap src/index.ts --outfile=app
fromImage:
path: debian
digest: sha256:610b4c7ad241e66f6e2f9791e3abdf0cc107a69238ab21bf9b4695d51fd6366a
copy:
- fromBuilder: build
paths:
- /app/apps/workflows/app
target: /bin/
chmod: '555'
entrypoint:
- /bin/app
expose:
- port: 3000
images:
registry.hub.docker.com:443:
library:
debian:
bullseye-slim:
digest: sha256:610b4c7ad241e66f6e2f9791e3abdf0cc107a69238ab21bf9b4695d51fd6366a
oven:
bun:
latest:
digest: sha256:e2c0b11e277f0285e089ffb77ad831faeec2833b9c4b04d6d317f054e587ef4e
resources:
dofigen.yml:
hash: d232b15ff842b392611e64b97bf65d642ca573052072490c2f54ea2f4dc4481e
content: |
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/server
- /apps/web
- /packages/analytics
- /packages/api
- /packages/error
- /packages/notifications
- /packages/tinybird
- /packages/tracker
- /packages/upstash
builders:
install:
fromImage: oven/bun
workdir: /app/
# Copy project
bind:
- package.json
- apps/workflows/package.json
- packages/assertions/package.json
- packages/db/package.json
- packages/emails/package.json
- packages/utils/package.json
- packages/tsconfig/package.json
# Install dependencies
run: bun install --production --ignore-scripts --frozen-lockfile --verbose
cache:
- /root/.bun/install/cache
build:
fromImage: oven/bun
workdir: /app/apps/workflows
copy:
- . /app/
- fromBuilder: install
source: /app/node_modules
target: /app/node_modules
# Should set env to production here
# Compile the TypeScript application
env:
NODE_ENV: production
run: bun build --compile --sourcemap src/index.ts --outfile=app
fromImage: debian:bullseye-slim
copy:
- fromBuilder: build
source: /app/apps/workflows/app
target: /bin/
chmod: "555"
expose: 3000
entrypoint: /bin/app
Loading

0 comments on commit 8f9b44d

Please sign in to comment.