Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(embed): deploy code embed renderer #45

Merged
merged 1 commit into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore(embed): deploy code embed renderer
  • Loading branch information
tericcabrel committed Sep 3, 2022
commit 8d4ff99b7b0f997ae34e139b36db940ae4da1ce3
16 changes: 4 additions & 12 deletions .github/workflows/deploy-code-embed.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
name: Sharingan Deploy Code Embed
on:
workflow_dispatch:
inputs:
stage:
default: Production
options:
- Production
- Development
description: "Environment to deploy on"
required: true
push:
branches:
- main
- dev
paths:
- 'packages/database/prisma/**'
- 'packages/database/src/**'
Expand All @@ -21,7 +13,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.stage }}
environment: ${{ (github.ref == 'refs/heads/main' && 'Production') || 'Development' }}
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
EMBED_STYLE_URL: ${{ secrets.EMBED_STYLE_URL }}
Expand All @@ -41,14 +33,14 @@ jobs:

- name: Deploy the application in staging
working-directory: 'apps/functions/code-embed'
if: ${{ github.event.inputs.stage == 'Development' }}
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
yarn setup:layer:remote
yarn sls deploy --stage dev

- name: Deploy the application in production
working-directory: 'apps/functions/code-embed'
if: ${{ github.event.inputs.stage == 'Production' }}
if: ${{ github.ref == 'refs/heads/main' }}
run: |
yarn setup:layer:remote
yarn sls deploy --stage prod
Expand Down
11 changes: 9 additions & 2 deletions apps/functions/code-embed/scripts/setup-layer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ yarn workspace @sharingan/database db:generate

cp -r node_modules/.prisma apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules

PRISMA_ENGINE_MACOS=apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-darwin.dylib.node
PRISMA_ENGINE_DOCKER_LINUX=apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-linux-musl.so.node

if [ $1 = "remote" ]; then
rm apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-darwin.dylib.node
rm apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-linux-musl.so.node
if [ -f "$PRISMA_ENGINE_MACOS" ]; then
rm $PRISMA_ENGINE_MACOS
fi
if [ -f "$PRISMA_ENGINE_DOCKER_LINUX" ]; then
rm $PRISMA_ENGINE_DOCKER_LINUX
fi
else
echo 'local'
fi
Expand Down
7 changes: 6 additions & 1 deletion apps/functions/code-embed/src/functions/renderer/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const shiki = require('shiki');
export const main: Handler<APIGatewayProxyEvent, APIGatewayProxyResult> = async (event) => {
const snippetId = event.pathParameters['id'];

const snippet = await dbClient.snippet.findFirst({ where: { id: snippetId, visibility: 'public' } });
const snippet = await dbClient.snippet.findFirst({
where: {
id: snippetId,
visibility: 'public',
},
});

const content = await renderSnippetToHtml({
options: {
Expand Down