Skip to content

Commit 07acf10

Browse files
authored
Various tweaks to support proper operation (#4)
* Various tweaks to support proper operation - Fix CircleCI build pipeline - Update Dockerfile to use a multistage build and set the correct CMD - Add morgan as logging middleware - Use proper domain (placeholder now...) when signing download URLs - Don't set DB secrets for k8s - DO set AWS_REGION and S3_BUCKET env vars for k8s
1 parent 425a2e0 commit 07acf10

File tree

12 files changed

+824
-117
lines changed

12 files changed

+824
-117
lines changed

templates/.circleci/config.yml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
version: 2.1
33
orbs:
4+
node: circleci/node@3.0.1
45
aws-ecr: circleci/aws-ecr@6.5.0
56
aws-eks: circleci/aws-eks@0.2.3
67
aws-s3: circleci/aws-s3@1.0.11
@@ -12,7 +13,7 @@ orbs:
1213
variables:
1314
- &workspace /home/circleci/project
1415

15-
- &build-image cimg/go:1.13
16+
- &build-image cimg/node:14.10
1617

1718

1819
aliases:
@@ -111,30 +112,30 @@ jobs:
111112
steps: # steps that comprise the `build` job
112113
- attach_workspace:
113114
at: *workspace
114-
- restore_cache: # restores saved cache if no changes are detected since last run
115-
keys:
116-
- v1-pkg-cache-{{ checksum "go.sum" }}
117-
- v1-pkg-cache-
115+
- node/install-packages:
116+
cache-path: "./node_modules"
117+
app-dir: .
118118
- run:
119-
name: Run unit tests
120-
command: |
121-
go get -u github.com/jstemmer/go-junit-report
122-
mkdir -p test-reports
123-
go test -v ./... | go-junit-report > test-reports/junit.xml
124-
125-
- save_cache: # Store cache in the /go/pkg directory
126-
key: v1-pkg-cache-{{ checksum "go.sum" }}
127-
paths:
128-
- "/go/pkg"
129-
119+
name: Generating env file
120+
command: cp .env.example .env
130121
- store_test_results:
131122
path: test-reports
132-
133123
- store_artifacts:
134124
path: test-reports
135125

136126
# Requires the SLACK_WEBHOOK env var to be set
137127
#- slack/notify-on-failure
128+
lint:
129+
docker:
130+
- image: *build-image
131+
working_directory: *workspace
132+
steps:
133+
- attach_workspace:
134+
at: *workspace
135+
- node/install-packages:
136+
cache-path: "./node_modules"
137+
app-dir: .
138+
- run: npm run lint
138139

139140
build_and_push:
140141
machine:
@@ -243,10 +244,14 @@ workflows:
243244
jobs:
244245
- checkout_code
245246

246-
- unit_test:
247+
- lint:
247248
requires:
248249
- checkout_code
249250

251+
- unit_test:
252+
requires:
253+
- lint
254+
250255
- build_and_push:
251256
account-id: "<% index .Params `accountId` %>"
252257
repo: "<% .Name %>"

templates/.eslintrc.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = {
2+
env: {
3+
es6: true,
4+
node: true,
5+
jest: true,
6+
jasmine: true,
7+
},
8+
extends: [
9+
"eslint:recommended",
10+
"plugin:import/errors",
11+
"plugin:import/warnings",
12+
"plugin:node/recommended",
13+
"plugin:promise/recommended",
14+
"plugin:prettier/recommended",
15+
],
16+
parserOptions: {
17+
ecmaVersion: 2020,
18+
sourceType: "module",
19+
ecmaFeatures: {
20+
jsx: true,
21+
},
22+
},
23+
plugins: ["import", "node", "prettier", "promise"],
24+
rules: {
25+
"import/order": [
26+
2,
27+
{
28+
groups: [
29+
["builtin", "external"],
30+
["internal", "parent", "sibling", "index"],
31+
],
32+
"newlines-between": "always",
33+
},
34+
],
35+
"import/newline-after-import": [2],
36+
"linebreak-style": ["error", "unix"],
37+
"no-console": "off",
38+
quotes: ["error", "double", { avoidEscape: true }],
39+
semi: ["error", "always"],
40+
},
41+
};

templates/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ $RECYCLE.BIN/
9999

100100
# application environment config
101101
.env
102+
node_modules

templates/Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
FROM node:14.9-alpine
1+
FROM node:14-alpine as base
22
WORKDIR /app
33
COPY . .
4-
RUN npm i
54

6-
ENTRYPOINT ["/app/<% .Name %>"]
5+
RUN touch .env
6+
RUN npm i --no-optional --production
7+
8+
FROM node:14-alpine
9+
WORKDIR /app
10+
COPY --from=base /app /app
11+
12+
CMD ["node", "src/app.js"]

templates/app.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

templates/kubernetes/base/deployment.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ spec:
4747
valueFrom:
4848
fieldRef:
4949
fieldPath: metadata.name
50-
- name: DATABASE_USERNAME
51-
valueFrom:
52-
secretKeyRef:
53-
name: <% .Name %>
54-
key: DATABASE_USERNAME
55-
- name: DATABASE_PASSWORD
56-
valueFrom:
57-
secretKeyRef:
58-
name: <% .Name %>
59-
key: DATABASE_PASSWORD
6050
- name: CF_KEYPAIR_ID
6151
valueFrom:
6252
secretKeyRef:

templates/kubernetes/base/kustomization.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ configMapGenerator:
1414
- DATABASE_PORT=<%if eq (index .Params `database`) "postgres" %>5432<% else if eq (index .Params `database`) "mysql" %>3306<% end %>
1515
- DATABASE_NAME=<% index .Params `databaseName` %>
1616
- SERVICE_PORT=80
17+
- AWS_REGION=<% index .Params `region` %>
1718

1819
commonLabels:
1920
app: <% .Name %>

templates/kubernetes/overlays/production/kustomization.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ configMapGenerator:
1414
behavior: merge
1515
literals:
1616
- ENVIRONMENT=production
17+
- DOMAIN=<% index .Params `productionHostRoot` %>
18+
- S3_BUCKET=files.<% index .Params `productionHostRoot` %>

templates/kubernetes/overlays/staging/kustomization.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ configMapGenerator:
1313
behavior: merge
1414
literals:
1515
- ENVIRONMENT=staging
16+
- DOMAIN=<% index .Params `stagingHostRoot` %>
17+
- S3_BUCKET=files.<% index .Params `stagingHostRoot` %>

0 commit comments

Comments
 (0)