diff --git a/src/commands/from_github.ts b/src/commands/from_github.ts index 4245a307..ed9a5c12 100644 --- a/src/commands/from_github.ts +++ b/src/commands/from_github.ts @@ -5,13 +5,7 @@ import { CommandModule } from "yargs"; import chalk from "chalk"; import inquirer from "inquirer"; import moment from "moment"; -import { - contentHashFile, - getImagePath, - getLegacyImagePath, - releaseFiles, - releaseFilesDefaultNames -} from "../params.js"; + import { getInstallDnpLink } from "../utils/getLinks.js"; import { githubGetReleases, @@ -20,7 +14,15 @@ import { import { ipfsAddDirFromUrls } from "../releaseUploader/ipfsNode/addDirFromUrls.js"; import { verifyIpfsConnection } from "../releaseUploader/ipfsNode/verifyConnection.js"; import { CliGlobalOptions } from "../types.js"; -import { Manifest, defaultArch } from "@dappnode/types"; +import { + Manifest, + defaultArch, + getImagePath, + getLegacyImagePath, + releaseFilesDefaultNames, + releaseFiles, + contentHashFile +} from "@dappnode/types"; interface CliCommandOptions extends CliGlobalOptions { repoSlug: string; diff --git a/src/commands/githubActions/endToEndTest/testCheckers.ts b/src/commands/githubActions/endToEndTest/testCheckers.ts index 8ad293db..1e195c23 100644 --- a/src/commands/githubActions/endToEndTest/testCheckers.ts +++ b/src/commands/githubActions/endToEndTest/testCheckers.ts @@ -2,8 +2,7 @@ import chalk from "chalk"; import Docker from "dockerode"; import got from "got"; import { ValidatorData } from "./types.js"; -import { getContainerName } from "../../../params.js"; -import { Compose, Network } from "@dappnode/types"; +import { Compose, Network, getContainerName } from "@dappnode/types"; export async function executeTestCheckers({ dnpName, diff --git a/src/commands/init.ts b/src/commands/init.ts index 0d77762f..756119d5 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -18,12 +18,10 @@ import { defaultDir, defaultManifestFileName, defaultManifestFormat, - getImageTag, - releaseFiles, YargsError } from "../params.js"; import { CliGlobalOptions } from "../types.js"; -import { Manifest, Compose } from "@dappnode/types"; +import { Manifest, Compose, getImageTag, releaseFiles } from "@dappnode/types"; const stringsToRemoveFromName = [ "DAppNode-package-", diff --git a/src/files/compose/getComposePackageImages.ts b/src/files/compose/getComposePackageImages.ts index 2fc1b93a..4380f969 100644 --- a/src/files/compose/getComposePackageImages.ts +++ b/src/files/compose/getComposePackageImages.ts @@ -1,5 +1,4 @@ -import { Compose } from "@dappnode/types"; -import { getImageTag } from "../../params.js"; +import { Compose, getImageTag } from "@dappnode/types"; import { PackageImage } from "../../types.js"; /** diff --git a/src/files/compose/updateComposeImageTags.ts b/src/files/compose/updateComposeImageTags.ts index 23ccf875..334ab6dd 100644 --- a/src/files/compose/updateComposeImageTags.ts +++ b/src/files/compose/updateComposeImageTags.ts @@ -1,6 +1,6 @@ import { mapValues } from "lodash-es"; -import { getImageTag, upstreamImageLabel } from "../../params.js"; -import { Compose } from "@dappnode/types"; +import { upstreamImageLabel } from "../../params.js"; +import { Compose, getImageTag } from "@dappnode/types"; /** * Update service image tag to current version diff --git a/src/files/manifest/compactManifestIfCore.ts b/src/files/manifest/compactManifestIfCore.ts index cbed4a11..572527a6 100644 --- a/src/files/manifest/compactManifestIfCore.ts +++ b/src/files/manifest/compactManifestIfCore.ts @@ -1,8 +1,7 @@ import fs from "fs"; import path from "path"; import yaml from "js-yaml"; -import { releaseFiles } from "../../params.js"; -import { SetupWizard } from "@dappnode/types"; +import { SetupWizard, releaseFiles } from "@dappnode/types"; import { readManifest } from "./readManifest.js"; import { writeManifest } from "./writeManifest.js"; diff --git a/src/files/manifest/readManifest.ts b/src/files/manifest/readManifest.ts index 0869acf4..595717bc 100644 --- a/src/files/manifest/readManifest.ts +++ b/src/files/manifest/readManifest.ts @@ -2,8 +2,13 @@ import yaml from "js-yaml"; import fs from "fs"; import path from "path"; import { readFile } from "../../utils/file.js"; -import { defaultDir, releaseFiles } from "../../params.js"; -import { ManifestPaths, Manifest, ManifestFormat } from "@dappnode/types"; +import { defaultDir } from "../../params.js"; +import { + ManifestPaths, + Manifest, + ManifestFormat, + releaseFiles +} from "@dappnode/types"; /** * Reads a manifest. Without arguments defaults to read the manifest at './dappnode_package.json' diff --git a/src/files/setupWizard/readSetupWizardIfExists.ts b/src/files/setupWizard/readSetupWizardIfExists.ts index b38d2b1f..7d5eef4b 100644 --- a/src/files/setupWizard/readSetupWizardIfExists.ts +++ b/src/files/setupWizard/readSetupWizardIfExists.ts @@ -1,9 +1,9 @@ import fs from "fs"; import path from "path"; import yaml from "js-yaml"; -import { defaultDir, releaseFiles } from "../../params.js"; +import { defaultDir } from "../../params.js"; import { readFile } from "../../utils/file.js"; -import { SetupWizard } from "@dappnode/types"; +import { SetupWizard, releaseFiles } from "@dappnode/types"; export function readSetupWizardIfExists(dir?: string): SetupWizard | null { const dirPath = dir || defaultDir; diff --git a/src/params.ts b/src/params.ts index 76688b86..efc6eb18 100644 --- a/src/params.ts +++ b/src/params.ts @@ -1,4 +1,4 @@ -import { Architecture, FileFormat, ManifestFormat } from "@dappnode/types"; +import { ManifestFormat } from "@dappnode/types"; export * from "./files/compose/params.js"; @@ -21,174 +21,3 @@ export const upstreamImageLabel = "dappnode.dnp.upstreamImage"; export const PINATA_URL = "https://api.pinata.cloud"; // The build_sdk.env file is used by "slaves" DAppNode packages to define the UPSTREAM_PROJECT and UPSTREAM_VERSION used in the gha export const buildSdkEnvFileName = "build_sdk.env"; -const containerNamePrefix = "DAppNodePackage-"; -const containerCoreNamePrefix = "DAppNodeCore-"; - -/** - * Plain text file with should contain the IPFS hash of the release - * Necessary for the installer script to fetch the latest content hash - * of the eth clients. The resulting hashes are used by the DAPPMANAGER - * to install an eth client when the user does not want to use a remote node - * - * /ipfs/QmNqDvqAyy3pN3PvymB6chM7S1FgYyive8LosVKUuaDdfd - */ -export const contentHashFile = "content-hash"; - -export const releaseFiles = { - manifest: { - regex: /dappnode_package.*\.(json|yaml|yml)$/, - format: FileFormat.YAML, - maxSize: 100e3, // Limit size to ~100KB - required: true as const, - multiple: false as const - }, - compose: { - regex: /compose.*\.yml$/, - format: FileFormat.YAML, - maxSize: 10e3, // Limit size to ~10KB - required: true as const, - multiple: false as const - }, - signature: { - regex: /^signature\.json$/, - format: FileFormat.JSON, - maxSize: 10e3, // Limit size to ~10KB - required: false as const, - multiple: false as const - }, - avatar: { - regex: /avatar.*\.png$/, - format: null, - maxSize: 100e3, - required: true as const, - multiple: false as const - }, - setupWizard: { - regex: /setup-wizard\..*(json|yaml|yml)$/, - format: FileFormat.YAML, - maxSize: 100e3, - required: false as const, - multiple: false as const - }, - setupSchema: { - regex: /setup\..*\.json$/, - format: FileFormat.JSON, - maxSize: 10e3, - required: false as const, - multiple: false as const - }, - setupTarget: { - regex: /setup-target\..*json$/, - format: FileFormat.JSON, - maxSize: 10e3, - required: false as const, - multiple: false as const - }, - setupUiJson: { - regex: /setup-ui\..*json$/, - format: FileFormat.JSON, - maxSize: 10e3, - required: false as const, - multiple: false as const - }, - disclaimer: { - regex: /disclaimer\.md$/i, - format: FileFormat.TEXT, - maxSize: 100e3, - required: false as const, - multiple: false as const - }, - gettingStarted: { - regex: /getting.*started\.md$/i, - format: FileFormat.TEXT, - maxSize: 100e3, - required: false as const, - multiple: false as const - }, - prometheusTargets: { - regex: /.*prometheus-targets.(json|yaml|yml)$/, - format: FileFormat.YAML, - maxSize: 10e3, - required: false as const, - multiple: false as const - }, - grafanaDashboards: { - regex: /.*grafana-dashboard.json$/, - format: FileFormat.JSON, - maxSize: 10e6, // ~ 10MB - required: false as const, - multiple: true as const - } -}; - -export const releaseFilesDefaultNames: { - [P in keyof typeof releaseFiles]: string; -} = { - manifest: "dappnode_package.json", - compose: "docker-compose.yml", - avatar: "avatar.png", - signature: "signature.json", - setupWizard: "setup-wizard.json", - setupSchema: "setup.schema.json", - setupTarget: "setup-target.json", - setupUiJson: "setup-ui.json", - disclaimer: "disclaimer.md", - gettingStarted: "getting-started.md", - grafanaDashboards: "grafana-dashboard.json", - prometheusTargets: "prometheus-targets.json" -}; - -// Naming - -// Single arch images -export const getArchTag = (arch: Architecture): string => - arch.replace(/\//g, "-"); -export const getImagePath = ( - name: string, - version: string, - arch: Architecture -): string => `${name}_${version}_${getArchTag(arch)}.txz`; -export const getLegacyImagePath = (name: string, version: string): string => - `${name}_${version}.tar.xz`; - -/** - * Get a unique domain per container, considering multi-service packages - */ -export const getContainerDomain = ({ - dnpName, - serviceName -}: { - serviceName: string; - dnpName: string; -}): string => { - if (!serviceName || serviceName === dnpName) { - return dnpName; - } else { - return [serviceName, dnpName].join("."); - } -}; - -export const getImageTag = ({ - dnpName, - serviceName, - version -}: { - dnpName: string; - serviceName: string; - version: string; -}): string => [getContainerDomain({ dnpName, serviceName }), version].join(":"); - -export const getContainerName = ({ - dnpName, - serviceName, - isCore -}: { - dnpName: string; - serviceName: string; - isCore: boolean; -}): string => - // Note: _PREFIX variables already end with the character "-" - [ - isCore ? containerCoreNamePrefix : containerNamePrefix, - getContainerDomain({ dnpName, serviceName }) - ].join(""); diff --git a/src/tasks/buildAndUpload.ts b/src/tasks/buildAndUpload.ts index 54886ff1..edd0ba73 100644 --- a/src/tasks/buildAndUpload.ts +++ b/src/tasks/buildAndUpload.ts @@ -5,13 +5,7 @@ import rimraf from "rimraf"; import { verifyAvatar } from "../utils/verifyAvatar.js"; import { copyReleaseFile } from "../utils/copyReleaseFile.js"; import { addReleaseRecord } from "../utils/releaseRecord.js"; -import { - releaseFiles, - CliError, - getImagePath, - getLegacyImagePath, - releaseFilesDefaultNames -} from "../params.js"; +import { CliError } from "../params.js"; import { ListrContextBuildAndPublish } from "../types.js"; import { parseTimeout } from "../utils/timeout.js"; import { buildWithBuildx } from "./buildWithBuildx.js"; @@ -50,6 +44,12 @@ import { writeManifest, readSetupWizardIfExists } from "../files/index.js"; +import { + getImagePath, + getLegacyImagePath, + releaseFiles, + releaseFilesDefaultNames +} from "@dappnode/types"; // Pretty percent uploaded reporting const percentToMessage = (percent: number) => diff --git a/src/tasks/createGithubRelease.ts b/src/tasks/createGithubRelease.ts index 1194cb3e..b1b1e5a5 100644 --- a/src/tasks/createGithubRelease.ts +++ b/src/tasks/createGithubRelease.ts @@ -7,13 +7,14 @@ import { compactManifestIfCore, composeDeleteBuildProperties } from "../files/index.js"; -import { contentHashFile, defaultDir } from "../params.js"; +import { defaultDir } from "../params.js"; import { TxData, CliGlobalOptions, ListrContextBuildAndPublish } from "../types.js"; import { Github } from "../providers/github/Github.js"; +import { contentHashFile } from "@dappnode/types"; /** * Create (or edit) a Github release, then upload all assets diff --git a/src/utils/copyReleaseFile.ts b/src/utils/copyReleaseFile.ts index 9090bc4b..495acfbe 100644 --- a/src/utils/copyReleaseFile.ts +++ b/src/utils/copyReleaseFile.ts @@ -1,6 +1,6 @@ +import { releaseFilesDefaultNames } from "@dappnode/types"; import fs from "fs"; import path from "path"; -import { releaseFilesDefaultNames } from "../params.js"; interface FileConfig { regex: RegExp; diff --git a/test/params.test.ts b/test/params.test.ts index 811d050f..189474f0 100644 --- a/test/params.test.ts +++ b/test/params.test.ts @@ -1,6 +1,9 @@ import { expect } from "chai"; -import { getImagePath, getLegacyImagePath } from "../src/params.js"; -import { Architecture } from "@dappnode/types"; +import { + Architecture, + getImagePath, + getLegacyImagePath +} from "@dappnode/types"; describe("params", () => { const testCases: { diff --git a/test/testUtils.ts b/test/testUtils.ts index 8244088f..860933d0 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -1,7 +1,6 @@ import fs from "fs"; import rimraf from "rimraf"; -import { getImageTag } from "../src/params.js"; -import { Compose, Manifest } from "@dappnode/types"; +import { Compose, Manifest, getImageTag } from "@dappnode/types"; export const testDir = "test_files"; export function cleanTestDir(): void {