Skip to content

Commit

Permalink
[7.9] [dev/build/docker_generator] convert to typescript (#73339) (#7…
Browse files Browse the repository at this point in the history
…3363)

Co-authored-by: spalger <[email protected]>

Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger authored Jul 27, 2020
1 parent 4aa301d commit 7635b4f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
*/

import { resolve } from 'path';
import { compressTar, copyAll, mkdirp, write } from '../../../lib';

import { ToolingLog } from '@kbn/dev-utils';

import { compressTar, copyAll, mkdirp, write, Config } from '../../../lib';
import { dockerfileTemplate } from './templates';
import { TemplateContext } from './template_context';

export async function bundleDockerFiles(config, log, build, scope) {
export async function bundleDockerFiles(config: Config, log: ToolingLog, scope: TemplateContext) {
log.info(
`Generating kibana${scope.imageFlavor}${scope.ubiImageFlavor} docker build context bundle`
);
Expand Down Expand Up @@ -50,17 +54,15 @@ export async function bundleDockerFiles(config, log, build, scope) {
// Compress dockerfiles dir created inside
// docker build dir as output it as a target
// on targets folder
await compressTar(
{
archiverOptions: {
gzip: true,
gzipOptions: {
level: 9,
},
await compressTar({
source: dockerFilesBuildDir,
destination: dockerFilesOutputDir,
archiverOptions: {
gzip: true,
gzipOptions: {
level: 9,
},
createRootDirectory: false,
},
dockerFilesBuildDir,
dockerFilesOutputDir
);
createRootDirectory: false,
});
}
1 change: 0 additions & 1 deletion src/dev/build/tasks/os_packages/docker_generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

// @ts-expect-error not ts yet
export { runDockerGenerator, runDockerGeneratorForUBI } from './run';
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@
import { access, link, unlink, chmod } from 'fs';
import { resolve } from 'path';
import { promisify } from 'util';
import { write, copyAll, mkdirp, exec } from '../../../lib';

import { ToolingLog } from '@kbn/dev-utils';

import { write, copyAll, mkdirp, exec, Config, Build } from '../../../lib';
import * as dockerTemplates from './templates';
import { TemplateContext } from './template_context';
import { bundleDockerFiles } from './bundle_dockerfiles';

const accessAsync = promisify(access);
const linkAsync = promisify(link);
const unlinkAsync = promisify(unlink);
const chmodAsync = promisify(chmod);

export async function runDockerGenerator(config, log, build, ubi = false) {
export async function runDockerGenerator(
config: Config,
log: ToolingLog,
build: Build,
ubi: boolean = false
) {
// UBI var config
const baseOSImage = ubi ? 'registry.access.redhat.com/ubi7/ubi-minimal:7.7' : 'centos:7';
const ubiVersionTag = 'ubi7';
Expand All @@ -52,7 +61,7 @@ export async function runDockerGenerator(config, log, build, ubi = false) {
const dockerOutputDir = config.resolveFromTarget(
`kibana${imageFlavor}${ubiImageFlavor}-${versionTag}-docker.tar.gz`
);
const scope = {
const scope: TemplateContext = {
artifactTarball,
imageFlavor,
versionTag,
Expand Down Expand Up @@ -112,10 +121,10 @@ export async function runDockerGenerator(config, log, build, ubi = false) {
});

// Pack Dockerfiles and create a target for them
await bundleDockerFiles(config, log, build, scope);
await bundleDockerFiles(config, log, scope);
}

export async function runDockerGeneratorForUBI(config, log, build) {
export async function runDockerGeneratorForUBI(config: Config, log: ToolingLog, build: Build) {
// Only run ubi docker image build for default distribution
if (build.isOss()) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export interface TemplateContext {
artifactTarball: string;
imageFlavor: string;
versionTag: string;
license: string;
artifactsDir: string;
imageTag: string;
dockerBuildDir: string;
dockerOutputDir: string;
baseOSImage: string;
ubiImageFlavor: string;
dockerBuildDate: string;
usePublicArtifact?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

import dedent from 'dedent';

import { TemplateContext } from '../template_context';

function generator({
imageTag,
imageFlavor,
versionTag,
dockerOutputDir,
baseOSImage,
ubiImageFlavor,
}) {
}: TemplateContext) {
return dedent(`
#!/usr/bin/env bash
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import dedent from 'dedent';

import { TemplateContext } from '../template_context';

function generator({
artifactTarball,
versionTag,
Expand All @@ -27,7 +29,7 @@ function generator({
baseOSImage,
ubiImageFlavor,
dockerBuildDate,
}) {
}: TemplateContext) {
const copyArtifactTarballInsideDockerOptFolder = () => {
if (usePublicArtifact) {
return `RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/kibana/${artifactTarball} && cd -`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import dedent from 'dedent';

function generator({ imageFlavor }) {
import { TemplateContext } from '../template_context';

function generator({ imageFlavor }: TemplateContext) {
return dedent(`
#
# ** THIS IS AN AUTO-GENERATED FILE **
Expand Down

0 comments on commit 7635b4f

Please sign in to comment.