Skip to content

Conversation

esseswann
Copy link

@esseswann esseswann commented Sep 2, 2022

Resolves #173

Package version fix is relatively straightforward
For certificates search path refer to the ced8e20
It is still recommended to use some kind of bundler like esbuild itself to bake the certs and version into the compiled code

const RELATIVE_PATH = process.env.TEST_ENVIRONMENT ? '../' : './'
const RESOLVED_PATH = path.join(__dirname, RELATIVE_PATH, CERTIFICATES_FOLDER)
const FALLBACK_INTERNAL_ROOT_CERTS = path.join(RESOLVED_PATH, 'internal.pem');
const FALLBACK_SYSTEM_ROOT_CERTS = path.join(RESOLVED_PATH, 'system.pem');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему бы содержимое сертификатов не положить в текстовом виде в переменную в какой-нибудь js модуль и не реквайрить их как обычно? Кажется это решит все проблемы (в том числе с бандлерами).

Copy link
Collaborator

@DavyJohnes DavyJohnes Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// certs.js

module.exports = {
  internal: '<text_contenxt_of_cert>',
  fallback: '<text_contenxt_of_cert>'
}

Copy link
Author

@esseswann esseswann Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я вполне с этим согласен -- это предлагалось, однако по уму их надо бандлить вебпком во время компиляции из файлов\по урлу. Если есть консенсус по этому вопросу могу реализовать как через бандлер, так и переменной в .js

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А расскажите, в какой ситуации здесь появляются бандлеры? Ведь ydb-nodejs-sdk - это нодовая библиотека и, кажется, нет особого смысла бандлить/минифицировать код, который выполняется на ноде и не доезжает до клиента.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Смысл еще как есть. Кроме того, что код собирается в один файлик (что при прочих равных удобно) так еще и размер артефакта значительно меньше (учитывая что все node_modules не надо тащить). В контексте serverless функции очень значимый момент.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хотелось бы понять можно ли всё-таки добавить webpack\esbuild для бандлинга cert или вставить сертификаты руками в код как предлагал @DavyJohnes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я правильно понимаю, что бандлер и зависимости ydb-sdk тоже в бандл положит?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, он соберёт всё в один файл
Я тут посмотрел на размер system.pem, он довольно здоровый, поэтому я бы рекомендовал рассмотреть возможность скачивания его с публичного хранилища

const RELATIVE_PATH = process.env.TEST_ENVIRONMENT ? '../' : './'
const RESOLVED_PATH = path.join(__dirname, RELATIVE_PATH, CERTIFICATES_FOLDER)
const FALLBACK_INTERNAL_ROOT_CERTS = path.join(RESOLVED_PATH, 'internal.pem');
const FALLBACK_SYSTEM_ROOT_CERTS = path.join(RESOLVED_PATH, 'system.pem');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А расскажите, в какой ситуации здесь появляются бандлеры? Ведь ydb-nodejs-sdk - это нодовая библиотека и, кажется, нет особого смысла бандлить/минифицировать код, который выполняется на ноде и не доезжает до клиента.

This is a poor man's fix for bundling compilers like esbuild\webpack
that require paths to be relative to the entry point.
Certs folder is moved into cjs\esm dists so we can utilize universal
path './certs' that would work for default tsc compilation and would
allow copying the certs folder to whatever path bundler is gonna output
compiled entry point.
Some sensible error communication is also added
This commit is not marked as breaking because if certs folder had not
been found when grpcs is present in previous implementation
the connection would not succeed and\or "File not found" error threw
@tsufiev tsufiev merged commit 9a5d104 into ydb-platform:main Sep 13, 2022
@esseswann esseswann deleted the fix/esbuild branch September 13, 2022 10:57
throw new Error(certificateNotFoundMessage)
}

const internalRootCertificates = fs.readFileSync(FALLBACK_INTERNAL_ROOT_CERTS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esseswann @tsufiev а почему решили оставить чтение с fs? Это тоже потребует дополнительной настройки бандлера. Может таки положим в виде строки в js модуль?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я не против, но меня немного смущает размер system.pem, возможно стоит обдумать как это можно сделать конфигурируемо

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так а какая разница? Он тут так или иначе в памяти окажется, читаешь ты его с fs или реквайришь как js модуль.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там есть кейс при котором его чтение необязательно, следовательно мы просто разжираем размер бандла. Это правда не меняет ситуацию относительно текущей, но теоретически можно было бы этого избежать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Referencing package.json breaks minification builds like esbuild

3 participants