[dev/build/docker_generator] convert to typescript (#73339)

Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Spencer 2020-07-27 14:31:02 -07:00 committed by GitHub
parent 5a47218971
commit 157fb097a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 23 deletions

View file

@ -18,10 +18,14 @@
*/
import { resolve } from 'path';
import { compressTar, copyAll, mkdirp, write } from '../../../lib';
import { dockerfileTemplate } from './templates';
export async function bundleDockerFiles(config, log, build, scope) {
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: Config, log: ToolingLog, scope: TemplateContext) {
log.info(
`Generating kibana${scope.imageFlavor}${scope.ubiImageFlavor} docker build context bundle`
);
@ -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,
});
}

View file

@ -17,5 +17,4 @@
* under the License.
*/
// @ts-expect-error not ts yet
export { runDockerGenerator, runDockerGeneratorForUBI } from './run';

View file

@ -20,8 +20,12 @@
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);
@ -29,7 +33,12 @@ 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';
@ -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,
@ -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;

View file

@ -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;
}

View file

@ -19,6 +19,8 @@
import dedent from 'dedent';
import { TemplateContext } from '../template_context';
function generator({
imageTag,
imageFlavor,
@ -26,7 +28,7 @@ function generator({
dockerOutputDir,
baseOSImage,
ubiImageFlavor,
}) {
}: TemplateContext) {
return dedent(`
#!/usr/bin/env bash
#

View file

@ -19,6 +19,8 @@
import dedent from 'dedent';
import { TemplateContext } from '../template_context';
function generator({
artifactTarball,
versionTag,
@ -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 -`;

View file

@ -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 **