🎥 Make videos programmatically with React
move functions into one container
Matt Mcgillivraya46df68fec22
diff --git a/packages/gcp/containers/renderMedia/Dockerfile b/packages/gcp/container/Dockerfilesimilarity index 100%rename from packages/gcp/containers/renderMedia/Dockerfilerename to packages/gcp/container/Dockerfilediff --git a/packages/gcp/containers/renderMedia/package.json b/packages/gcp/container/package.jsonsimilarity index 77%rename from packages/gcp/containers/renderMedia/package.jsonrename to packages/gcp/container/package.jsonindex 0d0fa8397b..3c8ded5cae 100644--- a/packages/gcp/containers/renderMedia/package.json+++ b/packages/gcp/container/package.json@@ -4,7 +4,7 @@"description": "Render media on Cloud Run","main": "dist/index.js","scripts": {- "start": "functions-framework --target=renderMediaSingleThread"+ "start": "functions-framework --target=renderOnCloudRun"},"dependencies": {"@google-cloud/functions-framework": "^3.1.3"diff --git a/packages/gcp/containers/renderStill/Dockerfile b/packages/gcp/containers/renderStill/Dockerfiledeleted file mode 100644index d10687a211..0000000000--- a/packages/gcp/containers/renderStill/Dockerfile+++ /dev/null@@ -1,26 +0,0 @@-FROM node:alpine--RUN apk add --no-cache \- chromium \- nss \- freetype \- freetype-dev \- harfbuzz \- ca-certificates \- ttf-freefont \- ffmpeg \- font-noto-emoji--ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \- PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser--WORKDIR /usr/app--COPY package*.json ./-COPY dist ./dist--RUN npm i--EXPOSE 8080--CMD ["npm", "run", "start"]\ No newline at end of filediff --git a/packages/gcp/containers/renderStill/package.json b/packages/gcp/containers/renderStill/package.jsondeleted file mode 100644index 17b8476fad..0000000000--- a/packages/gcp/containers/renderStill/package.json+++ /dev/null@@ -1,12 +0,0 @@-{- "name": "gcp-cloud-run-render-still",- "version": "0.1.0",- "description": "Render a still on Cloud Run",- "main": "dist/index.js",- "scripts": {- "start": "functions-framework --target=renderStillSingleThread"- },- "dependencies": {- "@google-cloud/functions-framework": "^3.1.3"- }-}diff --git a/packages/gcp/package.json b/packages/gcp/package.jsonindex 08662183f4..89e1a135dc 100644--- a/packages/gcp/package.json+++ b/packages/gcp/package.json@@ -4,11 +4,9 @@"description": "GCP alternative to lambda rendering","main": "dist/index.js","scripts": {- "build": "pnpm run build-container-renderStill && pnpm run build-container-renderMedia",+ "build": "ts-node src/admin/bundle-renderLogic.ts","start": "functions-framework --target=TypescriptFunction",- "prestart": "pnpm run build",- "build-container-renderStill": "ts-node src/admin/bundle-renderLogic.ts renderStill",- "build-container-renderMedia": "ts-node src/admin/bundle-renderLogic.ts renderMedia"+ "prestart": "pnpm run build"},"dependencies": {"@google-cloud/functions-framework": "^3.1.3",@@ -21,7 +19,6 @@"prettier-plugin-organize-imports": "^3.2.2","typescript": "^4.7.0","@remotion/compositor-linux-x64-musl": "3.3.36",- "zip-lib": "^0.7.2","ts-node": "^10.8.0"}}diff --git a/packages/gcp/readme.md b/packages/gcp/readme.mdindex 712716425d..cfe00ee74a 100644--- a/packages/gcp/readme.md+++ b/packages/gcp/readme.md@@ -1,27 +1,24 @@-from the root, `pnpm i && pnpm build` will trigger a build command for all packages. For the GCP package, this will bundle the required code into `containers/renderStill` and `containers/renderMedia`.+from the root, `pnpm i && pnpm build` will trigger a build command for all packages. For the GCP package, this will bundle the required code into `gcp/container`.-Each /container folder contains a package.json that lists functions-framework as a dependency, and a Dockerfile that will build the container. Functions-framework is a nodejs framework that allows you to run nodejs code in a containerized environment.+The /container folder contains a package.json that lists functions-framework as a dependency, and a Dockerfile that will build the container. Functions-framework is a nodejs framework that allows you to run nodejs code in a containerized environment.-This can be build and deployed to Cloud Run. Cloud Run is a serverless container platform that allows you to run containers in a managed environment.+This can be built and deployed to Cloud Run. Cloud Run is a serverless container platform that allows you to run containers in a managed environment.### Push images to Google Container Registry-To start, you need to create a project in the Google Cloud Console, and create a repository in the Google Container Registry, and push the container to the registry using-for renderStill:-`gcloud builds submit --tag australia-southeast1-docker.pkg.dev/remotion-lambda/repo1/render-still:0.1.0`-for renderMedia:-`gcloud builds submit --tag australia-southeast1-docker.pkg.dev/remotion-lambda/repo1/render-media:0.1.0`+To start, you need to create a project in the Google Cloud Console, and create a repository in the Google Container Registry, and push the container to the registry using;+`gcloud builds submit --tag australia-southeast1-docker.pkg.dev/remotion-lambda/repo1/render-on-cloud-run:0.1.0`### Deploy to Cloud RunNavigate to Cloud Run, and click "Create Service". Select "Container Registry", and select the image you just pushed. You can select `Allow unauthenticated invocations` to ignore security for now. Click "Create".To update the image running on Cloud Run, you can click "Edit & Deploy new revision" and select the new image.-### Run the servicesWithin the Cloud Run service, you can see the URL of the service. You can run the service by sending a POST request to the URL with the following body example:-#### Render Media Body:+#### Body to render media:```{+ "type": "media","composition": "HelloWorld","serveUrl": "https://remotionlambda-11kow3vq6f.s3.us-east-1.amazonaws.com/sites/xmycbufjs3/index.html","codec": "h264",@@ -33,7 +30,7 @@ Within the Cloud Run service, you can see the URL of the service. You can run th"outputFile": "outFolder/mediaOutput.mp4"}```-#### Render Still Body:+#### Body to render still:```{"composition": "StillRender",@@ -44,4 +41,13 @@ Within the Cloud Run service, you can see the URL of the service. You can run th"outputBucket": "remotionlambda-test","outputFile": "outFolder/stillOutput.png"}-```\ No newline at end of file+```+++### NEXT STEPS+> let's work towards making user facing APIs for deploying the container and invoke it.+> aka make equivalent functions for deployFunction() and renderMediaOnLambda()+> as far as I understand it right now, one would have to clone the monorepo to deploy it++Add firestore option for storing progress+https://www.remotion.dev/docs/renderer/render-media#onprogress\ No newline at end of filediff --git a/packages/gcp/src/admin/bundle-renderLogic.ts b/packages/gcp/src/admin/bundle-renderLogic.tsindex 550323babd..1915ed04e8 100644--- a/packages/gcp/src/admin/bundle-renderLogic.ts+++ b/packages/gcp/src/admin/bundle-renderLogic.ts@@ -2,20 +2,9 @@ import {BundlerInternals} from '@remotion/bundler';import {binaryPath as x64BinaryPath} from '@remotion/compositor-linux-x64-musl';import fs from 'fs';import path from 'path';-import zl = require('zip-lib');const bundleRenderLogic = async () => {- let renderTypeParam = process.argv[2];-- if (renderTypeParam === undefined) {- throw new Error('renderTypeParam is undefined');- }-- if (renderTypeParam !== 'renderStill' && renderTypeParam !== 'renderMedia') {- throw new Error('renderTypeParam must be either renderStill or renderMedia');- }-- const outdir = path.join(__dirname, '../../containers/', renderTypeParam, '/dist');+ const outdir = path.join(__dirname, '../../container/dist');fs.mkdirSync(outdir, {recursive: true,});@@ -41,7 +30,7 @@ const bundleRenderLogic = async () => {fs.copyFileSync(x64BinaryPath, compositorFile);- console.log(renderTypeParam + ' bundled.');+ console.log('distribution bundled.');};bundleRenderLogic()diff --git a/packages/gcp/src/index.ts b/packages/gcp/src/index.tsindex a3f50de6a8..2717dda478 100644--- a/packages/gcp/src/index.ts+++ b/packages/gcp/src/index.ts@@ -1,4 +1,18 @@+import * as ff from '@google-cloud/functions-framework';import { renderMediaSingleThread } from "./functions/render-media-single-thread";import { renderStillSingleThread } from "./functions/render-still-single-thread";-export { renderMediaSingleThread, renderStillSingleThread}\ No newline at end of file+export const renderOnCloudRun = async (req: ff.Request, res: ff.Response) => {+ const renderType = req.body.type;++ switch (renderType) {+ case 'media':+ await renderMediaSingleThread(req, res);+ break;+ case 'still':+ await renderStillSingleThread(req, res);+ break;+ default:+ res.status(400).send('Invalid render type, must be either "media" or "still"');+ }+};\ No newline at end of filediff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e67702b266..4e7f2199db 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -545,7 +545,6 @@ importers:remotion: 3.3.36ts-node: ^10.8.0typescript: ^4.7.0- zip-lib: ^0.7.2dependencies:'@google-cloud/functions-framework': 3.1.3'@google-cloud/storage': 6.9.1@@ -557,13 +556,6 @@ importers:prettier-plugin-organize-imports: 3.2.2_j2odc4yr77iddtreafyicbq5hits-node: 10.8.0_vnj66vw6pmisrnpmmxy72mdbpatypescript: 4.7.2- zip-lib: 0.7.2-- packages/gcp/container:- specifiers:- '@google-cloud/functions-framework': ^3.1.3- dependencies:- '@google-cloud/functions-framework': 3.1.3packages/gcp/containers/renderMedia:specifiers: