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
50 changes: 37 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
name: Build & Push Notification Service Docker Image
name: Ricash CI - Build & Push Docker Image

on:
pull_request:
branches:
- develop

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

permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io
IMAGE_NAME: ricash-org/${{ github.event.repository.name }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
# ===============================
# PR → BUILD ONLY (NO PUSH)
# ===============================
- name: Build Docker image (Pull Request)
if: github.event_name == 'pull_request'
run: |
docker build -t $IMAGE_NAME:pr .

# ===============================
# PUSH → LOGIN GHCR
# ===============================
- name: Login to GitHub Container Registry
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build & Push
# ===============================
# PUSH → BUILD & PUSH IMAGE
# ===============================
- name: Build & Push Docker image
if: github.event_name == 'push'
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
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name == 'main' && 'latest' || 'dev' }}
${{ env.REGISTRY }}/${{ 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
Loading