Skip to content

Commit

Permalink
Entrypoint, workdir and user layers when using customContent (#27)
Browse files Browse the repository at this point in the history
* chore(test): Writing integration test for correctly set entrypoint

* fix(customContent): Some layers not being set when using customContent

Layers for WORKDIR, ENTRYPOINT and user information were not being added
when using customContent
  • Loading branch information
vehagn authored Oct 11, 2023
1 parent 24fe80d commit 4bc049a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [2.5.1] - TBD

### Fixed

- Layers for `ENTRYPOINT`, `WORKDIR` and user information are now being added when using `customContent`

## [2.5.0] - TBD

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "containerify",
"version": "2.5.0",
"version": "2.5.1",
"description": "Build node.js docker images without docker",
"main": "./lib/cli.js",
"scripts": {
Expand Down
40 changes: 19 additions & 21 deletions src/appLayerCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,28 @@ function parseCommandLineToParts(entrypoint: string) {
}

async function addAppLayers(options: Options, config: Config, todir: string, manifest: Manifest, tmpdir: string) {
addEmptyLayer(
config,
options,
`WORKDIR ${options.workdir}`,
(config) => (config.config.WorkingDir = options.workdir),
);
const entrypoint = parseCommandLineToParts(options.entrypoint);
addEmptyLayer(
config,
options,
`ENTRYPOINT ${JSON.stringify(entrypoint)}`,
(config) => (config.config.Entrypoint = entrypoint),
);
addEmptyLayer(config, options, `USER ${options.user}`, (config) => {
config.config.User = options.user;
config.container_config.User = options.user;
});
await addEnvsLayer(options, config);
await addLabelsLayer(options, config);
if (options.customContent.length > 0) {
await addEnvsLayer(options, config);
await addLabelsLayer(options, config);
await addDataLayer(tmpdir, todir, options, config, manifest, options.customContent, "custom");
} else {
addEmptyLayer(
config,
options,
`WORKDIR ${options.workdir}`,
(config) => (config.config.WorkingDir = options.workdir),
);
const entrypoint = parseCommandLineToParts(options.entrypoint);
addEmptyLayer(
config,
options,
`ENTRYPOINT ${JSON.stringify(entrypoint)}`,
(config) => (config.config.Entrypoint = entrypoint),
);
addEmptyLayer(config, options, `USER ${options.user}`, (config) => {
config.config.User = options.user;
config.container_config.User = options.user;
});
await addEnvsLayer(options, config);
await addLabelsLayer(options, config);
const appFiles = (await fs.readdir(options.folder)).filter((l) => !ignore.includes(l));
const depLayerContent = appFiles.filter((l) => depLayerPossibles.includes(l));
const appLayerContent = appFiles.filter((l) => !depLayerPossibles.includes(l));
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "2.5.0";
export const VERSION = "2.5.1";
8 changes: 8 additions & 0 deletions tests/integration/file/containerify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"fromImage": "node:alpine",
"toImage": "containerify:demo-app",
"folder": ".",
"customContent": [
"customContent"
]
}
35 changes: 33 additions & 2 deletions tests/integration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rm -rf tmp
mkdir -p tmp/v1/content/
mkdir -p tmp/v2/content/
mkdir -p tmp/v3/content/
mkdir -p tmp/v4/content/
mkdir -p tmp/layercache

echo "Building image 1..."
Expand All @@ -23,11 +24,29 @@ echo "Building image 3..."

../../lib/cli.js --fromImage node:alpine --toImage containerify:demo-app --folder . --toTar tmp/v3.tar --customContent customContent --setTimeStamp "2023-03-07T12:53:10.471Z" --layerCacheFolder tmp/layercache > /dev/null

echo "Building image 4..."

../../lib/cli.js --file ./file/containerify.json --toTar tmp/v4.tar --setTimeStamp "2023-03-07T12:53:10.471Z" --layerCacheFolder tmp/layercache > /dev/null

echo "Untaring content ..."
tar -xf tmp/v1.tar -C tmp/v1/content/
tar -xf tmp/v2.tar -C tmp/v2/content/
tar -xf tmp/v3.tar -C tmp/v3/content/
tar -xf tmp/v4.tar -C tmp/v4/content/

jqscript='if (.config.Entrypoint == ["npm", "start"]) then true else false end'

echo "Checking that entrypoint is correctly set for 1 ..."
if [[ $(cat tmp/v1/content/config.json | jq "$jqscript") != "true" ]]; then
echo "ERROR: wrong entrypoint set";
exit 1;
fi

echo "Checking that entrypoint is correctly set for 3 ..."
if [[ $(cat tmp/v3/content/config.json | jq "$jqscript") != "true" ]]; then
echo "ERROR: wrong entrypoint set";
exit 1;
fi

echo "Checking that config files for 1 and 2 are equal ..."
if ! cmp -s tmp/v1/content/config.json tmp/v2/content/config.json; then
Expand All @@ -42,7 +61,7 @@ if ! cmp -s tmp/v1/content/manifest.json tmp/v2/content/manifest.json; then
fi

echo "Checking that config files for 1 and 3 are not equal ..."
if cmp -s tmp/v1/content/config.json tmp/v3/content/maniconfigfest.json; then
if cmp -s tmp/v1/content/config.json tmp/v3/content/config.json; then
echo "ERROR: config.jsons are the same";
exit 1;
fi
Expand All @@ -53,5 +72,17 @@ if cmp -s tmp/v1/content/manifest.json tmp/v3/content/manifest.json; then
exit 1;
fi

echo "Checking that config files for 3 and 4 are equal ..."
if ! cmp -s tmp/v3/content/config.json tmp/v4/content/config.json; then
echo "ERROR: config.jsons are not the same";
exit 1;
fi

echo "Checking that manifest files for 3 and 4 are equal ..."
if ! cmp -s tmp/v3/content/manifest.json tmp/v4/content/manifest.json; then
echo "ERROR: manifest.jsons are not the same";
exit 1;
fi

rm -rf tmp
echo "Success!"
echo "Success!"

0 comments on commit 4bc049a

Please sign in to comment.