Skip to content

Commit

Permalink
bug(build): fix docker base image (#27)
Browse files Browse the repository at this point in the history
* fix docker base image

* update compile settings

* fix build settings

* update build process for config

* replace config

* remove unneeded config dir
  • Loading branch information
mcalhoun authored May 19, 2022
1 parent 30e36d8 commit fccfcb3
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BOSSY_SLACK_OAUTH_TOKEN=default
BOSSY_SLACK_SECRET=default
BOSSY_SLACK_SIGNING_SECRET=default
BOSSY_SPACELIFT_TO_SLACK_CHANNEL=default
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- name: Build Affected Projects
shell: bash
run: npx nx run-many --target=build --all
run: npx nx run-many --target=build --prod --all

##################################################
# Build and Push Bossy Docker Image
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Thumbs.db
*.tfstate.*
.terraform
.terraform.tfstate.lock.info

.env
5 changes: 1 addition & 4 deletions apps/bossy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/nodejs:14
FROM public.ecr.aws/lambda/nodejs:16

# add app
COPY dist/apps/bossy/main.js ${LAMBDA_TASK_ROOT}
Expand All @@ -8,9 +8,6 @@ COPY dist/apps/bossy/package.json ${LAMBDA_TASK_ROOT}
# install app dependencies
RUN npm install --production

# add config
ADD config ${LAMBDA_TASK_ROOT}/config

ENV NODE_ENV=production

# start app
Expand Down
4 changes: 3 additions & 1 deletion apps/bossy/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"main": "apps/bossy/src/main.ts",
"tsConfig": "apps/bossy/tsconfig.app.json",
"assets": ["apps/bossy/src/assets"],
"generatePackageJson": true
"generatePackageJson": true,
"externalDependencies": "none"
},
"configurations": {
"production": {
"main": "apps/bossy/src/lambda.ts",
"optimization": true,
"extractLicenses": true,
"inspect": false,
Expand Down
2 changes: 0 additions & 2 deletions apps/bossy/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { sendSpaceliftEventsToSlackRouter } from "@cloudposse/modules/spacelift"
import express from "express";
import helmet from "helmet";

process.env["NODE_CONFIG_DIR"] = process.cwd() + "/config/";

const app = express();

app.use(helmet());
Expand Down
3 changes: 3 additions & 0 deletions apps/bossy/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();

import { createLogger } from "@cloudposse/common";
import serverlessExpress from "@vendia/serverless-express";

Expand Down
3 changes: 3 additions & 0 deletions apps/bossy/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config();

import { createLogger } from "@cloudposse/common";

import { app } from "./app";
Expand Down
4 changes: 3 additions & 1 deletion apps/bossy/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node", "express"]
"types": ["node", "express"],
"target": "es2017",
"lib": ["es2021"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
Expand Down
8 changes: 0 additions & 8 deletions config/custom-environment-variables.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions config/default.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions config/production.yaml

This file was deleted.

15 changes: 6 additions & 9 deletions libs/common/common/src/lib/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nodeConfig from "config";

interface IConfig {
env: string;
slack: ISlackConfig;
Expand All @@ -22,17 +20,16 @@ class Config implements IConfig {
spacelliftToSlackConfig: ISpacelliftToSlackConfig;

private constructor() {
this.env = nodeConfig.get<string>("env");
this.env = process.env.NODE_ENV || "development";

this.slack = {} as ISlackConfig;
this.slack.oAuthToken = nodeConfig.get<string>("slack.oauth_token");
this.slack.secret = nodeConfig.get<string>("slack.secret");
this.slack.signingSecret = nodeConfig.get<string>("slack.signing_secret");
this.slack.oAuthToken = process.env.BOSSY_SLACK_OAUTH_TOKEN;
this.slack.secret = process.env.BOSSY_SLACK_SECRET;
this.slack.signingSecret = process.env.BOSSY_SLACK_SIGNING_SECRET;

this.spacelliftToSlackConfig = {} as ISpacelliftToSlackConfig;
this.spacelliftToSlackConfig.slackChannel = nodeConfig.get<string>(
"spaceliftToSlack.slack_channel"
);
this.spacelliftToSlackConfig.slackChannel =
process.env.BOSSY_SPACELIFT_TO_SLACK_CHANNEL;
}

public static getInstance(): Config {
Expand Down
5 changes: 5 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"dependencies": "*",
"devDependencies": "*"
},
"bossy": {
"implicitDependencies": {
"js-yaml": "*"
}
},
".eslintrc.json": "*"
},
"tasksRunnerOptions": {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"start": "nx serve",
"build": "nx build",
"build:bossy:lambda": "nx build bossy --main apps/bossy/src/lambda.ts",
"build:bossy:docker": "docker build -t $BOSSY_ECR_REPO/bossy -f apps/bossy/Dockerfile .",
"build:bossy:docker": "docker build -t bossy -f apps/bossy/Dockerfile .",
"test": "nx test"
},
"private": true,
"dependencies": {
"@slack/bolt": "3.11.0",
"@slack/web-api": "6.7.1",
"@vendia/serverless-express": "4.8.0",
"config": "3.3.7",
"crypto": "1.0.1",
"dotenv": "^16.0.1",
"express": "4.18.1",
"helmet": "5.0.2",
"js-yaml": "4.1.0",
Expand Down Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-sort-destructure-keys": "1.4.0",
"jest": "28.1.0",
"moq.ts": "7.3.4",
"node-config-webpack": "^1.0.9",
"prettier": "2.6.2",
"ts-jest": "28.0.2",
"typescript": "4.6.4"
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"strict": false,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=

[email protected]:
[email protected], config@^3.3.6:
version "3.3.7"
resolved "https://registry.yarnpkg.com/config/-/config-3.3.7.tgz#4310410dc2bf4e0effdca21a12a4035860a24ee4"
integrity sha512-mX/n7GKDYZMqvvkY6e6oBY49W8wxdmQt+ho/5lhwFDXqQW9gI+Ahp8EKp8VAbISPnmf2+Bv5uZK7lKXZ6pf1aA==
Expand Down Expand Up @@ -2797,6 +2797,11 @@ domexception@^2.0.1:
dependencies:
webidl-conversions "^5.0.0"

dotenv@^16.0.1:
version "16.0.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d"
integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==

dotenv@~10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
Expand Down Expand Up @@ -5308,6 +5313,14 @@ node-addon-api@^3.2.1:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==

node-config-webpack@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/node-config-webpack/-/node-config-webpack-1.0.9.tgz#f7f8d22518577cfbfc9b8c2343bd24a420750528"
integrity sha512-8D9MIcRDUnav7r1Z0IPUrIyVFN9IVGrv25SUATZKq9eyIlKfrvelMxVVNbUaIUBT6smw3DchFFYaNRFZ/hkaoQ==
dependencies:
config "^3.3.6"
js-yaml "^4.1.0"

node-gyp-build@^4.3.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.4.0.tgz#42e99687ce87ddeaf3a10b99dc06abc11021f3f4"
Expand Down

0 comments on commit fccfcb3

Please sign in to comment.