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

New docker image for version of directus with sharp0.32.5 installed #19696

Closed
AndriyAntonenko opened this issue Sep 15, 2023 · 12 comments
Closed

Comments

@AndriyAntonenko
Copy link

Describe the Improvement

Issue Description

I'm currently working on creating a Directus extension (hook) to split some of my images into tiles. To achieve this, I'm trying to use the sharp library, which is already a part of Directus API. My current version of Directus is 10.6.1, and it is using sharp@0.32.1. Unfortunately, this version of sharp does not support tile splitting properly, which is essential for my project.

I noticed that a new version of sharp@0.32.5 has been released, which addresses the issue I'm facing. However, I need a Docker image for this new version to integrate it into my environment.

Question

Could you please provide an estimate of when the new Docker image with sharp@0.32.5 will be released? This information would be incredibly helpful for planning my project.

Thank you for your assistance!

@AndriyAntonenko
Copy link
Author

Here is the issue, that I faced using sharp@0.32.1 3581

@DanielBiegler
Copy link
Contributor

#19658 updated the sharp dependency which will then be available to you in the next release. Can't give you an exact date but you could just build your own version for the meanwhile and switch back to our image once its released. A custom extension is also a great choice. See the extension-docs.

@DanielBiegler DanielBiegler closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
@AndriyAntonenko
Copy link
Author

@DanielBiegler, thank you for the quick response! Do you mean to build docker image by my own? Also, I didn't get how to use another version of Sharp in the Directus extension. Can you please clarify?

@DanielBiegler
Copy link
Contributor

DanielBiegler commented Sep 15, 2023

The new sharp version already got merged into our main branch which means you can clone the repository and build the image yourself, yes. See our Dockerfile. Then you could replace the image in your docker-compose to use your own new image.

You could also build the project for running locally.

Regarding extensions you can add the sharp dependency and use it wherever you need it. (Hooks, Operations, ...)

@AndriyAntonenko
Copy link
Author

Ok, thank you for your help! Have a nice day!

@AndriyAntonenko
Copy link
Author

Unfortunately, it doesn't resolve my issue. When I am using a local Directus image, my extension cannot resolve sharp dependency
Знімок екрана 2023-09-15 о 14 19 47

I've build Directus using docker build -t custom-directus . in the root of the Directus repository

Here is a part of my docker compose file to run my directus application

    directus:
        container_name: directus-do
        image: custom-directus
        ports:
            - 8055:8055
            - 587:587
        restart: on-failure
        volumes:
            - ./uploads:/directus/uploads
            - ./extensions:/directus/extensions
        env_file:
            - .dev.do.env

Also, here is the way how I import sharp library

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
import type { Sharp, SharpOptions } from 'sharp';
const sharp: (opts?: SharpOptions) => Sharp = require('sharp'); // @HACK: sharp is not a esm module

@AndriyAntonenko
Copy link
Author

@DanielBiegler could you check it, please? Is everything correct?

@DanielBiegler
Copy link
Contributor

What does your package.json of the extension look like? Did you install sharp?

@AndriyAntonenko
Copy link
Author

@DanielBiegler here is my package.json

{
	"name": "directus-extension-do",
	"version": "1.0.0",
	"type": "module",
	"dependencies": {
		"@directus/api": "^13.0.0",
		"icc": "3.0.0",
		"pino": "^8.14.1",
		"sharp": "0.32.5"
	},
	"directus:extension": {
		"host": "^10.1.7",
		"type": "bundle",
		"path": {
			"app": "../extensions/directus-extension-do/dist/app.js",
			"api": "../extensions/directus-extension-do/dist/api.js"
		},
		"entries": [
			{
				"type": "hook",
				"name": "locations-json-to-db",
				"source": "src/locations/json-to-db/index.ts"
			},
			{
				"type": "interface",
				"name": "locations-autocomplete-interface",
				"source": "src/locations/autocomplete-interface/index.ts"
			},
			{
				"type": "hook",
				"name": "locations-save-locations-to-related-fields",
				"source": "src/locations/save-locations-to-related-fields/index.ts"
			},
			{
				"type": "endpoint",
				"name": "impressions",
				"source": "src/impressions/index.ts"
			},
			{
				"type": "interface",
				"name": "digital-original-input",
				"source": "src/interfaces/digital-original-input/index.ts"
			},
			{
				"type": "endpoint",
				"name": "api",
				"source": "src/api/index.ts"
			},
			{
				"type": "hook",
				"name": "do-tiles",
				"source": "src/do-tiles/index.ts"
			}
		]
	},
	"description": "Please enter a description for your extension",
	"icon": "extension",
	"keywords": [
		"directus",
		"directus-extension",
		"directus-custom-bundle"
	],
	"scripts": {
		"build": "directus-extension build",
		"dev": "directus-extension build -w --no-minify",
		"link": "directus-extension link",
		"add": "directus-extension add"
	},
	"devDependencies": {
		"@directus/extensions-sdk": "10.1.7",
		"@types/node": "^20.6.2",
		"typescript": "^5.2.2",
		"vue": "^3.3.4"
	}
}

Also, here is the result of npm ls sharp

directus-extension-do@1.0.0 /Users/insomnia.exe/Workspace/digitaloriginal/do-directus-develop/do-extensions
├─┬ @directus/api@13.0.0
│ └── sharp@0.32.1
└── sharp@0.32.5

@AndriyAntonenko
Copy link
Author

Also, when I am using image directus/directus:10.6.1, and installing sharp@0.32.5, the runtime is using version 0.32.1. I've checked it by calling such function

import fs from 'fs/promises';

async function checkSharpVersion() {
	const dirs = await fs.readdir('node_modules');
	for (const dir of dirs) {
		try {
			console.info("Checking '" + dir + "'");
			if (dir !== 'sharp') continue;
			const file = 'node_modules/' + dir + '/package.json';
			const json = JSON.parse(await fs.readFile(file, 'utf-8'));
			const name = json.name;
			const version = json.version;
			console.info("Found '" + name + "' version " + version + ' in ' + file);
			console.log(name + ': ' + version);
		} catch (err) {}
	}
}

and here is the output from the console

directus-do                        | Checking 'sharp'
directus-do                        | Found 'sharp' version 0.32.1 in node_modules/sharp/package.json
directus-do                        | sharp: 0.32.1

@paescuj
Copy link
Member

paescuj commented Sep 17, 2023

Hey @AndriyAntonenko 👋 Please note that sharp is a native module, which means it can't & won't be included in the bundle of your hook extension. Therefore the version of sharp is used, which comes with Directus.
We'll publish a release very soon which includes the updated version of sharp (#19658).

@AndriyAntonenko
Copy link
Author

AndriyAntonenko commented Sep 17, 2023

@paescuj thanks for your answer. I will wait for it. My application require this update)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants