Remove directory from dockerfiles target (#37258)

* Remove directory from dockerfiles target

Produce a docker build context tarball without a top-level directory to
match the expected format for downstream automation.

This will produce:

```
$ tar -tzf target/kibana-8.0.0-docker-build-context.tar.gz
Dockerfile
bin/
config/
bin/kibana-docker
config/kibana.yml
```

Instead of:

```
$ tar -tzf target/kibana-8.0.0-docker-build-context.tar.gz
kibana-8.0.0-docker-build-context/Dockerfile
kibana-8.0.0-docker-build-context/bin/
kibana-8.0.0-docker-build-context/config/
kibana-8.0.0-docker-build-context/bin/kibana-docker
kibana-8.0.0-docker-build-context/config/kibana.yml
```

* Use options object for root directory config
This commit is contained in:
Chris Koehnke 2019-05-29 13:29:34 -04:00 committed by GitHub
parent 1ea4b5499e
commit 2f162d44ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 8 deletions

View file

@ -188,8 +188,8 @@ export async function untar(source, destination, extractOptions = {}) {
export async function compress(type, options = {}, source, destination) {
const output = fs.createWriteStream(destination);
const archive = archiver(type, options);
const name = source.split(sep).slice(-1)[0];
const archive = archiver(type, options.archiverOptions);
const name = (options.createRootDirectory ? source.split(sep).slice(-1)[0] : false);
archive.pipe(output);

View file

@ -34,11 +34,36 @@ export const CreateArchivesTask = {
switch (path.extname(destination)) {
case '.zip':
await compress('zip', { zlib: { level: 9 } }, source, destination);
await compress(
'zip',
{
archiverOptions: {
zlib: {
level: 9
}
},
createRootDirectory: true
},
source,
destination
);
break;
case '.gz':
await compress('tar', { gzip: true, gzipOptions: { level: 9 } }, source, destination);
await compress(
'tar',
{
archiverOptions: {
gzip: true,
gzipOptions: {
level: 9
}
},
createRootDirectory: true
},
source,
destination
);
break;
default:

View file

@ -59,10 +59,13 @@ export async function bundleDockerFiles(config, log, build, scope) {
await compress(
'tar',
{
gzip: true,
gzipOptions: {
level: 9
}
archiverOptions: {
gzip: true,
gzipOptions: {
level: 9
}
},
createRootDirectory: false
},
dockerFilesBuildDir,
dockerFilesOutputDir