Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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