From c5d00b4766d7afed0440460e819192f8a853d442 Mon Sep 17 00:00:00 2001 From: DecDuck Date: Mon, 4 Nov 2024 20:50:35 +1100 Subject: [PATCH] docker based deployment --- .dockerignore | 26 ++++++++++++++++++++++++++ .gitignore | 7 ++++++- Dockerfile | 27 +++++++++++++++++++++++++++ build/launch.sh | 7 +++++++ deploy-template/compose.yml | 27 +++++++++++++++++++++++++++ dev-tools/compose.yml | 14 +------------- server/plugins/app-setup.ts | 4 +--- 7 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 build/launch.sh create mode 100644 deploy-template/compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4abae2b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# Nuxt dev/build outputs +.output +.data +.nuxt +.nitro +.cache +dist + +# Node dependencies +node_modules + +# Logs +logs +*.log + +# Misc +.DS_Store +.fleet +.idea + +# Local env files +.env +.env.* +!.env.example + +.data diff --git a/.gitignore b/.gitignore index 223b7fb..7729035 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,10 @@ logs .env.* !.env.example - .data + + +# deploy template +deploy-template/* + +!deploy-template/compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..07e0507 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# pull pre-configured and updated build environment +FROM registry.deepcore.dev/drop-oss/drop-server-build-environment/main:latest AS build-system + +# setup workdir +RUN mkdir /build +WORKDIR /build + +# install dependencies and build +COPY . . +RUN yarn install +RUN yarn build + +# create run environment for Drop +FROM node:lts-slim AS run-system + +RUN mkdir /app +WORKDIR /app + +COPY --from=build-system /build/.output ./app +COPY --from=build-system /build/prisma ./prisma +COPY --from=build-system /build/build ./startup + +# OpenSSL as a dependency for Drop (TODO: seperate build environment) +RUN apt-get update -y && apt-get install -y openssl +RUN yarn global add prisma + +CMD ["/app/startup/launch.sh"] \ No newline at end of file diff --git a/build/launch.sh b/build/launch.sh new file mode 100755 index 0000000..2a7166d --- /dev/null +++ b/build/launch.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# This file starts up the Drop server by running migrations and then starting the executable +prisma migrate deploy + +# Actually start the application +node /app/app/server/index.mjs \ No newline at end of file diff --git a/deploy-template/compose.yml b/deploy-template/compose.yml new file mode 100644 index 0000000..66eb451 --- /dev/null +++ b/deploy-template/compose.yml @@ -0,0 +1,27 @@ +services: + postgres: + image: postgres:14-alpine + user: "1000:1000" + ports: + - 5432:5432 + volumes: + - ./db:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=drop + - POSTGRES_USER=drop + - POSTGRES_DB=drop + drop: + image: drop # todo + user: "1000:1000" + ports: + - 3000:3000 + volumes: + - ./library:/library + - ./certs:/certs + - ./objects:/objects + environment: + - DATABASE_URL=postgres://drop:drop@postgres:5432/drop + - FS_BACKEND_PATH=/objects + - CLIENT_CERTIFICATES=/certs + - LIBRARY=/library + - GIANT_BOMB_API_KEY=REPLACE_WITH_YOUR_KEY diff --git a/dev-tools/compose.yml b/dev-tools/compose.yml index bd37f6e..a73ce86 100644 --- a/dev-tools/compose.yml +++ b/dev-tools/compose.yml @@ -9,16 +9,4 @@ services: environment: - POSTGRES_PASSWORD=drop - POSTGRES_USER=drop - - POSTGRES_DB=drop - minio: - # honestly no idea where this image comes from - image: quay.io/minio/minio - ports: - - 9000:9000 - - 9001:9001 - volumes: - - ../.data/s3:/data - environment: - - MINIO_ROOT_USER=drop - - MINIO_ROOT_PASSWORD=drop - command: server /data --console-address ":9001" + - POSTGRES_DB=drop \ No newline at end of file diff --git a/server/plugins/app-setup.ts b/server/plugins/app-setup.ts index f11e6de..6bfa3ff 100644 --- a/server/plugins/app-setup.ts +++ b/server/plugins/app-setup.ts @@ -1,6 +1,4 @@ -import { - applicationSettings, -} from "../internal/config/application-configuration"; +import { applicationSettings } from "../internal/config/application-configuration"; import prisma from "../internal/db/database"; export default defineNitroPlugin(async (nitro) => {