Skip to content

Commit

Permalink
Setup for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 3, 2024
1 parent 7f4e74f commit c2be572
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.env
.github
build
Dockerfile
docker-compose.yml
node_modules
tmp
*.log
*.zip
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# lambda build
build/
build.zip
22 changes: 22 additions & 0 deletions .lambdaignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.dockerignore
.editorconfig
.env
.eslintrc.yml
.git
.github
.gitignore
.lambdaignore
.prettierignore
.prettierrc.yml
.tool-versions
buildspec.yml
docker-compose.yml
Dockerfile
env-example
/build*
runner.js
/tmp
tsconfig.json
*.test.js
*.log
*.zip
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore artifacts:
build
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM public.ecr.aws/lambda/nodejs:20

LABEL maintainer="PRX <[email protected]>"
LABEL org.prx.spire.publish.s3="LAMBDA_ZIP"

WORKDIR /app

ENTRYPOINT [ "yarn", "run" ]
CMD [ "test" ]

RUN yum install -y rsync zip tar xz && yum clean all && rm -rf /var/cache/yum
ADD yarn.lock ./
ADD package.json ./
RUN yarn install
ADD . .
RUN yarn run build
18 changes: 18 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.2
env:
variables:
PRX_SPIRE_S3_PKG_PARAMETERS: LAMBDA_ZIP=/prx/stag/Spire/Dovetail-CDN_Usage/pkg/s3-object-key
PRX_S3_ARCHIVE_BUILD_PATH: /app/build.zip
exported-variables:
- PRX_SPIRE_S3_PKG_PARAMETERS
- LAMBDA_ZIP
phases:
build:
commands:
- docker-compose build
- docker-compose run test
post_build:
commands:
- curl -sO "https://raw.githubusercontent.com/PRX/Infrastructure/main/ci/utility/post_build.sh"
- chmod +x post_build.sh
- . ./post_build.sh
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"
services:
test:
build: .
image: dovetailcdnusage
command: test
volumes:
- ./index.js:/app/index.js
- ./index.test.js:/app/index.test.js
- ./lib:/app/lib
- ./package.json:/app/package.json
15 changes: 15 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const log = require("lambda-log");
const index = require("./index");

describe("index", () => {
describe("handler", () => {
it("validates dates", async () => {
jest.spyOn(log, "error").mockImplementation(() => null);

expect(index.handler({ day: "n/a" })).rejects.toThrow(/invalid date/i);

expect(log.error).toHaveBeenCalledTimes(1);
expect(log.error.mock.calls[0][0]).toMatch(/error running rollups/);
});
});
});
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"private": "true",
"scripts": {
"build": "yarn run build-sync && yarn run build-prune && yarn run build-zip",
"build-sync": "rsync -crl --delete --exclude-from .lambdaignore . build",
"build-prune": "cd build && yarn --production",
"build-zip": "rm -f build.zip && cd build && zip -rq ../build.zip .",
"lint": "npm run lint-prettier && npm run lint-es",
"lint-prettier": "npx prettier --check **/*.{json,yml}",
"lint-es": "npx eslint '**/*.{js,mjs}'",
Expand Down

0 comments on commit c2be572

Please sign in to comment.