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

V4 #52

Merged
merged 5 commits into from
Jul 19, 2024
Merged

V4 #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions lib/release/api.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,29 @@
import pMap = require('p-map');
import type { PinejsClientCore, RetryParameters } from 'pinejs-client-core';
import { PinejsClientRequest } from 'pinejs-client-request';
import type { PinejsClientCore } from 'pinejs-client-core';
import * as models from './models';
import type { Dict } from './types';

import type { Composition } from '../../lib/parse';

const MAX_CONCURRENT_REQUESTS = 5;

export interface ClientConfig {
/**
* The host address of the API server to use, complete with the protocol,
* eg. `https://api.balena-cloud.com`. This module will issue requests to v4 of
* the API.
*/
apiEndpoint: string;

/**
* The complete string to forward as Authorization HTTP header, eg.
* `Bearer <authtoken>`.
*/
auth: string;

retry?: RetryParameters;
}

export function createClient(config: ClientConfig): PinejsClientRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that this is gone, there is a comment at line 58/28 that needs to be updated.

return new PinejsClientRequest({
apiPrefix: `${config.apiEndpoint}/v6/`,
passthrough: {
headers: {
Authorization: config.auth,
},
},
retry: config.retry,
});
}

export interface Request {
/**
* An instance of PineJS, appropriately authenticated and configured for the
* API server to use. The only compatible API version is v5, so make sure to
* API server to use. The compatible API versions are v5 and v6, so make sure to
* configure `apiPrefix` appropriately.
*
* ```
* import Pine = require('pinejs-client-request');
* import Pine from 'pinejs-client-fetch';
* const client = new Pine({
* apiPrefix: 'https://api.balena-cloud.com/v5',
* apiPrefix: 'https://api.balena-cloud.com/v6',
* passthrough: {
* headers: {
* Authorization: `Bearer ${authToken}`,
* },
* },
* });
* ```
*
* You can use the `createClient` convenience function of this module to create
* a client that can reused across requests.
*/
client: PinejsClientCore<unknown>;

Expand Down
5 changes: 0 additions & 5 deletions lib/release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
*/
export { create, Request, Response, updateImage, updateRelease } from './api';

/**
* Re-export convenience API to create a client.
*/
export { ClientConfig, createClient } from './api';

/**
* Re-export of all errors thrown by this module.
*/
Expand Down
20 changes: 7 additions & 13 deletions lib/resolve/resolvers/nodeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
import * as memoize from 'memoizee';

import * as _ from 'lodash';
import * as request from 'request';
import * as semver from 'semver';
import { promisify } from 'util';

const getAsync = promisify(request.get);

import type { Bundle, FileInfo, Resolver } from '../resolver';
import type { ParsedPathPlus } from '../utils';
Expand All @@ -34,19 +30,17 @@ const getDeviceTypeVersions = memoize(
let nextUrl: string | undefined =
`https://hub.docker.com/v2/repositories/resin/${deviceType}-node/tags/?page_size=100`;
while (nextUrl != null) {
const res = (
await getAsync({
url: nextUrl,
json: true,
})
).body as { results: Array<{ name: string }>; next?: string };

const curr: string[] = res.results
const response = (await fetch(nextUrl).then((res) => res.json())) as {
results: Array<{ name: string }>;
next?: string;
};

const curr: string[] = response.results
.map(({ name }) => name)
.filter(versionTest);

tags.push(...curr);
nextUrl = res.next;
nextUrl = response.next;
}

return tags;
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"README.md"
],
"engines": {
"node": ">=16.13.0"
"node": ">=20.6.0"
},
"scripts": {
"clean": "rimraf dist",
Expand Down Expand Up @@ -48,9 +48,8 @@
"@types/memoizee": "^0.4.11",
"@types/mocha": "^10.0.1",
"@types/mz": "^2.7.4",
"@types/node": "^16.18.65",
"@types/node": "^20.14.11",
"@types/proxyquire": "^1.3.28",
"@types/request": "^2.48.4",
"@types/semver": "^7.3.5",
"@types/tar-stream": "^2.2.0",
"chai": "^4.3.4",
Expand Down Expand Up @@ -84,8 +83,6 @@
"mz": "^2.7.0",
"p-map": "^4.0.0",
"pinejs-client-core": "^6.13.0",
"pinejs-client-request": "^7.3.5",
"request": "^2.88.2",
"semver": "^7.3.5",
"stream-to-promise": "^3.0.0",
"tar-stream": "^3.1.6",
Expand Down
Binary file modified test/build/test-files/archives/failure-layers.tar
Binary file not shown.
Binary file modified test/build/test-files/archives/failure.tar
Binary file not shown.
Binary file modified test/build/test-files/archives/success.tar
Binary file not shown.
24 changes: 8 additions & 16 deletions test/multibuild/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,10 @@ describe('Resolved project building', () => {
const newTask = resolveTask(task, 'amd64', 'intel-nuc', resolveListeners);

resolve(runBuildTask(newTask, docker, secretMap, buildVars));
})
.then((image) => {
expect(image).to.have.property('successful').that.equals(true);
return checkExists(image.name!);
})
.then((inspect: any) => {
expect(inspect).to.have.property('Architecture').that.equals('amd64');
});
}).then((image) => {
expect(image).to.have.property('successful').that.equals(false);
expect(image).to.have.property('error').that.is.not.null;
});
});

it('should build without "platform" flag (v1 manifest) for multi-stage builds', async () => {
Expand All @@ -349,14 +345,10 @@ describe('Resolved project building', () => {
const newTask = resolveTask(task, 'amd64', 'intel-nuc', resolveListeners);

resolve(runBuildTask(newTask, docker, secretMap, buildVars));
})
.then((image) => {
expect(image).to.have.property('successful').that.equals(true);
return checkExists(image.name!);
})
.then((inspect: any) => {
expect(inspect).to.have.property('Architecture').that.equals('amd64');
});
}).then((image) => {
expect(image).to.have.property('successful').that.equals(false);
expect(image).to.have.property('error').that.is.not.null;
});
});

it('should build using "platform" flag (v2 manifest) on third party registry', async () => {
Expand Down
Loading