Browse Source

Migrate to Deno for Docker deployment

master
buttercat1791 1 year ago
parent
commit
905a03560a
  1. 5
      .gitignore
  2. 42
      Dockerfile.local
  3. 15
      Dockerfile.next
  4. 50
      Dockerfile.prod
  5. 7
      deno.json
  6. 2905
      deno.lock
  7. 18
      import_map.json
  8. 11
      svelte.config.js

5
.gitignore vendored

@ -13,3 +13,8 @@ package-lock.json @@ -13,3 +13,8 @@ package-lock.json
# tests
/tests/e2e/html-report/*.html
/tests/e2e/test-results/*.last-run.json
# Deno
/.deno/
/deno_dir/
/import_map.lock.json

42
Dockerfile.local

@ -1,35 +1,15 @@ @@ -1,35 +1,15 @@
# Dockerfile for production deployments of Alexandria.
# Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker.
# Use the official Bun image
FROM oven/bun:1.2-alpine AS base
WORKDIR /usr/src/app
# Install dependencies into a temp directory.
# This will cache them and speed up future builds.
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json /temp/dev/
RUN cd /temp/dev && bun install
# Copy node_modules from temp directory.
# Then copy all (non-ignored) project files into the image.
FROM base AS prerelease
ENV NODE_ENV=production
COPY --from=install /temp/dev/node_modules node_modules
FROM denoland/deno:alpine AS build
WORKDIR /app/src
COPY . .
RUN deno install
RUN deno task build
# Run tests and build.
# RUN bun --bun run test # Uncomment when tests are ready.
RUN bun --bun run build
FROM denoland/deno:alpine AS release
WORKDIR /app
COPY --from=build /app/src/build/ ./build/
COPY --from=build /app/src/import_map.json .
# Copy production dependencies and source code into final image.
FROM base AS release
ENV HOST=0.0.0.0
ENV ORIGIN=http://localhost:3040
COPY --from=prerelease /usr/src/app/build .
ENV ORIGIN=http://localhost:3000
# Run the app.
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "start" ]
EXPOSE 3000
CMD [ "deno", "run", "--allow-env", "--allow-read", "--allow-net", "--import-map=import_map.json", "./build/index.js" ]

15
Dockerfile.next

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
FROM denoland/deno:alpine AS build
WORKDIR /app/src
COPY . .
RUN deno install
RUN deno task build
FROM denoland/deno:alpine AS release
WORKDIR /app
COPY --from=build /app/src/build/ ./build/
COPY --from=build /app/src/import_map.json .
ENV ORIGIN=https://next-alexandria.gitcitadel.eu
EXPOSE 3000
CMD [ "deno", "run", "--allow-env", "--allow-read", "--allow-net", "--import-map=import_map.json", "./build/index.js" ]

50
Dockerfile.prod

@ -1,43 +1,15 @@ @@ -1,43 +1,15 @@
# Dockerfile for production deployments of Alexandria.
# Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker.
# Use the official Bun image
FROM oven/bun:1 AS base
WORKDIR /usr/src/app
# 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
FROM denoland/deno:alpine AS build
WORKDIR /app/src
COPY . .
RUN deno install
RUN deno task build
# [Optional] Tests & build.
ENV NODE_ENV=production
ENV ALEX_HOST=127.0.0.1
ENV ALEX_PORT=3040
ENV ALEX_ORIGIN=https://alexandria.gitcitadel.eu
RUN bun test
RUN bun run build
FROM denoland/deno:alpine AS release
WORKDIR /app
COPY --from=build /app/src/build/ ./build/
COPY --from=build /app/src/import_map.json .
# 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/index.ts .
COPY --from=prerelease /usr/src/app/package.json .
ENV ORIGIN=https://alexandria.gitcitadel.eu
# Run the app.
USER bun
EXPOSE 3040/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]
EXPOSE 3000
CMD [ "deno", "run", "--allow-env", "--allow-read", "--allow-net", "--import-map=import_map.json", "./build/index.js" ]

7
deno.json

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
{
"importMap": "./import_map.json",
"compilerOptions": {
"allowJs": true,
"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]
}
}

2905
deno.lock

File diff suppressed because it is too large Load Diff

18
import_map.json

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
{
"imports": {
"he": "npm:he@1.2.x",
"@nostr-dev-kit/ndk": "npm:@nostr-dev-kit/ndk@2.11.x",
"@nostr-dev-kit/ndk-cache-dexie": "npm:@nostr-dev-kit/ndk-cache-dexie@2.5.x",
"@popperjs/core": "npm:@popperjs/core@2.11.x",
"@tailwindcss/forms": "npm:@tailwindcss/forms@0.5.x",
"@tailwindcss/typography": "npm:@tailwindcss/typography@0.5.x",
"asciidoctor": "npm:asciidoctor@3.0.x",
"d3": "npm:d3@7.9.x",
"nostr-tools": "npm:nostr-tools@2.10.x",
"tailwind-merge": "npm:tailwind-merge@2.5.x",
"svelte": "npm:svelte@5.0.x",
"flowbite": "npm:flowbite@2.2.x",
"flowbite-svelte": "npm:flowbite-svelte@0.44.x",
"flowbite-svelte-icons": "npm:flowbite-svelte-icons@2.0.x"
}
}

11
svelte.config.js

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import adapter from "svelte-adapter-bun";
import adapter from "@sveltejs/adapter-node";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
/** @type {import('@sveltejs/kit').Config} */
@ -8,13 +8,8 @@ const config = { @@ -8,13 +8,8 @@ const config = {
preprocess: [vitePreprocess()],
kit: {
// Bun adapter
adapter: adapter({
out: "build",
assets: true,
development: false,
precompress: false,
}),
// Deno adapter
adapter: adapter(),
alias: {
$lib: "src/lib",
$components: "src/lib/components",

Loading…
Cancel
Save