@tahminator/pipeline 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docker/index.d.ts +28 -1
- package/dist/docker/index.js +55 -4
- package/dist/gh/tag/index.d.ts +2 -1
- package/dist/gh/tag/index.js +4 -1
- package/dist/utils/colors.d.ts +22 -0
- package/dist/utils/colors.js +89 -0
- package/package.json +1 -1
package/dist/docker/index.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
export declare class DockerClient {
|
|
2
2
|
private readonly username;
|
|
3
|
-
private readonly pat;
|
|
4
3
|
private constructor();
|
|
4
|
+
/**
|
|
5
|
+
* @note This class must be cleaned up manually by calling `cleanup()`.
|
|
6
|
+
* You can also do this manually by utilizing the [`usage`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management) keyword.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* export async function main() {
|
|
11
|
+
* await using client = await DockerClient.create(username, pat);
|
|
12
|
+
*
|
|
13
|
+
* client.promoteDockerImage({});
|
|
14
|
+
*
|
|
15
|
+
* // client will automatically be cleaned up at the end of the scope.
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
5
19
|
static create(username: string, pat: string): Promise<DockerClient>;
|
|
6
20
|
/**
|
|
7
21
|
* Will lookup the Docker Hub image of `originalTag` & add `newGithubTags` to it.
|
|
@@ -11,5 +25,18 @@ export declare class DockerClient {
|
|
|
11
25
|
newGithubTags: string[];
|
|
12
26
|
repository: string;
|
|
13
27
|
}): Promise<void>;
|
|
28
|
+
buildImage(args: {
|
|
29
|
+
dockerFileLocation: string;
|
|
30
|
+
/**
|
|
31
|
+
* @example ["staging-latest", `staging-${sha}`, `staging-%{timestamp.toString()}`]
|
|
32
|
+
*/
|
|
33
|
+
tags: string[];
|
|
34
|
+
dockerUsername: string;
|
|
35
|
+
dockerRepository: string;
|
|
36
|
+
shouldUpload?: boolean;
|
|
37
|
+
platforms?: string[];
|
|
38
|
+
buildArgs?: Record<string, string | number | boolean>;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
14
41
|
cleanup(): Promise<void>;
|
|
15
42
|
}
|
package/dist/docker/index.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { $ } from "bun";
|
|
2
|
+
import { cyan } from "../utils/colors";
|
|
2
3
|
export class DockerClient {
|
|
3
4
|
username;
|
|
4
|
-
|
|
5
|
-
constructor(username, pat) {
|
|
5
|
+
constructor(username) {
|
|
6
6
|
this.username = username;
|
|
7
|
-
this.pat = pat;
|
|
8
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @note This class must be cleaned up manually by calling `cleanup()`.
|
|
10
|
+
* You can also do this manually by utilizing the [`usage`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management) keyword.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* export async function main() {
|
|
15
|
+
* await using client = await DockerClient.create(username, pat);
|
|
16
|
+
*
|
|
17
|
+
* client.promoteDockerImage({});
|
|
18
|
+
*
|
|
19
|
+
* // client will automatically be cleaned up at the end of the scope.
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
9
23
|
static async create(username, pat) {
|
|
10
|
-
const client = new DockerClient(username
|
|
24
|
+
const client = new DockerClient(username);
|
|
11
25
|
await $ `echo ${pat} | docker login -u ${username} --password-stdin`;
|
|
12
26
|
return client;
|
|
13
27
|
}
|
|
@@ -26,6 +40,43 @@ export class DockerClient {
|
|
|
26
40
|
}
|
|
27
41
|
console.log(`Promoted ${originalTag} to: ${newGithubTags.join(", ")}`);
|
|
28
42
|
}
|
|
43
|
+
async buildImage(args) {
|
|
44
|
+
const { dockerFileLocation, tags, dockerUsername, dockerRepository, shouldUpload = true, platforms = ["linux/amd64"], buildArgs = {}, } = args;
|
|
45
|
+
if (!tags.length) {
|
|
46
|
+
throw new Error("You must provide atleast one tag.");
|
|
47
|
+
}
|
|
48
|
+
console.log("Building image with following tags:");
|
|
49
|
+
tags.forEach((tag) => console.log(cyan(tag)));
|
|
50
|
+
try {
|
|
51
|
+
await $ `docker buildx create --use --name ${dockerRepository}-builder`;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
await $ `docker buildx use ${dockerRepository}-builder`;
|
|
55
|
+
}
|
|
56
|
+
const buildModeFlag = shouldUpload ? "--push" : "--load";
|
|
57
|
+
const tagFlags = tags.flatMap((tag) => [
|
|
58
|
+
"--tag",
|
|
59
|
+
`${dockerUsername}/${dockerRepository}:${tag}`,
|
|
60
|
+
]);
|
|
61
|
+
const buildArgFlags = Object.entries(buildArgs).flatMap(([k, v]) => [
|
|
62
|
+
"--build-arg",
|
|
63
|
+
`${k}=${v.toString()}`,
|
|
64
|
+
]);
|
|
65
|
+
await $ `docker buildx build ${buildModeFlag} \
|
|
66
|
+
--platform ${platforms.join(",")} \
|
|
67
|
+
--file ${dockerFileLocation} \
|
|
68
|
+
--cache-from=type=gha \
|
|
69
|
+
--cache-to=type=gha,mode=max \
|
|
70
|
+
${buildArgFlags} \
|
|
71
|
+
${tagFlags} \
|
|
72
|
+
.`;
|
|
73
|
+
console.log(shouldUpload ?
|
|
74
|
+
`Image build & successfully uploaded to ${dockerUsername}/${dockerRepository}`
|
|
75
|
+
: "Image has been built (upload skipped.)");
|
|
76
|
+
}
|
|
77
|
+
async [Symbol.asyncDispose]() {
|
|
78
|
+
await this.cleanup();
|
|
79
|
+
}
|
|
29
80
|
async cleanup() {
|
|
30
81
|
await $ `docker logout`;
|
|
31
82
|
}
|
package/dist/gh/tag/index.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import semver from "semver";
|
|
|
3
3
|
import type { OwnerString, RepoString } from "../../types";
|
|
4
4
|
export declare class GitHubTagManager {
|
|
5
5
|
private readonly client;
|
|
6
|
-
readonly isExplicitToken
|
|
6
|
+
private readonly isExplicitToken;
|
|
7
7
|
private static readonly BASE_VERSION;
|
|
8
8
|
constructor(client: Octokit, isExplicitToken: boolean);
|
|
9
|
+
private checkToken;
|
|
9
10
|
/**
|
|
10
11
|
* Utilizes the GitHub API to create a new tag version in the given repository.
|
|
11
12
|
*
|
package/dist/gh/tag/index.js
CHANGED
|
@@ -8,7 +8,9 @@ export class GitHubTagManager {
|
|
|
8
8
|
constructor(client, isExplicitToken) {
|
|
9
9
|
this.client = client;
|
|
10
10
|
this.isExplicitToken = isExplicitToken;
|
|
11
|
-
|
|
11
|
+
}
|
|
12
|
+
checkToken() {
|
|
13
|
+
if (!this.isExplicitToken) {
|
|
12
14
|
throw new Error("You must pass in an explicit GitHub token for this operation. You may either use a PAT or a GitHub App Token");
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -20,6 +22,7 @@ export class GitHubTagManager {
|
|
|
20
22
|
* a GitHub PAT.
|
|
21
23
|
*/
|
|
22
24
|
async createTag({ repositoryOverride, releaseType, onPreTagCreate, }) {
|
|
25
|
+
this.checkToken();
|
|
23
26
|
const repositoryEnv = (() => {
|
|
24
27
|
const v = process.env.GITHUB_REPOSITORY;
|
|
25
28
|
return v;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function black(s: string): string;
|
|
2
|
+
export declare function red(s: string): string;
|
|
3
|
+
export declare function green(s: string): string;
|
|
4
|
+
export declare function yellow(s: string): string;
|
|
5
|
+
export declare function blue(s: string): string;
|
|
6
|
+
export declare function magenta(s: string): string;
|
|
7
|
+
export declare function cyan(s: string): string;
|
|
8
|
+
export declare function white(s: string): string;
|
|
9
|
+
export declare function gray(s: string): string;
|
|
10
|
+
export declare function brightRed(s: string): string;
|
|
11
|
+
export declare function brightGreen(s: string): string;
|
|
12
|
+
export declare function brightYellow(s: string): string;
|
|
13
|
+
export declare function brightBlue(s: string): string;
|
|
14
|
+
export declare function brightMagenta(s: string): string;
|
|
15
|
+
export declare function brightCyan(s: string): string;
|
|
16
|
+
export declare function brightWhite(s: string): string;
|
|
17
|
+
export declare function pink(s: string): string;
|
|
18
|
+
export declare function orange(s: string): string;
|
|
19
|
+
export declare function bold(s: string): string;
|
|
20
|
+
export declare function dim(s: string): string;
|
|
21
|
+
export declare function italic(s: string): string;
|
|
22
|
+
export declare function underline(s: string): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export function black(s) {
|
|
2
|
+
return `${BLACK}${s}${RESET}`;
|
|
3
|
+
}
|
|
4
|
+
export function red(s) {
|
|
5
|
+
return `${RED}${s}${RESET}`;
|
|
6
|
+
}
|
|
7
|
+
export function green(s) {
|
|
8
|
+
return `${GREEN}${s}${RESET}`;
|
|
9
|
+
}
|
|
10
|
+
export function yellow(s) {
|
|
11
|
+
return `${YELLOW}${s}${RESET}`;
|
|
12
|
+
}
|
|
13
|
+
export function blue(s) {
|
|
14
|
+
return `${BLUE}${s}${RESET}`;
|
|
15
|
+
}
|
|
16
|
+
export function magenta(s) {
|
|
17
|
+
return `${MAGENTA}${s}${RESET}`;
|
|
18
|
+
}
|
|
19
|
+
export function cyan(s) {
|
|
20
|
+
return `${CYAN}${s}${RESET}`;
|
|
21
|
+
}
|
|
22
|
+
export function white(s) {
|
|
23
|
+
return `${WHITE}${s}${RESET}`;
|
|
24
|
+
}
|
|
25
|
+
export function gray(s) {
|
|
26
|
+
return `${GRAY}${s}${RESET}`;
|
|
27
|
+
}
|
|
28
|
+
export function brightRed(s) {
|
|
29
|
+
return `${BRIGHT_RED}${s}${RESET}`;
|
|
30
|
+
}
|
|
31
|
+
export function brightGreen(s) {
|
|
32
|
+
return `${BRIGHT_GREEN}${s}${RESET}`;
|
|
33
|
+
}
|
|
34
|
+
export function brightYellow(s) {
|
|
35
|
+
return `${BRIGHT_YELLOW}${s}${RESET}`;
|
|
36
|
+
}
|
|
37
|
+
export function brightBlue(s) {
|
|
38
|
+
return `${BRIGHT_BLUE}${s}${RESET}`;
|
|
39
|
+
}
|
|
40
|
+
export function brightMagenta(s) {
|
|
41
|
+
return `${BRIGHT_MAGENTA}${s}${RESET}`;
|
|
42
|
+
}
|
|
43
|
+
export function brightCyan(s) {
|
|
44
|
+
return `${BRIGHT_CYAN}${s}${RESET}`;
|
|
45
|
+
}
|
|
46
|
+
export function brightWhite(s) {
|
|
47
|
+
return `${BRIGHT_WHITE}${s}${RESET}`;
|
|
48
|
+
}
|
|
49
|
+
export function pink(s) {
|
|
50
|
+
return `${PINK}${s}${RESET}`;
|
|
51
|
+
}
|
|
52
|
+
export function orange(s) {
|
|
53
|
+
return `${ORANGE}${s}${RESET}`;
|
|
54
|
+
}
|
|
55
|
+
export function bold(s) {
|
|
56
|
+
return `${BOLD}${s}${RESET}`;
|
|
57
|
+
}
|
|
58
|
+
export function dim(s) {
|
|
59
|
+
return `${DIM}${s}${RESET}`;
|
|
60
|
+
}
|
|
61
|
+
export function italic(s) {
|
|
62
|
+
return `${ITALIC}${s}${RESET}`;
|
|
63
|
+
}
|
|
64
|
+
export function underline(s) {
|
|
65
|
+
return `${UNDERLINE}${s}${RESET}`;
|
|
66
|
+
}
|
|
67
|
+
const BLACK = "\x1b[30m";
|
|
68
|
+
const RED = "\x1b[31m";
|
|
69
|
+
const GREEN = "\x1b[32m";
|
|
70
|
+
const YELLOW = "\x1b[33m";
|
|
71
|
+
const BLUE = "\x1b[34m";
|
|
72
|
+
const MAGENTA = "\x1b[35m";
|
|
73
|
+
const CYAN = "\x1b[36m";
|
|
74
|
+
const WHITE = "\x1b[37m";
|
|
75
|
+
const GRAY = "\x1b[90m";
|
|
76
|
+
const BRIGHT_RED = "\x1b[91m";
|
|
77
|
+
const BRIGHT_GREEN = "\x1b[92m";
|
|
78
|
+
const BRIGHT_YELLOW = "\x1b[93m";
|
|
79
|
+
const BRIGHT_BLUE = "\x1b[94m";
|
|
80
|
+
const BRIGHT_MAGENTA = "\x1b[95m";
|
|
81
|
+
const BRIGHT_CYAN = "\x1b[96m";
|
|
82
|
+
const BRIGHT_WHITE = "\x1b[97m";
|
|
83
|
+
const PINK = "\x1b[38;5;213m";
|
|
84
|
+
const ORANGE = "\x1b[38;5;214m";
|
|
85
|
+
const RESET = "\x1b[0m";
|
|
86
|
+
const BOLD = "\x1b[1m";
|
|
87
|
+
const DIM = "\x1b[2m";
|
|
88
|
+
const ITALIC = "\x1b[3m";
|
|
89
|
+
const UNDERLINE = "\x1b[4m";
|