Skip to content

Commit

Permalink
add build docker container script
Browse files Browse the repository at this point in the history
Former-commit-id: 6b508f0
Former-commit-id: f279b0b10add514266481fffe7dbd08ae0cacfbb
  • Loading branch information
breadchris committed Apr 13, 2022
1 parent fcf8384 commit 2373f4e
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 17 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ outputs/
node_modules/
.npmrc
lunatrace/cli/test/**
lunatrace/bsl/backend-cdk/cdk.out
1 change: 1 addition & 0 deletions .idea/lunasec-monorepo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lunatrace/bsl/backend-cdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
cdk.out

cdk.context.json
build/
49 changes: 49 additions & 0 deletions lunatrace/bsl/backend-cdk/build-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
OUT_DIR=build/

saved_dir=$PWD

change-dir() {
saved_dir=$PWD
if ! cd "$1" ; then
echo "Unable to cd to $1"
exit 1
fi
}

reset-dir() {
change-dir "$saved_dir"
}

change-dir ../../..
if ! docker build . -f lunatrace/bsl/repo-bootstrap.dockerfile -t repo-bootstrap ; then
echo "unable to build repo-bootstrap"
exit 1
fi
reset-dir

change-dir ../frontend
if ! docker build . -t lunatrace-frontend ; then
echo "unable to build lunatrace-frontend"
exit 1
fi
reset-dir

change-dir ../backend
if ! docker build --target backend-express-server . -t lunatrace-backend ; then
echo "unable to build lunatrace-backend"
exit 1
fi
reset-dir

change-dir ../backend
if ! docker build --target backend-queue-processor . -t lunatrace-backend-queue-processor ; then
echo "unable to build lunatrace-backend-queue-processor"
exit 1
fi
reset-dir

mkdir -p $OUT_DIR
docker save -o $OUT_DIR/lunatrace-frontend.tar lunatrace-frontend
docker save -o $OUT_DIR/lunatrace-backend.tar lunatrace-backend
docker save -o $OUT_DIR/lunatrace-backend-queue-processor.tar lunatrace-backend-queue-processor
9 changes: 4 additions & 5 deletions lunatrace/bsl/backend-cdk/lib/etl-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* limitations under the License.
*
*/
import * as path from "path";

import { AssetImage, Cluster, ContainerImage, DeploymentControllerType, Secret as EcsSecret } from '@aws-cdk/aws-ecs';
import * as ecsPatterns from '@aws-cdk/aws-ecs-patterns';
import { ISecret } from '@aws-cdk/aws-secretsmanager';
Expand All @@ -19,6 +21,7 @@ import { Construct } from '@aws-cdk/core';

import { commonBuildProps } from './constants';
import { EtlStorageStackState } from './etl-storage-stack';
import {getContainerTarballPath} from "./util";

interface EtlStackProps extends cdk.StackProps {
fargateCluster: Cluster;
Expand Down Expand Up @@ -58,11 +61,7 @@ export class EtlStack extends cdk.Stack {
storageStack,
} = props;

const QueueProcessorContainerImage = ContainerImage.fromAsset('../', {
...commonBuildProps,
file: './backend/Dockerfile',
target: 'backend-queue-processor',
});
const QueueProcessorContainerImage = ContainerImage.fromTarball(getContainerTarballPath('lunatrace-backend-queue-processor.tar'));

const processManifestQueueService = new ecsPatterns.QueueProcessingFargateService(
context,
Expand Down
14 changes: 5 additions & 9 deletions lunatrace/bsl/backend-cdk/lib/lunatrace-backend-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*
*/

import * as path from "path";

import { Certificate } from '@aws-cdk/aws-certificatemanager';
import { Port, SecurityGroup, Vpc } from '@aws-cdk/aws-ec2';
import {
Expand All @@ -35,6 +37,7 @@ import * as cdk from '@aws-cdk/core';
import { commonBuildProps } from './constants';
import { EtlStack } from './etl-stack';
import { EtlStorageStack, EtlStorageStackState } from './etl-storage-stack';
import {getContainerTarballPath} from "./util";

interface LunaTraceStackProps extends cdk.StackProps {
// TODO: Make the output URL be a URL managed by us, not AWS
Expand Down Expand Up @@ -131,10 +134,7 @@ export class LunatraceBackendStack extends cdk.Stack {
executionRole: execRole,
});

const frontendContainerImage = ContainerImage.fromAsset('../', {
...commonBuildProps,
file: './frontend/Dockerfile',
});
const frontendContainerImage = ContainerImage.fromTarball(getContainerTarballPath('lunatrace-frontend.tar'));

const frontend = taskDef.addContainer('FrontendContainer', {
image: frontendContainerImage,
Expand Down Expand Up @@ -208,11 +208,7 @@ export class LunatraceBackendStack extends cdk.Stack {
},
});

const backendContainerImage = ContainerImage.fromAsset('../', {
...commonBuildProps,
file: './backend/Dockerfile',
target: 'backend-express-server',
});
const backendContainerImage = ContainerImage.fromAsset(getContainerTarballPath('lunatrace-backend.tar'));

const backend = taskDef.addContainer('BackendContainer', {
image: backendContainerImage,
Expand Down
18 changes: 18 additions & 0 deletions lunatrace/bsl/backend-cdk/lib/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright by LunaSec (owned by Refinery Labs, Inc)
*
* Licensed under the Business Source License v1.1
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import * as path from "path";

export function getContainerTarballPath(filename: string): string {
return path.join(__dirname, '../build', filename);
}
4 changes: 2 additions & 2 deletions lunatrace/bsl/backend-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",
"dev:cdk:deploy": "DEVELOPMENT=true yarn run cdk deploy --all",
"prod:cdk:deploy": "yarn run cdk deploy --all"
"dev:cdk:deploy": "DEVELOPMENT=true cdk deploy --all",
"prod:cdk:deploy": "rm -rf cdk.out && cdk build && cd cdk.out && cdk deploy --all --app ."
},
"devDependencies": {
"@aws-cdk/assert": "1.147.0",
Expand Down
2 changes: 1 addition & 1 deletion lunatrace/bsl/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN apk update && apk upgrade
COPY --from=frontend-build /usr/repo/lunatrace/bsl/frontend/build /static

RUN rm -rf /etc/nginx/conf.d/default.conf
COPY lunatrace/bsl/frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf

0 comments on commit 2373f4e

Please sign in to comment.