FROM public.ecr.aws/lambda/nodejs:14 as base
FROM base as builder

WORKDIR /usr/src/lambda

COPY package.json package-lock.json  ./

RUN npm ci

COPY tsconfig.json ./
COPY src/ ./src/

RUN npm run build

FROM base as runtime

COPY --from=builder /usr/src/lambda/node_modules ${LAMBDA_TASK_ROOT}/node_modules
COPY --from=builder /usr/src/lambda/dist/*.js ${LAMBDA_TASK_ROOT}/dist/

# Datadog on Lambda with Docker
# https://docs.datadoghq.com/serverless/installation/nodejs/?tab=containerimage#configure-the-function
ENV DD_TRACE_ENABLED=true
ENV DD_FLUSH_TO_LOG=true
ENV DD_LOG_LEVEL=debug

VOLUME ${LAMBDA_TASK_ROOT}/dist

CMD [ "dist/function.sendNotifications" ]
