Update Dockerfile and LogManager

This commit is contained in:
Jesse Wierzbinski 2024-04-07 00:18:21 -10:00
parent ae2173e8b1
commit 21711960df
No known key found for this signature in database
5 changed files with 8 additions and 18 deletions

View file

@ -71,7 +71,7 @@ jobs:
with: with:
context: . context: .
file: Dockerfile file: Dockerfile
labels: latest #${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }} platforms: ${{ matrix.platform }}

View file

@ -42,6 +42,6 @@ LABEL org.opencontainers.image.description "Lysand Server docker image"
# CD to app # CD to app
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
ENTRYPOINT [ "/bin/sh", "entrypoint.sh" ] ENTRYPOINT [ "/bin/sh", "/app/entrypoint.sh" ]
# Run migrations and start the server # Run migrations and start the server
CMD [ "start" ] CMD [ "start" ]

View file

@ -7,9 +7,9 @@
# - `prisma`: Execute a Prisma command, sends # - `prisma`: Execute a Prisma command, sends
# Exit immediately if a command exits with a non-zero status. # Exit immediately if a command exits with a non-zero status.
set -e set -euxo pipefail
cd ./dist cd /app/dist
# Parse first argument # Parse first argument
case "$1" in case "$1" in

View file

@ -1,4 +1,4 @@
import { appendFile, writeFile, mkdir, exists } from "node:fs/promises"; import { appendFile, mkdir, exists } from "node:fs/promises";
import { dirname } from "node:path"; import { dirname } from "node:path";
import type { BunFile } from "bun"; import type { BunFile } from "bun";
@ -42,6 +42,7 @@ export class LogManager {
} }
private async write(text: string) { private async write(text: string) {
Bun.stdout.name;
if (this.output === Bun.stdout) { if (this.output === Bun.stdout) {
await Bun.write(Bun.stdout, `${text}\n`); await Bun.write(Bun.stdout, `${text}\n`);
} else { } else {
@ -51,7 +52,6 @@ export class LogManager {
await mkdir(dirname(this.output.name ?? ""), { await mkdir(dirname(this.output.name ?? ""), {
recursive: true, recursive: true,
}); });
await writeFile(this.output.name ?? "", "");
this.output = Bun.file(this.output.name ?? ""); this.output = Bun.file(this.output.name ?? "");
} catch { } catch {
// //

View file

@ -21,13 +21,14 @@ describe("LogManager", () => {
beforeEach(async () => { beforeEach(async () => {
mockOutput = Bun.file("test.log"); mockOutput = Bun.file("test.log");
mockAppend = jest.fn(); mockAppend = jest.fn();
await mock.module("fs/promises", () => ({ await mock.module("node:fs/promises", () => ({
appendFile: mockAppend, appendFile: mockAppend,
})); }));
logManager = new LogManager(mockOutput); logManager = new LogManager(mockOutput);
}); });
it("should initialize and write init log", () => { it("should initialize and write init log", () => {
new LogManager(mockOutput);
expect(mockAppend).toHaveBeenCalledWith( expect(mockAppend).toHaveBeenCalledWith(
mockOutput.name, mockOutput.name,
expect.stringContaining("--- INIT LogManager at"), expect.stringContaining("--- INIT LogManager at"),
@ -72,17 +73,6 @@ describe("LogManager", () => {
); );
}); });
it("should throw error if output file does not exist", () => {
mockAppend.mockImplementationOnce(() => {
return Promise.reject(
new Error("Output file doesnt exist (and isnt stdout)"),
);
});
expect(
logManager.log(LogLevel.INFO, "TestEntity", "Test message"),
).rejects.toThrow(Error);
});
it("should log error message", async () => { it("should log error message", async () => {
const error = new Error("Test error"); const error = new Error("Test error");
await logManager.logError(LogLevel.ERROR, "TestEntity", error); await logManager.logError(LogLevel.ERROR, "TestEntity", error);