-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement master-images component handlers + event/command writer
- Loading branch information
Showing
32 changed files
with
798 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/server-analysis-manager/src/components/master-images/commands/build/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './module'; |
64 changes: 64 additions & 0 deletions
64
packages/server-analysis-manager/src/components/master-images/commands/build/module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { REGISTRY_MASTER_IMAGE_PROJECT_NAME } from '@privateaim/core-kit'; | ||
import path from 'node:path'; | ||
import tar from 'tar-fs'; | ||
import type { | ||
MasterImagesBuildCommandPayload, MasterImagesPushCommandPayloadTag, | ||
} from '@privateaim/server-analysis-manager-kit'; | ||
import { | ||
buildRemoteDockerImageURL, useCoreClient, useDocker, waitForDockerActionStream, | ||
} from '../../../../core'; | ||
import { writePushCommand } from '../../queue'; | ||
|
||
export async function executeMasterImagesBuildCommand( | ||
payload: MasterImagesBuildCommandPayload, | ||
) { | ||
const coreClient = useCoreClient(); | ||
const docker = useDocker(); | ||
const promises : Promise<unknown>[] = []; | ||
|
||
const { data: registries } = await coreClient.registry.getMany(); | ||
|
||
const tags : MasterImagesPushCommandPayloadTag[] = []; | ||
|
||
for (let i = 0; i < payload.images.length; i++) { | ||
const imagePath = path.join(payload.directory, payload.images[i].path); | ||
|
||
for (let j = 0; j < registries.length; j++) { | ||
const imageTag = buildRemoteDockerImageURL({ | ||
hostname: registries[j].host, | ||
projectName: REGISTRY_MASTER_IMAGE_PROJECT_NAME, | ||
repositoryName: payload.images[i].virtualPath, | ||
tagOrDigest: 'latest', | ||
}); | ||
|
||
tags.push({ | ||
name: imageTag, | ||
registryId: registries[j].id, | ||
}); | ||
|
||
const pack = tar.pack(imagePath); | ||
const promise = docker | ||
.buildImage(pack, { | ||
t: imageTag, | ||
}) | ||
.then((stream) => waitForDockerActionStream(stream)); | ||
|
||
promises.push(promise); | ||
} | ||
} | ||
|
||
await Promise.all(promises); | ||
|
||
await writePushCommand({ | ||
tags, | ||
}); | ||
|
||
return payload; | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/server-analysis-manager/src/components/master-images/commands/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './build'; | ||
export * from './push'; | ||
export * from './synchronize'; |
8 changes: 8 additions & 0 deletions
8
packages/server-analysis-manager/src/components/master-images/commands/push/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './module'; |
Oops, something went wrong.