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

feat: debian datasource #13463

Closed
wants to merge 42 commits into from
Closed

Conversation

Ka0o0
Copy link

@Ka0o0 Ka0o0 commented Jan 10, 2022

Changes:

Context:

This datasource is able to search multiple Debian package sources that provide a Packages file as described here.
This repository standard defines components within a release repository (e.g. main within bullseye release).

The datasource works by downloading the compressed Packages file for each component and extracting it. Currently, only .xz files are supported, but it should be possible to add other compression standards as well.
The file is downloaded using curl, which is a shell cmd call, into a configurable folder.
The file is only downloaded if the local version is older than what the server has (using curl's -z parameter) and is only extracted if needed.

The file is then searched through, currently, line by line which is a bit slow with Node.JS and further work might improve the performance by removing unused information from the extracted files.
It then returns the latest version which is, differently from what repology is returning us, the version you can specify with apt install, like apt-get install curl=7.74.0-1.3+deb11u1. An example PR created with this banch merged looks like this: Ka0o0/renovate-testrepo#2

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

Open Points

  • Where to add documentation?
  • Is the current implementation regarding the datasource configuration valid like it is currently?
  • This datasource calls some third party tools which are currently available in the renovate Docker image. Are any changes to how this is used required, like explicitly stating the dependency somewhere?

@HonkingGoose
Copy link
Collaborator

  • Where to add documentation?

Once the code for the feature is approved by the maintainers, the documentation can be added in a new lib/datasource/deb/readme.md file, I think.

The "Repology datasource" has docs that you can look at for inspiration. 1

Footnotes

  1. https://github.com/renovatebot/renovate/blob/main/lib/datasource/repology/readme.md

@rarkins rarkins changed the title Add Debian package datasource feat: debian datasource Jan 10, 2022
@rarkins
Copy link
Collaborator

rarkins commented Jan 10, 2022

Hi @Ka0o0, thanks for this PR! Can you create a feature request issue to link to from this PR, and so we can discuss the requirements/implementation proposal there first?

@Ka0o0
Copy link
Author

Ka0o0 commented Jan 10, 2022

Hi @rarkins,

thanks for pointing that out. Actually, there is #7041 already opened which I've referenced in this PR's description.

lib/datasource/deb/index.spec.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/api.ts Outdated Show resolved Hide resolved
@Ka0o0 Ka0o0 requested a review from viceice January 13, 2022 15:56
@viceice
Copy link
Member

viceice commented Jan 13, 2022

Please do not use simple Done like comments, they produce a lot of noise.

@HonkingGoose Can we extend our contribution guide? So people should simply resolve conversations when done and only use re-request review button. Any only if no maintainer answer, use comments after ~5days.

@rarkins WDYT?

@HonkingGoose
Copy link
Collaborator

@HonkingGoose Can we extend our contribution guide? So people should simply resolve conversations when done and only use re-request review button. Any only if no maintainer answer, use comments after ~5days.

Sounds good to me. Is the goal here to reduce noise, and to "teach" contributors to wait a bit before commenting?

Our .github/contributing.md file says: 1

Re-requesting a review

Please do not ping your reviewer(s) by mentioning them in a new comment.
Instead, use the re-request review functionality.
Read more about this in the GitHub docs, Re-requesting a review.

Footnotes

  1. https://github.com/renovatebot/renovate/blob/main/.github/contributing.md#re-requesting-a-review

@viceice
Copy link
Member

viceice commented Jan 13, 2022

@HonkingGoose Can we extend our contribution guide? So people should simply resolve conversations when done and only use re-request review button. Any only if no maintainer answer, use comments after ~5days.

Sounds good to me. Is the goal here to reduce noise, and to "teach" contributors to wait a bit before commenting?

So we only need some sentence about to suppress short comments like Done and instead resolve conversation.

lib/datasource/deb/index.spec.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
@Ka0o0 Ka0o0 requested a review from viceice January 14, 2022 08:22
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Show resolved Hide resolved
return needsToDownload;
}

