Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,12 @@ install_deploysuite: &install_deploysuite
cp ./../buildscript/awsconfiguration.sh .
cp ../buildscript/psvar-processor.sh .

restore_cache_settings_for_build: &restore_cache_settings_for_build
key: docker-node-modules-{{ checksum "package-lock.json" }}

save_cache_settings: &save_cache_settings
key: docker-node-modules-{{ checksum "package-lock.json" }}
paths:
- node_modules

builddeploy_steps: &builddeploy_steps
- checkout
- setup_remote_docker
- run: *install_dependency
- run: *install_deploysuite
- restore_cache: *restore_cache_settings_for_build
- run: ./build.sh ${APPNAME}
- save_cache: *save_cache_settings
- deploy:
name: Running MasterScript.
command: |
Expand Down
24 changes: 14 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# compiled output
.git
.gitignore
.circleci
.vscode
/node_modules
.env*
node_modules
dist
coverage
logs
docs
test
*.log

# code formatter
.eslintrc
.eslintignore
.editorconfig
.eslintignore
.eslintrc
.huskyrc
.lintstagedrc.json
.prettierrc

# test
jest.config.js

# docker
Dockerfile
docker-compose.yml
jest.config.js
3 changes: 2 additions & 1 deletion .env.development.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ ORIGIN = *
CREDENTIALS = true

# Needed only locally, AWS env has those preconf on EC2
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=<ADD KEY>
AWS_SECRET_ACCESS_KEY=<ADD SECRET>
AWS_SECRET_ACCESS_KEY=<ADD SECRET>
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v17.8.0
v24.19.0
54 changes: 39 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
# Common build stage
FROM node:14.14.0-alpine3.12 as common-build-stage
# syntax=docker/dockerfile:1

COPY . ./app
ARG NODE_IMAGE=node:24.19.0-alpine3.24@sha256:d32cdf619f63fe0471182d08996dd516c6275bb5fd31ae06e55a570bd9e1ad43

FROM ${NODE_IMAGE} AS build-stage

WORKDIR /app

RUN npm install
COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npm run build

# This target is for local development only. The deploy pipeline intentionally
# uses development-build-stage, which is a minimal runtime image below.
FROM build-stage AS local-development-build-stage

ENV NODE_ENV=development

EXPOSE 3000
CMD ["npm", "run", "dev"]

# Development build stage
FROM common-build-stage as development-build-stage
FROM ${NODE_IMAGE} AS production-dependencies-stage

RUN chmod +x /app/docker-entrypoint.sh
WORKDIR /app

ENTRYPOINT [ "docker-entrypoint.sh" ]
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --ignore-scripts \
&& npm cache clean --force

ENV NODE_ENV development
FROM ${NODE_IMAGE} AS runtime-stage

CMD ["npm", "run", "dev"]
WORKDIR /app

# Production build stage
FROM common-build-stage as production-build-stage
# Package managers are build-time tooling. Removing them from the runtime image
# eliminates their dependency tree and prevents package installation in a live
# container.
RUN rm -rf /usr/local/lib/node_modules /opt/yarn-v* \
&& rm -f /usr/local/bin/corepack /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/yarn /usr/local/bin/yarnpkg

ENV NODE_ENV production
RUN npm run build
COPY --from=production-dependencies-stage /app/node_modules ./node_modules
COPY --from=build-stage /app/dist ./dist

EXPOSE 3000
USER node
CMD ["node", "dist/server.js"]

# CircleCI deploys this target to the development ECR repository.
FROM runtime-stage AS development-build-stage
ENV NODE_ENV=development

CMD ["npm", "run", "prod"]
FROM runtime-stage AS production-build-stage
ENV NODE_ENV=production
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ APP_NAME := $(APP_NAME)
# Build the container image - Dvelopment
build-dev:
docker build -t ${APP_NAME}\
--target development-build-stage\
--target local-development-build-stage\
-f Dockerfile .

# Build the container image - Production
Expand Down
24 changes: 2 additions & 22 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
#!/bin/bash
set -eo pipefail
APP_NAME=$1
UPDATE_CACHE=""
# docker-compose -f docker/docker-compose.yml build $APP_NAME
# docker create --name app $APP_NAME:latest

docker build -f Dockerfile \
--target ${BUILDSTAGE}-build-stage \
-t $APP_NAME:latest .
docker create --name app $APP_NAME:latest

if [ -d node_modules ]
then
mv package-lock.json old-package-lock.json
docker cp app:/app/package-lock.json package-lock.json
set +eo pipefail
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
set -eo pipefail
else
UPDATE_CACHE=1
fi

if [ "$UPDATE_CACHE" == 1 ]
then
docker cp app:/app/node_modules .
fi
--target "${BUILDSTAGE}-build-stage" \
-t "${APP_NAME}:latest" .
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
server:
build:
context: ./
target: development-build-stage
target: local-development-build-stage
dockerfile: Dockerfile
container_name: server
ports:
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { compilerOptions } = require('./tsconfig.json');
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
roots: ['<rootDir>/src', '<rootDir>/test'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
Expand Down
Loading
Loading