Skip to content

Commit c4a7853

Browse files
authored
Fix createService not passing registry auth (#116)
1 parent ff474b7 commit c4a7853

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/docker-api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import Dockerode, {ConfigInfo, NetworkInspectInfo, Service} from "dockerode";
1+
import Dockerode, {AuthConfigObject, ConfigInfo, NetworkInspectInfo, Service} from "dockerode";
22
import {initServiceSpec, sortServiceSpec} from "./service-spec.js";
33
import {HashedConfigs} from "./hashed-config.js";
44
import {assertString} from "./asserts.js";
55
import {SwarmAppConfig} from "./swarm-app-config.js";
66
import {resolveAuthConfig} from "./docker-config.js";
7-
import {AuthConfigObject} from "dockerode";
87
import timers from "timers/promises";
98
import assert from "assert";
109

@@ -128,7 +127,11 @@ export async function upsertServices ({dockerode, config, current, appName, hash
128127
const foundService = current.services.find((s) => s.Spec?.Name === `${appName}_${serviceName}`);
129128
if (!foundService) {
130129
console.log(`Creating service ${appName}_${serviceName}`);
131-
await dockerode.createService({...serviceSpec, authconfig});
130+
if (authconfig) {
131+
await dockerode.createService(authconfig, serviceSpec);
132+
} else {
133+
await dockerode.createService(serviceSpec);
134+
}
132135
} else {
133136
serviceSpec.version = foundService.Version?.Index ?? 0;
134137
console.log(`Updating service ${appName}_${serviceName}`);

src/docker-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ export function resolveAuthConfig (image: string, auths: Record<string, AuthConf
2323
const entry = auths[registry];
2424
if (!entry?.auth) return undefined;
2525

26-
return {auth: entry.auth, serveraddress: registry};
26+
const decoded = Buffer.from(entry.auth, "base64").toString();
27+
const separatorIndex = decoded.indexOf(":");
28+
if (separatorIndex === -1) return undefined;
29+
const username = decoded.substring(0, separatorIndex);
30+
const password = decoded.substring(separatorIndex + 1);
31+
32+
return {username, password, serveraddress: registry};
2733
}

0 commit comments

Comments
 (0)