Skip to content

Commit

Permalink
build: 👷 Build Docker image for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
5ika committed Jul 31, 2023
1 parent be2ee78 commit 1e17778
Show file tree
Hide file tree
Showing 11 changed files with 4,771 additions and 2,465 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build & Publish Docker image for demo

on:
push:
branches:
- main

jobs:
build-publish-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: fidbee-demo:latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
*.log
*.log
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:alpine AS build

WORKDIR /app
COPY . .
RUN yarn
WORKDIR /app/lib
RUN yarn build
WORKDIR /app/demo
RUN yarn build

FROM denoland/deno:ubuntu-1.35.2

WORKDIR /app
COPY ./server-example .
COPY --from=build /app/demo/dist ./assets

EXPOSE 8080

CMD deno run -A server.ts
5 changes: 4 additions & 1 deletion demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ function App() {
<center>
<img src="/puppy.jpeg" />
</center>
<Fidbee webhookUrl="http://localhost:4000" projectName="Demo Fidbee" />
<Fidbee
webhookUrl="http://localhost:8080/notify"
projectName="Demo Fidbee"
/>
</>
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "fidbee",
"private": false,
"version": "0.1.2",
"license": "AGPL-3.0-or-later",
"homepage": "https://github.com/octree-gva/fidbee",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fidbee",
"name": "fidbee-ws",
"private": true,
"workspaces": [
"lib",
Expand Down
2 changes: 1 addition & 1 deletion server-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Then, use Deno and appropriate permissions to start server.
deno run --allow-net --allow-read --allow-env server.ts
```

Server now runs on http://localhost:4000.
Server now runs on http://localhost:8080.
16 changes: 14 additions & 2 deletions server-example/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import sendEmail from "./src/sendEmail.ts";

const PORT = 4000;
const PORT = 8080;
const app = new Application();

app.use((ctx, next) => {
Expand All @@ -17,9 +17,20 @@ app.addEventListener("listen", ({ port }) => {
console.log(`🚀 Running on ${port}`);
});

app.use(async (context, next) => {
try {
await context.send({
root: `${Deno.cwd()}/assets`,
index: "index.html",
});
} catch {
await next();
}
});

const router = new Router();

router.post("/", async ctx => {
router.post("/notify", async ctx => {
const body = await ctx.request.body({ type: "json" });
const payload: FeedbackPayload = await body.value;
const hasScreenCapture = !!payload.screenCapture;
Expand All @@ -35,4 +46,5 @@ router.post("/", async ctx => {

app.use(router.routes());
app.use(router.allowedMethods());

await app.listen({ port: PORT });
18 changes: 11 additions & 7 deletions server-example/src/sendEmail.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { SMTPClient, SendConfig } from "https://deno.land/x/denomailer/mod.ts";
import { html } from "https://deno.land/x/html/mod.ts";
import "https://deno.land/[email protected]/dotenv/load.ts";
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";

await load({ allowEmptyValues: true, examplePath: "" });

const emailTo =
Deno.env.get("SMTP_RECEIVER") || Deno.env.get("SMTP_SENDER") || "";

export default (payload: FeedbackPayload) =>
sendEmail({
to: emailTo,
subject: `New feedback by Fidbee for project ${payload.projectName}`,
html: formatEmailContent(payload),
});
export default (payload: FeedbackPayload) => {
if (emailTo)
sendEmail({
to: emailTo,
subject: `New feedback by Fidbee for project ${payload.projectName}`,
html: formatEmailContent(payload),
});
};

const formatEmailContent = (payload: FeedbackPayload) => html`<div>
<p>You received a new feedback by Fidbee:</p>
Expand Down
Loading

0 comments on commit 1e17778

Please sign in to comment.