This commit is contained in:
cupcakearmy 2022-02-07 13:14:23 +01:00
parent 8904ffcbdd
commit 157ce6b7b6
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
3 changed files with 35 additions and 5 deletions

View File

@ -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/), 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). 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 ## [1.1.1] - 2022-02-07
### Security ### Security

View File

@ -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 FROM node:16-alpine
WORKDIR /app WORKDIR /app
ADD . . ADD ./package.json ./pnpm-lock.yaml ./
RUN npm install -g pnpm RUN npm exec pnpm install --frozen-lockfile --prod
RUN pnpm install --frozen-lockfile COPY --from=builder /app/dist/ /app/dist/
RUN pnpm run build
STOPSIGNAL SIGTERM
CMD ["node", "."] CMD ["node", "."]

View File

@ -3,6 +3,7 @@ import Axios from 'axios'
import { CronJob } from 'cron' import { CronJob } from 'cron'
import { config } from 'dotenv' import { config } from 'dotenv'
import winston from 'winston' import winston from 'winston'
import process from 'process'
const logger = winston.createLogger({ const logger = winston.createLogger({
level: 'info', 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)) 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.') logger.info('Started service.')
function terminate() {
logger.info('Stopping service.')
cron.stop()
process.exit(0)
}
process.on('SIGINT', terminate)
process.on('SIGTERM', terminate)
} }
main() main()