Skip to content

Commit 26c3f4d

Browse files
committed
Fix createService not passing registry auth correctly
Dockerode's createService single-arg codepath does NOT extract authconfig from the options object (unlike createImage and service.update which do). Passing {…serviceSpec, authconfig} resulted in the entire service spec being serialized as the X-Registry-Auth header, which the registry cannot parse. Use the two-argument form createService(auth, opts) so the auth config is correctly sent as the X-Registry-Auth header.
1 parent ff474b7 commit 26c3f4d

1 file changed

Lines changed: 6 additions & 3 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}`);

0 commit comments

Comments
 (0)