changed to docker compose build
Unit Tests with docker compose / unit-test (push) Successful in 33s Details
Unit Tests with docker compose / unit-test (pull_request) Successful in 22s Details

This commit is contained in:
Alie 2024-04-20 12:39:35 +02:00
parent 971905f138
commit 54cc8c106d
7 changed files with 25 additions and 36 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
node_modules/ node_modules/
bun.lockb
.vscode .vscode
.env .env
.editorconfig .editorconfig

View File

@ -1,31 +1,16 @@
# Dockerfile
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base FROM oven/bun:1 as base
WORKDIR /usr/src/app WORKDIR /usr/src/app
# Generate new bun lock
FROM base as lock
RUN mkdir -p /temp/lock
COPY package.json /temp/lock
RUN cd /temp/lock && bun install
# install dependencies into temp folder
# this will cache them and speed up future builds
FROM base AS install FROM base AS install
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod RUN mkdir -p /temp/prod
COPY --from=lock /temp/lock/package.json /temp/lock/bun.lockb /temp/prod/ COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --production --frozen-lockfile RUN cd /temp/prod && bun install --production --frozen-lockfile
# Copy production dependencies and source code into final image
FROM base AS release FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules COPY --from=install /temp/prod/node_modules node_modules
COPY --from=install /temp/prod/package.json . COPY --from=install /temp/prod/package.json .
COPY ./src ./src COPY ./src ./src
# run the app
USER bun USER bun
ENV NODE_ENV production ENV NODE_ENV production
EXPOSE 8080/tcp EXPOSE 8080/tcp

19
Dockerfile.dev Normal file
View File

@ -0,0 +1,19 @@
FROM oven/bun:1 as base
WORKDIR /usr/src/app
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
FROM base AS release
COPY --from=install /temp/dev/node_modules node_modules
COPY --from=install /temp/dev/package.json .
COPY ./src ./src
COPY ./tests ./tests
USER bun
ENV NODE_ENV dev
EXPOSE 8080/tcp
ENTRYPOINT [ "/bin/bash", "-c" ]
CMD ["bun --hot run src/index.ts"]

BIN
bun.lockb Executable file

Binary file not shown.

View File

@ -12,11 +12,9 @@ services:
- mongodb_data:/data/db - mongodb_data:/data/db
bot-api: bot-api:
image: oven/bun:1 build:
dockerfile: Dockerfile.dev
container_name: bot-api container_name: bot-api
entrypoint: /bin/bash -c
command: ["bun --hot run src/index.ts"]
working_dir: /usr/src/app
ports: ports:
- "8080:8080" - "8080:8080"
depends_on: depends_on:
@ -26,8 +24,6 @@ services:
MONGODB_USER: "root" MONGODB_USER: "root"
MONGODB_PASS: "password" MONGODB_PASS: "password"
JWTSECRET: "cooljwtsecret" JWTSECRET: "cooljwtsecret"
volumes:
- ./:/usr/src/app:ro
volumes: volumes:
mongodb_data: mongodb_data:

View File

@ -20,9 +20,8 @@
"typescript": "^5.0.0" "typescript": "^5.0.0"
}, },
"scripts": { "scripts": {
"start": "bun run src/index.ts", "dev": "docker compose down -v && docker compose up --build",
"dev": "docker compose down -v && docker compose up", "test": "docker compose down -v && docker compose run --build bot-api 'bun test'"
"test": "docker compose down -v && docker compose run bot-api 'bun test'"
}, },
"dependencies": { "dependencies": {
"compression": "^1.7.4", "compression": "^1.7.4",

View File

@ -1,12 +1,3 @@
import { startApp } from "./app"; import { startApp } from "./app";
await startApp(); await startApp();
// This try carch is to prevent hot reload from making the process die due to coliding entries
try {
// Not insert test data into production
if (process.env.NODE_ENV != "production") {
const populateDatabase = require("../tests/populateDatabase");
await populateDatabase();
}
} catch {}