Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: Build & Push Notification Service Docker Image

on:
push:
branches: ["main"]
branches:
- develop
- main

permissions:
contents: read
packages: write

env:
IMAGE_NAME: ghcr.io/ricash-org/notification-service

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -29,11 +34,13 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build & Push
- name: Build & Push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
tags: ghcr.io/ricash-org/notification-service:latest
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ github.ref_name }}
${{ env.IMAGE_NAME }}:${{ github.sha }}
23 changes: 6 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
# =============================
# Stage 1 : Build
# Stage 1 : Build
# =============================
FROM node:18-alpine AS builder
FROM node:20-alpine AS builder
WORKDIR /app

# Copier package.json et lock file
COPY package*.json ./
RUN npm ci

# Installer toutes les dépendances
RUN npm install

# Copier tout le code source
COPY . .

# Compiler Typescript -> JavaScript
RUN npm run build

# =============================
# Stage 2 : Runtime
# ============================
FROM node:18-alpine AS runner
# Stage 2 : Runtime
# =============================
FROM node:20-alpine
WORKDIR /app
ENV NODE_ENV=production

# Copier uniquement ce qui sert à l'exécution
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

# Exposer le port
EXPOSE 3000


# Lancer la version compilée
CMD ["node", "dist/server.js"]

4 changes: 2 additions & 2 deletions src/config/rabbitmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as amqp from "amqplib";
import type { Connection, Channel } from "amqplib";


let connection: amqp.Connection | null = null;
//let connection: amqp.Connection | null = null;
let channel: Channel | null= null;

/** Variables standardisées */
Expand Down Expand Up @@ -30,7 +30,7 @@ export async function ensureChannel(): Promise<Channel> {
conn.on("close", () => {
console.error("RabbitMQ fermé – reconnexion...");
// channel = null;
// connection = null;
//connection = null;
setTimeout(ensureChannel, 3000);
});

Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ router.post("/otp/generate", generateOtp);
router.post("/otp/verify", verifyOtp);

export default router;

require("dotenv").config();
const express = require("express");
const healthRoute = require("../routes/health");

const app = express();
const PORT = process.env.SERVICE_PORT || 8000;

app.use(express.json());
app.use("/", healthRoute);

app.listen(PORT, () => {
console.log(`🚀 Service running on port ${PORT}`);
});
13 changes: 13 additions & 0 deletions src/routes/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require("express");
import type { Request, Response } from "express";
const router = express.Router();

interface HealthResponse {
status: string;
}

router.get("/health", (req: Request, res: Response<HealthResponse>) => {
res.status(200).json({ status: "OK" });
});

module.exports = router;
8 changes: 7 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import { startConsumer } from "./messaging/consumer";
import { ensureChannel } from "./config/rabbitmq";
import { startExternalNotificationConsumer } from "./messaging/externalConsumer";

const express = require("express");
const healthRoute = require("../routes/health");


dotenv.config();

const PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
const PORT = process.env.SERVICE_PORT ? Number(process.env.SERVICE_PORT) : 8000;


AppDataSource.initialize()
Expand All @@ -22,6 +26,8 @@ AppDataSource.initialize()

})
.catch((err) => console.error("Erreur de connexion :", err));
app.use(express.json());
app.use("/", healthRoute);
/*
async function startServer() {
console.log("⏳ Initialisation du service de notifications...");
Expand Down