diff --git a/Dockerfile.consumer b/Dockerfile.consumer new file mode 100644 index 0000000..478ec15 --- /dev/null +++ b/Dockerfile.consumer @@ -0,0 +1,35 @@ +FROM debian:bookworm-slim + +ARG DEBIAN_FRONTEND=noninteractive + +# NodeJs + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + gnupg2 \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y --no-install-recommends nodejs \ + && rm -rf /var/lib/apt/lists/* + +# Consumer + +WORKDIR /mycdc +COPY package.json package-lock.json ./ +RUN npm install --only=prod + +ARG BUILD_ID=unknown +ARG VERSION +ENV VERSION $VERSION +RUN echo $VERSION + +COPY config config +COPY \ + LICENSE \ + README.md \ + consumer.js \ + queue.js \ + ./ + +CMD ["node", "consumer.js"] diff --git a/Dockerfile.producer b/Dockerfile.producer new file mode 100644 index 0000000..01e403e --- /dev/null +++ b/Dockerfile.producer @@ -0,0 +1,34 @@ +FROM debian:bookworm-slim + +ARG DEBIAN_FRONTEND=noninteractive + +# NodeJs + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + gnupg2 \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y --no-install-recommends nodejs \ + && rm -rf /var/lib/apt/lists/* + +# Consumer + +WORKDIR /mycdc +COPY package.json package-lock.json ./ +RUN npm install --only=prod + +ARG BUILD_ID=unknown +ARG VERSION +ENV VERSION $VERSION +RUN echo $VERSION + +COPY config config +COPY \ + LICENSE \ + README.md \ + mycdc.js \ + ./ + +CMD ["node", "mycdc.js"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..9f5c8b6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,40 @@ +#!/usr/bin/env groovy + +pipeline { + agent any + options { + disableConcurrentBuilds() + } + stages { + stage('Build') { + when {branch 'master'} + steps { + script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + } + sh 'docker-compose build --build-arg BUILD_ID=$BUILD_ID --parallel' + } + } + stage('Push') { + when {branch 'master'} + environment { + CREDENTIALS = credentials('docker-registry') + } + steps { + script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + } + sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY' + sh 'docker-compose push' + } + } + } + post { + unsuccessful { + setEnv() + sendEmail() + } + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..92fea62 --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +Copyright (C) 2024 - Verdnatura Levante S.L. + +This package is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +On Debian systems, the complete text of the GNU General Public +License can be found in "/usr/share/common-licenses/GPL-3". \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6ed67f4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.7' +services: + producer: + image: registry.verdnatura.es/mycdc-producer:${VERSION:?} + build: + context: . + dockerfile: Dockerfile.producer + consumer: + image: registry.verdnatura.es/mycdc-consumer:${VERSION:?} + build: + context: . + dockerfile: Dockerfile.consumer diff --git a/queue.js b/queue.js index d5668c0..a05c39d 100644 --- a/queue.js +++ b/queue.js @@ -5,7 +5,10 @@ module.exports = class Queue { } async consume() { - if (this.conf.mode !== 'fk') return; + if (this.conf.mode !== 'fk') { + console.warn(`Ignoring queue '${this.name} with unknown mode '${this.conf.mode}'`); + return; + } const channel = await this.consumer.amqpConn.createChannel(); channel.prefetch(this.conf.amqpPrefetch);