async probeExtractedPackage(
Copy link
Member

Choose a reason for hiding this comment

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

This is a goot candidate to add cache decorator, sample:

@cache({
namespace: `datasource-${TerraformProviderDatasource.id}-build-hashes`,
key: (build: TerraformBuild) => build.url,
ttlMinutes: TerraformProviderHash.hashCacheTTL,
})
static async calculateSingleHash(
build: TerraformBuild,
cacheDir: string
): Promise<string> {

Copy link
Author

Choose a reason for hiding this comment

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

Mhm but what if the server returns a new compressed file, can I manually invalidate the cache entry then?

Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

@rarkins I'm still somehow unconfident with the current cache mechanism. I think we should extract all updates and write to renovate cache with additional metadata. And only use cache if still valid.

Comment on lines 10 to 11
const testPackagesFile = __dirname + '/test-data/Packages.gz';
const extractedTestFile = __dirname + '/test-data/Packages';
Copy link
Member

Choose a reason for hiding this comment

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

We have helpers for this, checkout fixtures class

Copy link
Author

Choose a reason for hiding this comment

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

The only test case where I think a fixture would make sense is this one. However, I don't quite know how to get it running.

If I understood it correctly, the Fixtures.mock method will register some temp files based on what is provided as a parameter and intercept FS calls to those files? So I'm setting up the test case like this (basically replacing line 44 - 45):

const fixtures: DirectoryJSON = {};
fixtures[extractedPackageFile] = Fixtures.get('Packages');
Fixtures.mock(fixtures);

But now the test case would fail here. Shouldn't the Fixtures' mock make sure that the file exists?

lib/datasource/deb/index.spec.ts Outdated Show resolved Hide resolved
expect(res.releases).toHaveLength(1);

// validate that the server was called correctly
expect(httpMock.getTrace()).toHaveLength(1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(httpMock.getTrace()).toHaveLength(1);

This will be always equal to your mocked http requests, so no benefit. 😉

Copy link
Author

Choose a reason for hiding this comment

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

Unfulfilled mocks are only evaluated after the test block. In the next line the array access on getTrace() would therefore be executed which would lead to an runtime exception in a failing test case scenario.

Copy link
Member

Choose a reason for hiding this comment

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

Yes and no, if you look at the http mock code, you can see a afterEach which will validate this, so we don't have to repeat it here. 😉

lib/datasource/deb/index.spec.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
lib/datasource/deb/index.ts Outdated Show resolved Hide resolved
Comment on lines +182 to +185
const rl = readline.createInterface({
input: fs.createReadStream(extractedFile),
terminal: false,
});
Copy link
Member

Choose a reason for hiding this comment

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

I think we should cache the compressed file and directly stream if possible. Would sava a lot disk space. 🤔

Copy link
Author

Choose a reason for hiding this comment

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

I agree that would indeed some disk space for the cost of computational expense. I was also thinking about removing some unused meta information from the extracted Package file which would also reduce the package file size and reduce the lookup time (which is more important I guess). What do you think?

lib/util/fs/index.ts Outdated Show resolved Hide resolved
@Ka0o0 Ka0o0 requested a review from viceice February 21, 2022 15:12
@rarkins rarkins marked this pull request as draft March 25, 2022 10:13
@rarkins
Copy link
Collaborator

rarkins commented Mar 25, 2022

Needs test fixes

@@ -0,0 +1,41 @@
import { createReadStream } from 'fs';
Copy link
Member

Choose a reason for hiding this comment

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

why this file?

return fs.createReadStream(path);
}

export function access(path: string, mode?: number): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

move to ./proxies.ts

@@ -0,0 +1,182 @@
import { copyFile, mkdirp, stat } from 'fs-extra';
Copy link
Member

Choose a reason for hiding this comment

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

file structure changed, please move datasource to right folder.

please don't force-push

@rarkins
Copy link
Collaborator

rarkins commented Oct 19, 2022

Closing due to staleness

@rarkins rarkins closed this Oct 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add apt datasource for private repositories
4 participants