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

Update node resolver #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as stream from 'node:stream';
import * as tar from 'tar-stream';

// Import hook definitions
import * as Plugin from './plugin';
import type * as Plugin from './plugin';
import * as Utils from './utils';

export type ErrorHandler = (error: Error) => void;
Expand Down
2 changes: 1 addition & 1 deletion lib/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import * as klaw from 'klaw';

import * as Plugin from './plugin';
import type * as Plugin from './plugin';

/**
* Given a docker 'arrow message' containing a sha representing
Expand Down
2 changes: 1 addition & 1 deletion lib/dockerfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function process(
return line[0] !== '#'
? lodash.template(line, { interpolate: /%%([A-Z][A-Z_]+)%%/ })(
variables,
)
)
: line;
})
.join('\n');
Expand Down
12 changes: 7 additions & 5 deletions lib/multibuild/build-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
* limitations under the License.
*/

import { Either, isLeft } from 'fp-ts/lib/Either';
import * as t from 'io-ts';
import type { Either } from 'fp-ts/lib/Either';
import { isLeft } from 'fp-ts/lib/Either';
import type * as t from 'io-ts';
import { reporter } from 'io-ts-reporters';
import * as jsYaml from 'js-yaml';
import * as _ from 'lodash';
import * as Path from 'path';
import type * as Stream from 'stream';
import * as tar from 'tar-stream';
import type * as tar from 'tar-stream';
import * as TarUtils from 'tar-utils';

import { BalenaYml, parsedBalenaYml, ParsedBalenaYml } from './build-secrets';
import type { BalenaYml, ParsedBalenaYml } from './build-secrets';
import { parsedBalenaYml } from './build-secrets';
import {
BalenaYMLValidationError,
MultipleBalenaConfigFilesError,
MultipleMetadataDirectoryError,
RegistrySecretValidationError,
} from './errors';
import * as PathUtils from './path-utils';
import type { RegistrySecrets } from './registry-secrets';
import {
addCanonicalDockerHubEntry,
RegistrySecrets,
RegistrySecretValidator,
} from './registry-secrets';

Expand Down
3 changes: 2 additions & 1 deletion lib/multibuild/build-secrets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import * as dockerfileTemplate from '../../dockerfile';

import type BuildMetadata from '../build-metadata';
import { BuildSecretMissingError, SecretPopulationError } from '../errors';
import { PermissiveVarList, VarList } from '../validation-types/varlist';
import type { VarList } from '../validation-types/varlist';
import { PermissiveVarList } from '../validation-types/varlist';
import { pipeline } from 'stream';

