Issue
It seems that there is an encoding issue when calling importImage with the changes parameter.
When passing changes as a string array to the function, I get the following error :
(HTTP code 400) unexpected - ["EXPOSE is not a valid change command
If I call encodingURIComponent on all the elements of the changes array, I get the following error :
(HTTP code 400) unexpected - ["EXPOSE%2022%2Ftcp","EXPOSE%2080%2Ftcp", ....... entrypoint%22%5D"] is not a valid change command
It is interesting to see that the docs specify that elements of the changes array should be URI encoded : https://docs.docker.com/reference/api/engine/version/v1.43/#tag/Image/operation/ImageCommit
I use to have a working "import" function before using this one, but it would missinterpret the brackets of ENTRYPOINT & CMD changes. Here is it's implementation :
export type ImportDockerImageOptions = {
repo: string;
tag: string;
platform?: string;
} & {
changes?: string[];
} &
(
{
fromSrc: string;
message?: string;
} |
{
fromImage: string;
}
);
export const importDockerImage = (
docker: Dockerode,
file: string | NodeJS.ReadableStream,
options: ImportDockerImageOptions,
): Promise<NodeJS.ReadableStream> => {
const queryString = qs
.encode(options)
.replace(/%5B/g, '[')
.replace(/%5D/g, ']');
// console.log(`[DEBUG] importDockerImage query string : ${queryString}`);
const optsf: DockerModem.DialOptions = {
path: `/images/create?${queryString}`,
method: 'POST',
options: {},
file: file,
abortSignal: undefined,
isStream: true,
statusCodes: {
200: true,
404: `repository ${options.repo} does not exist or no read access`,
500: 'server error',
},
};
return new Promise((resolve, reject) => {
docker.modem.dial(
optsf,
(err, data) => {
if(err) {
return reject(err);
}
resolve(data as NodeJS.ReadableStream);
});
});
};
In the beginning of the function you can see that I process brackets in a special way to make it work. Otherwise I get errors from the Docker API. My ENTRYPOINT bug lied there.
I was hoping that using the "official" importImage function would fix my issue AND make my code more standard.
TODO
Issue
It seems that there is an encoding issue when calling
importImagewith thechangesparameter.When passing
changesas a string array to the function, I get the following error :If I call
encodingURIComponenton all the elements of thechangesarray, I get the following error :It is interesting to see that the docs specify that elements of the
changesarray should be URI encoded : https://docs.docker.com/reference/api/engine/version/v1.43/#tag/Image/operation/ImageCommitI use to have a working "import" function before using this one, but it would missinterpret the brackets of
ENTRYPOINT&CMDchanges. Here is it's implementation :In the beginning of the function you can see that I process brackets in a special way to make it work. Otherwise I get errors from the Docker API. My
ENTRYPOINTbug lied there.I was hoping that using the "official"
importImagefunction would fix my issue AND make my code more standard.TODO
changesoptionsoptionsparameter of the function