diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d3b34b6d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +examples/assets diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 80% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 2e131f9f..1f489fa0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Test +name: CI on: push: @@ -72,6 +72,7 @@ jobs: cache: "npm" cache-dependency-path: ./package.json - run: npm install + - run: npm run build - run: npm run lint - run: npm run test - uses: actions/upload-artifact@v4 @@ -80,3 +81,19 @@ jobs: path: editly-out.mp4 compression-level: 0 if-no-files-found: error + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: mifi/editly-assets + path: examples/assets + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.nodejs }} + cache: "npm" + cache-dependency-path: ./package.json + - run: docker compose build + - run: docker compose up -d + - run: docker compose run editly bash -c "cd examples && ./run audio1.json5" diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index c4fbb0d7..82b5067a 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -47,9 +47,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 22 - cache: "yarn" + cache: "npm" cache-dependency-path: ./package.json - - run: yarn install + - run: npm install && npm run build - run: | cd examples ./run "${{ matrix.example }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6e6b0385 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + push: + branches: + - "master" + tags: + - "v*" + +jobs: + docker: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: editly/editly + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 202d27ee..258bc1a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,58 +1,65 @@ -FROM jrottenberg/ffmpeg:4.3.1-ubuntu1804 +FROM node:lts-bookworm AS build + +# Install dependencies for building canvas/gl +RUN apt-get update -y + +RUN apt-get -y install \ + build-essential \ + libcairo2-dev \ + libgif-dev \ + libgl1-mesa-dev \ + libglew-dev \ + libglu1-mesa-dev \ + libjpeg-dev \ + libpango1.0-dev \ + librsvg2-dev \ + libxi-dev \ + pkg-config \ + python-is-python3 WORKDIR /app -# Ensures tzinfo doesn't ask for region info. -ENV DEBIAN_FRONTEND noninteractive - -## INSTALL NODE VIA NVM - -RUN apt-get update && apt-get install -y \ - dumb-init \ - xvfb - -# Source: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a -# replace shell with bash so we can source files -RUN rm /bin/sh && ln -s /bin/bash /bin/sh - -# update the repository sources list -# and install dependencies -RUN apt-get update \ - && apt-get install -y curl \ - && apt-get -y autoclean - -# nvm environment variables -ENV NVM_VERSION 0.37.2 -ENV NVM_DIR /usr/local/nvm -ENV NODE_VERSION 14.4.0 - -# install nvm -# https://github.com/creationix/nvm#install-script -RUN mkdir -p $NVM_DIR \ - && curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh | bash - -# install node and npm -RUN source ${NVM_DIR}/nvm.sh \ - && nvm install $NODE_VERSION \ - && nvm alias default $NODE_VERSION \ - && nvm use default - -# add node and npm to path so the commands are available -ENV NODE_PATH ${NVM_DIR}/v${NODE_VERSION}/lib/node_modules -ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:$PATH - -# confirm installation -RUN node -v -RUN npm -v - -## INSTALL EDITLY - -# ## Install app dependencies -COPY package.json /app/ -RUN npm install +# Install node dependencies +COPY package.json ./ +RUN npm install --no-fund --no-audit # Add app source -COPY . /app +COPY . . + +# Build TypeScript +RUN npm run build + +# Prune dev dependencies +RUN npm prune --omit=dev + +# Purge build dependencies +RUN apt-get --purge autoremove -y \ + build-essential \ + libcairo2-dev \ + libgif-dev \ + libgl1-mesa-dev \ + libglew-dev \ + libglu1-mesa-dev \ + libjpeg-dev \ + libpango1.0-dev \ + librsvg2-dev \ + libxi-dev \ + pkg-config \ + python-is-python3 + +# Remove Apt cache +RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/* + +# Final stage for app image +FROM node:lts-bookworm + +# Install runtime dependencies +RUN apt-get update -y \ + && apt-get -y install ffmpeg dumb-init xvfb libcairo2 libpango1.0 libgif7 librsvg2-2 \ + && rm -rf /var/lib/apt/lists/* /var/cache/apt/* + +WORKDIR /app +COPY --from=build /app /app # Ensure `editly` binary available in container RUN npm link diff --git a/docker-compose.yml b/docker-compose.yml index f74659c8..709df07b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: editly: container_name: editly @@ -9,6 +7,7 @@ services: dockerfile: Dockerfile volumes: - "outputs:/outputs" + - ./examples/assets/:/app/examples/assets/ volumes: outputs: diff --git a/examples/README.md b/examples/README.md index c3f2fde4..667c17d6 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,6 +8,7 @@ How to run examples: git clone https://github.com/mifi/editly.git cd editly npm install +npm run build cd examples git clone https://github.com/mifi/editly-assets.git assets ./run commonFeatures.json5 diff --git a/examples/customFabric.ts b/examples/customFabric.ts index 6b82d517..bfcb37c5 100644 --- a/examples/customFabric.ts +++ b/examples/customFabric.ts @@ -1,5 +1,5 @@ import editly from 'editly'; -import { CustomFabricFunctionArgs, CustomFabricFunctionCallbacks } from '../dist/index.js'; +import type { CustomFabricFunctionArgs, CustomFabricFunctionCallbacks } from 'editly'; function func({ width, height, fabric }: CustomFabricFunctionArgs): CustomFabricFunctionCallbacks { return { diff --git a/package.json b/package.json index 6b56997a..037e13e5 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "p-map": "^7.0.2" }, "scripts": { - "prepare": "pkgroll --clean-dist --sourcemap", + "build": "pkgroll --clean-dist --sourcemap", + "prepublishOnly": "npm run build", "test": "tsx test/index.ts", "lint": "eslint ." }, diff --git a/src/sources/fabric.ts b/src/sources/fabric.ts index 4af4ba59..d5fab289 100644 --- a/src/sources/fabric.ts +++ b/src/sources/fabric.ts @@ -1,8 +1,7 @@ import * as fabric from 'fabric/node'; import { type CanvasRenderingContext2D, createCanvas, ImageData } from 'canvas'; import { boxBlurImage } from '../BoxBlur.js'; -import type { CreateFrameSourceOptions, FrameSource, CanvasLayer, CustomFabricFunctionCallbacks, Layer } from '../types.js'; -import { OptionalPromise } from '../../dist/index.js'; +import type { CreateFrameSourceOptions, FrameSource, CanvasLayer, CustomFabricFunctionCallbacks, Layer, OptionalPromise } from '../types.js'; export type FabricFrameSourceOptions = CreateFrameSourceOptions & { fabric: typeof fabric }; export type FabricFrameSourceCallback = (options: FabricFrameSourceOptions) => OptionalPromise;