export const secretType = t.interface({
Expand Down
3 changes: 2 additions & 1 deletion lib/multibuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import * as _ from 'lodash';
import * as semver from 'semver';
import * as stream from 'stream';

import { Builder, BuildHooks, FromTagInfo } from '../build';
import type { BuildHooks, FromTagInfo } from '../build';
import { Builder } from '../build';

import type { SecretsPopulationMap } from './build-secrets';
import type { BuildTask } from './build-task';
Expand Down
2 changes: 1 addition & 1 deletion lib/multibuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import * as Compose from '../parse';

import { runBuildTask } from './build';
import BuildMetadata from './build-metadata';
import type { SecretsPopulationMap } from './build-secrets';
import {
BalenaYml,
generateSecretPopulationMap,
ParsedBalenaYml,
populateSecrets,
removeSecrets,
SecretsPopulationMap,
} from './build-secrets';
import type { BuildTask } from './build-task';
import * as contracts from './contracts';
Expand Down
4 changes: 2 additions & 2 deletions lib/parse/compose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Readable } from 'stream';
import type { Readable } from 'stream';
import * as _ from 'lodash';
import * as path from 'path';

Expand All @@ -13,7 +13,7 @@ import {
SchemaVersion,
validate,
} from './schemas';
import {
import type {
BuildConfig,
Composition,
Dict,
Expand Down
4 changes: 2 additions & 2 deletions lib/release/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import pMap = require('p-map');
import type { PinejsClientCore, RetryParameters } from 'pinejs-client-core';
import { PinejsClientRequest } from 'pinejs-client-request';
import * as models from './models';
import { Dict } from './types';
import type { Dict } from './types';

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

const MAX_CONCURRENT_REQUESTS = 5;

Expand Down
3 changes: 2 additions & 1 deletion lib/resolve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/
import * as _ from 'lodash';
import { Readable, pipeline } from 'stream';
import type { Readable } from 'stream';
import { pipeline } from 'stream';
import * as tar from 'tar-stream';
import * as TarUtils from 'tar-utils';

Expand Down
2 changes: 1 addition & 1 deletion lib/resolve/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Bundle from './bundle';
import { FileInfo } from './fileInfo';
import { ParsedPathPlus } from './utils';
import type { ParsedPathPlus } from './utils';

// Make the external types available to implementers
export { Bundle, FileInfo };
Expand Down
5 changes: 3 additions & 2 deletions lib/resolve/resolvers/archDockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { posix } from 'path';

import * as DockerfileTemplate from '../../dockerfile';

import { Bundle, FileInfo, Resolver } from '../resolver';
import { ParsedPathPlus, removeExtension } from '../utils';
import type { Bundle, FileInfo, Resolver } from '../resolver';
import type { ParsedPathPlus } from '../utils';
import { removeExtension } from '../utils';
import { DockerfileTemplateVariableError } from './dockerfileTemplate';

// Internal tuple to pass files and their extensions around
Expand Down
6 changes: 3 additions & 3 deletions lib/resolve/resolvers/dockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Bundle } from '../resolver';
import type { Bundle } from '../resolver';

import { FileInfo, Resolver } from '../resolver';
import { ParsedPathPlus } from '../utils';
import type { FileInfo, Resolver } from '../resolver';
import type { ParsedPathPlus } from '../utils';

export class DockerfileResolver implements Resolver {
public priority = 0;
Expand Down
5 changes: 3 additions & 2 deletions lib/resolve/resolvers/dockerfileTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import { TypedError } from 'typed-error';

import * as DockerfileTemplate from '../../dockerfile';
import { Bundle, FileInfo, Resolver } from '../resolver';
import { ParsedPathPlus, removeExtension } from '../utils';
import type { Bundle, FileInfo, Resolver } from '../resolver';
import type { ParsedPathPlus } from '../utils';
import { removeExtension } from '../utils';

export class DockerfileTemplateVariableError extends TypedError {}

Expand Down
17 changes: 10 additions & 7 deletions lib/resolve/resolvers/nodeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import { promisify } from 'util';

const getAsync = promisify(request.get);

import { Bundle, FileInfo, Resolver } from '../resolver';
import { ParsedPathPlus } from '../utils';
import type { Bundle, FileInfo, Resolver } from '../resolver';
import type { ParsedPathPlus } from '../utils';

const versionTest = RegExp.prototype.test.bind(/^[0-9]+\.[0-9]+\.[0-9]+$/);
const getDeviceTypeVersions = memoize(
async (deviceType: string): Promise<string[]> => {
const tags: string[] = [];
// 100 is the max page size
let nextUrl: string | undefined =
`https://hub.docker.com/v2/repositories/resin/${deviceType}-node/tags/?page_size=100`;
`https://hub.docker.com/v2/repositories/balenalib/${deviceType}-node/tags/?page_size=100`;
while (nextUrl != null) {
const res = (
await getAsync({
Expand All @@ -41,11 +41,14 @@ const getDeviceTypeVersions = memoize(
})
).body as { results: Array<{ name: string }>; next?: string };

const curr: string[] = res.results
.map(({ name }) => name)
.filter(versionTest);
// sometimes the last result is undefined
if (res.results !== undefined) {
const curr: string[] = res.results
.map(({ name }) => name)
.filter(versionTest);
tags.push(...curr);
}

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

Expand Down
3 changes: 2 additions & 1 deletion lib/resolve/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

import { ParsedPath, posix } from 'path';
import type { ParsedPath } from 'path';
import { posix } from 'path';

export interface ParsedPathPlus extends ParsedPath {
minusExt: string;
Expand Down
3 changes: 2 additions & 1 deletion test/build/all.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import * as url from 'url';

import * as proxyquire from 'proxyquire';

import { Builder, BuildHooks } from '../../lib/build';
import type { BuildHooks } from '../../lib/build';
import { Builder } from '../../lib/build';
import * as Utils from '../../lib/build/utils';

const TEST_FILE_PATH = 'test/build/test-files';
Expand Down
3 changes: 2 additions & 1 deletion test/build/build_stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/
import { assert } from 'chai';
import { Readable, Stream, Writable } from 'stream';
import type { Readable, Writable } from 'stream';
import { Stream } from 'stream';

import * as proxyquire from 'proxyquire';

Expand Down
6 changes: 3 additions & 3 deletions test/multibuild/build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import * as Dockerode from 'dockerode';
import * as fs from 'fs';
import * as Path from 'path';
import * as Stream from 'stream';
import * as tar from 'tar-stream';
import type * as Stream from 'stream';
import type * as tar from 'tar-stream';
import * as Url from 'url';

import BuildMetadata from '../../lib/multibuild/build-metadata';
import { BalenaYml } from '../../lib/multibuild/build-secrets';
import type { BalenaYml } from '../../lib/multibuild/build-secrets';

export const TEST_FILES_PATH = 'test/multibuild/test-files';

Expand Down
8 changes: 2 additions & 6 deletions test/multibuild/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ import {

import * as Compose from '../../lib/parse';

import {
splitBuildStream,
BuildTask,
BuildProcessError,
LocalImage,
} from '../../lib/multibuild';
import type { BuildTask, LocalImage } from '../../lib/multibuild';
import { splitBuildStream, BuildProcessError } from '../../lib/multibuild';
import { runBuildTask } from '../../lib/multibuild/build';
import { resolveTask } from '../../lib/multibuild/resolve';

Expand Down
6 changes: 4 additions & 2 deletions test/multibuild/manifests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
* limitations under the License.
*/

import type {
DockerImageManifest,
DockerImageManifestPlatform,
} from '../../lib/multibuild/manifests';
import {
MEDIATYPE_MANIFEST_V1,
MEDIATYPE_MANIFEST_LIST_V2,
MEDIATYPE_MANIFEST_V2,
MEDIATYPE_OCI_IMAGE_INDEX_V1,
getManifest,
DockerImageManifest,
DockerImageManifestPlatform,
} from '../../lib/multibuild/manifests';
import { expect } from 'chai';
import * as Dockermodem from 'docker-modem';
Expand Down
5 changes: 3 additions & 2 deletions test/multibuild/multibuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as fs from 'fs';
import * as Stream from 'stream';
import type * as Stream from 'stream';

import {
checkExists,
Expand All @@ -27,7 +27,8 @@ import {
TEST_FILES_PATH,
} from './build-utils';

import { performBuilds, BuildTask, LocalImage } from '../../lib/multibuild';
import type { BuildTask, LocalImage } from '../../lib/multibuild';
import { performBuilds } from '../../lib/multibuild';
import BuildMetadata from '../../lib/multibuild/build-metadata';

chai.use(chaiAsPromised);
Expand Down
2 changes: 1 addition & 1 deletion test/multibuild/registry-secrets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import * as fs from 'fs';

import { normalize } from '../../lib/parse';

import type { RegistrySecrets } from '../../lib/multibuild';
import {
addCanonicalDockerHubEntry,
RegistrySecrets,
RegistrySecretValidator,
RegistrySecretValidationError,
splitBuildStream,
Expand Down
4 changes: 2 additions & 2 deletions test/multibuild/resolve.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as fs from 'fs';
import { Pack } from 'tar-stream';
import type { Pack } from 'tar-stream';

import BuildMetadata from '../../lib/multibuild/build-metadata';
import { BuildTask } from '../../lib/multibuild';
import type { BuildTask } from '../../lib/multibuild';
import { resolveTask } from '../../lib/multibuild/resolve';

import { TEST_FILES_PATH } from './build-utils';
Expand Down
2 changes: 1 addition & 1 deletion test/multibuild/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as Stream from 'stream';
import type * as Stream from 'stream';
import * as tar from 'tar-stream';

import * as Compose from '../../lib/parse';
Expand Down
9 changes: 5 additions & 4 deletions test/resolve/all.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { expect, use } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as fs from 'fs';
import { Readable } from 'stream';
import type { Readable } from 'stream';
import * as tar from 'tar-stream';
import * as TarUtils from 'tar-utils';

Expand Down Expand Up @@ -309,13 +309,14 @@ describe('Resolvers', () => {
);
});

it.skip('should resolve a nodeJS project', function () {
this.timeout(3600000);
it('should resolve a nodeJS project', function () {
// test often takes around 40 sec to complete
this.timeout(180000);
const deviceType = 'raspberrypi3';
return testResolveInput({
deviceType,
dockerfileContentMatcher: (contents) =>
contents.startsWith(`FROM resin/${deviceType}-node:10.0.0-onbuild`),
contents.startsWith(`FROM resin/${deviceType}-node:18.0.0-onbuild`),
expectedResolvedDockerfilePath: undefined,
expectedResolverName: 'NodeJS',
specifiedDockerfilePath: undefined,
Expand Down
Binary file modified test/resolve/test-files/NodeProject/archive.tar
Binary file not shown.
2 changes: 1 addition & 1 deletion test/resolve/test-files/NodeProject/archive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"express": "^4.15.2"
},
"engines": {
"node": "10.0.0"
"node": "18.0.0"
}
}
2 changes: 1 addition & 1 deletion typings/event-stream.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Stream } from 'stream';
import type { Stream } from 'stream';

/**
* Additional typing information that is merged with that available in the npm
Expand Down
Loading