From 157ce6b7b622a6c48dc6dd30edabced66402df04 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 7 Feb 2022 13:14:23 +0100 Subject: [PATCH] 1.2.0 --- CHANGELOG.md | 10 ++++++++++ Dockerfile | 19 +++++++++++++++---- src/index.ts | 11 ++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8fd25..e3a9d8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.0] - 2022-02-07 + +### Added + +- Sigterm and Sigkill hooks for graceful shutdown + +### Changed + +- Multistage steps to reduce image size + ## [1.1.1] - 2022-02-07 ### Security diff --git a/Dockerfile b/Dockerfile index f9b3e8d..9edbf69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,21 @@ +FROM node:16-alpine as builder + +WORKDIR /app + +ADD ./package.json ./pnpm-lock.yaml ./ +RUN npm exec pnpm install --frozen-lockfile + +ADD . . +RUN npm exec pnpm run build + FROM node:16-alpine WORKDIR /app -ADD . . -RUN npm install -g pnpm -RUN pnpm install --frozen-lockfile -RUN pnpm run build +ADD ./package.json ./pnpm-lock.yaml ./ +RUN npm exec pnpm install --frozen-lockfile --prod +COPY --from=builder /app/dist/ /app/dist/ + +STOPSIGNAL SIGTERM CMD ["node", "."] diff --git a/src/index.ts b/src/index.ts index 6b6ae4a..7b57d49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import Axios from 'axios' import { CronJob } from 'cron' import { config } from 'dotenv' import winston from 'winston' +import process from 'process' const logger = winston.createLogger({ level: 'info', @@ -107,8 +108,16 @@ async function main() { if (changed) await update(cf, { ip, record: DNS_RECORD!, zone: ZONE! }).catch((e) => logger.error(e.message)) } - new CronJob(CRON || '*/5 * * * *', fn, null, true, undefined, null, true) + const cron = new CronJob(CRON || '*/5 * * * *', fn, null, true, undefined, null, true) logger.info('Started service.') + + function terminate() { + logger.info('Stopping service.') + cron.stop() + process.exit(0) + } + process.on('SIGINT', terminate) + process.on('SIGTERM', terminate) } main()