Commit 77c13ecb authored by Grant's avatar Grant
Browse files

docker deploy

parent ff63fdf5
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+17 −0
Original line number Diff line number Diff line
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
doc
data
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -36,3 +36,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dynamicly generated files
src/types/openapi.d.ts
/src/generated/prisma
/data
 No newline at end of file

Dockerfile

0 → 100644
+43 −0
Original line number Diff line number Diff line
FROM oven/bun:latest AS base
WORKDIR /usr/src/app
RUN apt-get update -y && apt-get install -y openssl

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lock /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production
# RUN bun test
RUN bunx prisma generate
RUN bun run dev:api-ts
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release

COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/src/generated ./src/generated
COPY --from=prerelease /usr/src/app/dist ./dist
COPY --from=prerelease /usr/src/app/package.json .

ENV PORT=3000

# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "./dist/index.js" ]
 No newline at end of file

docker-compose.yml

0 → 100644
+23 −0
Original line number Diff line number Diff line
services:
  api:
    image: sc07/fediverse.events-api
    build: .
    ports:
      - "3001:3000"
    environment:
      - DATABASE_URL=postgres://postgres@postgres:5432/fedievents-api
    env_file:
      - .env
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    restart: always
    image: postgres:14-alpine
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
  },
  "scripts": {
    "dev": "bun run --hot src/index.ts",
    "build": "bun build src/index.ts --outdir ./dist --target=bun --sourcemap=inline --minify --packages=external",
    "bundle:api-doc": "redocly bundle openapi/spec.yml -o openapi/openapi.yaml && sed -i '1s/^/# AUTOGENERATED FILE\\n# Run bunx bundle:api-doc\\n/' openapi/openapi.yaml",
    "build:api-doc": "redocly build-docs openapi/spec.yml -o public/index.html --title \"Fediverse Events API\"",
    "dev:api-doc": "redocly preview-docs openapi/spec.yml",