🔧 WIP Dockerfile fixes
This commit is contained in:
@@ -42,6 +42,8 @@ RUN node -v && npm -v
|
|||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
COPY moleculer.config.ts ./
|
COPY moleculer.config.ts ./
|
||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
|
COPY scripts ./scripts
|
||||||
|
RUN chmod +x ./scripts/*
|
||||||
|
|
||||||
# Install application dependencies
|
# Install application dependencies
|
||||||
RUN npm install
|
RUN npm install
|
||||||
@@ -50,9 +52,8 @@ RUN npm install -g typescript ts-node
|
|||||||
# Copy the rest of the application files
|
# Copy the rest of the application files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build and clean up
|
# clean up
|
||||||
RUN npm run build \
|
RUN npm prune
|
||||||
&& npm prune
|
|
||||||
|
|
||||||
# Expose the application's port
|
# Expose the application's port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
@@ -1,10 +1,47 @@
|
|||||||
import { createClient } from "redis";
|
import { createClient } from "redis";
|
||||||
const redisURL = new URL(process.env.REDIS_URI);
|
import { URL } from "url";
|
||||||
|
|
||||||
const pubClient = createClient({ url: `redis://${redisURL.hostname}:6379` });
|
// Ensure that the REDIS_URI environment variable is set
|
||||||
(async () => {
|
const redisURL = process.env.REDIS_URI ? new URL(process.env.REDIS_URI) : null;
|
||||||
await pubClient.connect();
|
if (!redisURL) {
|
||||||
})();
|
throw new Error("REDIS_URI environment variable is not set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to create a Redis client
|
||||||
|
const createRedisClient = (url) => {
|
||||||
|
const client = createClient({ url });
|
||||||
|
|
||||||
|
client.on("error", (err) => {
|
||||||
|
console.error("Redis Client Error", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("connect", () => {
|
||||||
|
console.log("Connected to Redis:", url);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("reconnecting", () => {
|
||||||
|
console.log("Reconnecting to Redis...");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attempt to connect with error handling
|
||||||
|
client.connect().catch((err) => {
|
||||||
|
console.error("Failed to connect to Redis:", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return client;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create publisher and subscriber clients
|
||||||
|
const pubClient = createRedisClient(process.env.REDIS_URI);
|
||||||
const subClient = pubClient.duplicate();
|
const subClient = pubClient.duplicate();
|
||||||
|
|
||||||
|
// Ensure subscriber client handles connection and errors
|
||||||
|
subClient.on("error", (err) => {
|
||||||
|
console.error("Redis Subscriber Client Error", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
subClient.connect().catch((err) => {
|
||||||
|
console.error("Failed to connect Redis Subscriber:", err);
|
||||||
|
});
|
||||||
|
|
||||||
export { subClient, pubClient };
|
export { subClient, pubClient };
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const brokerConfig: BrokerOptions = {
|
|||||||
// More info: https://moleculer.services/docs/0.14/networking.html
|
// More info: https://moleculer.services/docs/0.14/networking.html
|
||||||
// Note: During the development, you don't need to define it because all services will be loaded locally.
|
// Note: During the development, you don't need to define it because all services will be loaded locally.
|
||||||
// In production you can set it via `TRANSPORTER=nats://localhost:4222` environment variable.
|
// In production you can set it via `TRANSPORTER=nats://localhost:4222` environment variable.
|
||||||
transporter: process.env.REDIS_URI || "redis://localhost:6379",
|
transporter: process.env.REDIS_URI || "redis://127.0.0.1:6379",
|
||||||
|
|
||||||
// Define a cacher.
|
// Define a cacher.
|
||||||
// More info: https://moleculer.services/docs/0.14/caching.html
|
// More info: https://moleculer.services/docs/0.14/caching.html
|
||||||
|
|||||||
Reference in New Issue
Block a user