diff --git a/.gitea/workflows/01_test.yaml b/.gitea/workflows/01_test.yaml index bc53a23..f60cf17 100644 --- a/.gitea/workflows/01_test.yaml +++ b/.gitea/workflows/01_test.yaml @@ -19,4 +19,4 @@ jobs: - name: Install project dependencies run: yarn install --frozen-lockfile --ignore-scripts - name: Run docker-compose - run: docker compose down -v && docker compose run bot-api bun test \ No newline at end of file + run: docker compose down -v && docker compose run bot-api 'bun test' \ No newline at end of file diff --git a/.gitignore b/.gitignore index f16c346..6edcfa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules/ -bun.lockb .vscode .env .editorconfig diff --git a/Dockerfile b/Dockerfile index 54fd62a..2603d0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 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 -# install with --production (exclude devDependencies) 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 -# Copy production dependencies and source code into final image FROM base AS release COPY --from=install /temp/prod/node_modules node_modules COPY --from=install /temp/prod/package.json . COPY ./src ./src -# run the app USER bun ENV NODE_ENV production EXPOSE 8080/tcp diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..3b6f0f7 --- /dev/null +++ b/Dockerfile.dev @@ -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"] diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..ce7cc8f Binary files /dev/null and b/bun.lockb differ diff --git a/compose.yaml b/compose.yaml index d8bf85f..2feb6cc 100644 --- a/compose.yaml +++ b/compose.yaml @@ -12,11 +12,9 @@ services: - mongodb_data:/data/db bot-api: - image: oven/bun:1 + build: + dockerfile: Dockerfile.dev container_name: bot-api - entrypoint: /bin/bash -c - command: ["bun --hot run src/index.ts"] - working_dir: /usr/src/app ports: - "8080:8080" depends_on: @@ -26,8 +24,6 @@ services: MONGODB_USER: "root" MONGODB_PASS: "password" JWTSECRET: "cooljwtsecret" - volumes: - - ./:/usr/src/app:ro volumes: mongodb_data: diff --git a/package.json b/package.json index 4983e60..943c0a7 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,8 @@ "typescript": "^5.0.0" }, "scripts": { - "start": "bun run src/index.ts", - "dev": "docker compose down -v && docker compose up", - "test": "docker compose down -v && docker compose run bot-api 'bun test'" + "dev": "docker compose down -v && docker compose up --build", + "test": "docker compose down -v && docker compose run --build bot-api 'bun test'" }, "dependencies": { "compression": "^1.7.4", diff --git a/src/index.ts b/src/index.ts index 1fc84e5..34fbd71 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,3 @@ import { startApp } from "./app"; -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 {} +await startApp(); \ No newline at end of file