Skip to content

Commit 157ce6b

Browse files
committed
1.2.0
1 parent 8904ffc commit 157ce6b

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.0] - 2022-02-07
9+
10+
### Added
11+
12+
- Sigterm and Sigkill hooks for graceful shutdown
13+
14+
### Changed
15+
16+
- Multistage steps to reduce image size
17+
818
## [1.1.1] - 2022-02-07
919

1020
### Security

Dockerfile

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
FROM node:16-alpine
1+
FROM node:16-alpine as builder
22

33
WORKDIR /app
44

5+
ADD ./package.json ./pnpm-lock.yaml ./
6+
RUN npm exec pnpm install --frozen-lockfile
7+
58
ADD . .
6-
RUN npm install -g pnpm
7-
RUN pnpm install --frozen-lockfile
8-
RUN pnpm run build
9+
RUN npm exec pnpm run build
10+
11+
FROM node:16-alpine
12+
13+
WORKDIR /app
14+
15+
ADD ./package.json ./pnpm-lock.yaml ./
16+
RUN npm exec pnpm install --frozen-lockfile --prod
17+
COPY --from=builder /app/dist/ /app/dist/
18+
19+
STOPSIGNAL SIGTERM
920

1021
CMD ["node", "."]

src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Axios from 'axios'
33
import { CronJob } from 'cron'
44
import { config } from 'dotenv'
55
import winston from 'winston'
6+
import process from 'process'
67

78
const logger = winston.createLogger({
89
level: 'info',
@@ -107,8 +108,16 @@ async function main() {
107108
if (changed) await update(cf, { ip, record: DNS_RECORD!, zone: ZONE! }).catch((e) => logger.error(e.message))
108109
}
109110

110-
new CronJob(CRON || '*/5 * * * *', fn, null, true, undefined, null, true)
111+
const cron = new CronJob(CRON || '*/5 * * * *', fn, null, true, undefined, null, true)
111112
logger.info('Started service.')
113+
114+
function terminate() {
115+
logger.info('Stopping service.')
116+
cron.stop()
117+
process.exit(0)
118+
}
119+
process.on('SIGINT', terminate)
120+
process.on('SIGTERM', terminate)
112121
}
113122

114123
main()

0 commit comments

Comments
 (0)