🔧 WIP Dockerfile fixes

This commit is contained in:
2024-05-15 11:32:11 -05:00
parent f4563c12c6
commit 323548c0ff
3 changed files with 47 additions and 9 deletions

View File

@@ -42,6 +42,8 @@ RUN node -v && npm -v
COPY package.json package-lock.json ./
COPY moleculer.config.ts ./
COPY tsconfig.json ./
COPY scripts ./scripts
RUN chmod +x ./scripts/*
# Install application dependencies
RUN npm install
@@ -50,9 +52,8 @@ RUN npm install -g typescript ts-node
# Copy the rest of the application files
COPY . .
# Build and clean up
RUN npm run build \
&& npm prune
# clean up
RUN npm prune
# Expose the application's port
EXPOSE 3000

View File

@@ -1,10 +1,47 @@
import { createClient } from "redis";
const redisURL = new URL(process.env.REDIS_URI);
import { URL } from "url";
const pubClient = createClient({ url: `redis://${redisURL.hostname}:6379` });
(async () => {
await pubClient.connect();
})();
// Ensure that the REDIS_URI environment variable is set
const redisURL = process.env.REDIS_URI ? new URL(process.env.REDIS_URI) : null;
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();
// 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 };

View File

@@ -90,7 +90,7 @@ const brokerConfig: BrokerOptions = {
// 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.
// 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.
// More info: https://moleculer.services/docs/0.14/caching.html