Skip to content
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
1 change: 1 addition & 0 deletions common/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare global {

interface IGlobalInstanceDockerConfig {
containerName?: string;
pullPolicy?: boolean;
image?: string;
memory?: number;
ports?: string[];
Expand Down
34 changes: 19 additions & 15 deletions daemon/src/entity/commands/docker/docker_pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,32 @@ export default class DockerPullCommand extends InstanceCommand {

async exec(instance: Instance) {
const imageName = instance.config.docker.image;
const pullPolicy = instance.config.docker.pullPolicy;
if (!imageName) throw new Error(t("TXT_CODE_17be5f70"));
const cachedStartCount = instance.startCount;
// If the image exists, there is no need to pull again.
if (await checkImage(imageName)) return;
if(pullPolicy === false ) {
if (await checkImage(imageName)) return;
} else {

try {
const docker = new DefaultDocker();
instance.println("CONTAINER", t("TXT_CODE_2fa46b8c") + imageName);
instance.asynchronousTask = this;
try {
const docker = new DefaultDocker();
instance.println("CONTAINER", t("TXT_CODE_2fa46b8c") + imageName);
instance.asynchronousTask = this;

await docker.pull(imageName, {});
await docker.pull(imageName, {});

await this.awaitImageDone(instance, imageName);
if (cachedStartCount !== instance.startCount) return;
instance.println("CONTAINER", t("TXT_CODE_c68b0bef"));
} catch (err: any) {
if (cachedStartCount !== instance.startCount) return;
throw new Error([t("TXT_CODE_db37b7f9"), err?.message].join("\n"));
} finally {
this.stopped(instance);
}
await this.awaitImageDone(instance, imageName);
if (cachedStartCount !== instance.startCount) return;
instance.println("CONTAINER", t("TXT_CODE_c68b0bef"));
} catch (err: any) {
if (cachedStartCount !== instance.startCount) return;
throw new Error([t("TXT_CODE_db37b7f9"), err?.message].join("\n"));
} finally {
this.stopped(instance);
}
}
}

async stop(instance: Instance): Promise<void> {
this.stopped(instance);
Expand Down
1 change: 1 addition & 0 deletions daemon/src/entity/instance/Instance_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class InstanceConfig implements IGlobalInstanceConfig {
public docker: IGlobalInstanceDockerConfig = {
containerName: "",
image: "",
pullPolicy: false,
ports: [],
extraVolumes: [],
memory: 0,
Expand Down
1 change: 1 addition & 0 deletions daemon/src/entity/instance/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export default class Instance extends EventEmitter {

if (cfg.docker) {
configureEntityParams(this.config.docker, cfg.docker, "containerName", String);
configureEntityParams(this.config.docker, cfg.docker, "pullPolicy", Boolean);
configureEntityParams(this.config.docker, cfg.docker, "image", String);
configureEntityParams(this.config.docker, cfg.docker, "memory", Number);
configureEntityParams(this.config.docker, cfg.docker, "ports");
Expand Down
Loading