cli: added backend:build-image command
Co-authored-by: Ivan Shmidt <bahoc47@gmail.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { createDistWorkspace } from '../../lib/packager';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { run } from '../../lib/run';
|
||||
|
||||
export default async (imageTag: string) => {
|
||||
const tempDistWorkspace = await createDistWorkspace(['example-backend'], {
|
||||
files: [
|
||||
'package.json',
|
||||
'yarn.lock',
|
||||
'app-config.yaml',
|
||||
{ src: paths.resolveTarget('Dockerfile'), dest: 'Dockerfile' },
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Dist workspace ready at ${tempDistWorkspace}`);
|
||||
|
||||
await run('docker', ['build', '.', '-t', imageTag], {
|
||||
cwd: tempDistWorkspace,
|
||||
});
|
||||
|
||||
await fs.remove(tempDistWorkspace);
|
||||
};
|
||||
@@ -46,6 +46,15 @@ const main = (argv: string[]) => {
|
||||
.description('Build a backend plugin')
|
||||
.action(lazyAction(() => import('./commands/backend/build'), 'default'));
|
||||
|
||||
program
|
||||
.command('backend:build-image <image-tag>')
|
||||
.description(
|
||||
'Builds a docker image from the package, with all local deps included',
|
||||
)
|
||||
.action(
|
||||
lazyAction(() => import('./commands/backend/buildImage'), 'default'),
|
||||
);
|
||||
|
||||
program
|
||||
.command('backend:dev')
|
||||
.description('Start local development server with HMR for the backend')
|
||||
|
||||
@@ -75,6 +75,7 @@ export async function createDistWorkspace(
|
||||
const dest = typeof file === 'string' ? file : file.dest;
|
||||
await fs.copy(paths.resolveTargetRoot(src), resolvePath(targetDir, dest));
|
||||
}
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
async function moveToDistWorkspace(
|
||||
|
||||
Reference in New Issue
Block a user