-
-
Notifications
You must be signed in to change notification settings - Fork 4
Fixes and improvements #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3061d29
53066b2
0b150ad
bb634d3
17db276
e0725c0
a4e243a
9119627
bc1fb01
cecee4b
f57a017
e460bb1
19e58c8
2ce1773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,9 @@ pnpm-debug.log* | |
.DS_Store | ||
|
||
build/cache/ | ||
public/ | ||
|
||
public/* | ||
!public/.gitkeep | ||
|
||
slim.report.json | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
FROM node:21 AS builder | ||
FROM node:22-slim AS base | ||
WORKDIR /app | ||
COPY package.json package-lock.json ./ | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get update && apt-get install -y --no-install-recommends python3-minimal && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
FROM base AS prod-deps | ||
RUN npm ci --omit=dev | ||
# Remove a bunch of unnecessary stuff to slim down the image | ||
RUN rm -rf \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other option is doing what I did originally, which was installing only specifically the packages we needed to run the app. Maybe I'll compare the total size, but this solution takes our runtime Best solution might be a combination of both. Install only what we need, and then delete any extra dependencies that get added that we simply won't use. |
||
/app/node_modules/@astrojs/cloudflare \ | ||
/app/node_modules/typescript \ | ||
/app/node_modules/@shikijs \ | ||
/app/node_modules/@esbuild \ | ||
/app/node_modules/@cloudflare \ | ||
/app/node_modules/fontkit \ | ||
/app/node_modules/@babel \ | ||
/app/node_modules/prismjs \ | ||
/app/node_modules/shiki \ | ||
/app/node_modules/rollup \ | ||
/app/node_modules/vite \ | ||
/app/node_modules/@types \ | ||
/app/node_modules/terser \ | ||
/app/node_modules/@rollup \ | ||
/app/node_modules/esbuild \ | ||
/app/node_modules/sharp \ | ||
/app/node_modules/@img \ | ||
/app/node_modules/astro | ||
|
||
COPY package.json /app | ||
COPY package-lock.json /app | ||
COPY node_modules /app/node_modules | ||
RUN npm install | ||
|
||
COPY ./build /app/build | ||
COPY ./public /app/public | ||
COPY astro.config.mjs . | ||
COPY tsconfig.json /app/tsconfig.json | ||
COPY src /app/src | ||
FROM base AS build-deps | ||
RUN npm ci | ||
|
||
|
||
FROM build-deps AS builder | ||
COPY astro.config.mjs tsconfig.json ./ | ||
COPY .astro ./ | ||
COPY src ./src | ||
COPY build ./build | ||
COPY public ./public | ||
ENV BUILD_ENV=docker | ||
RUN npm run build | ||
RUN npm run astrobuild | ||
|
||
FROM node:21-alpine | ||
WORKDIR /app | ||
COPY --from=builder /app/dist /app/dist | ||
|
||
# Final Image | ||
FROM gcr.io/distroless/nodejs22-debian12 AS final | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Way smaller base image - it has exactly enough to run We could probably look at I played around with making the site entirely static inside Docker, but:
|
||
WORKDIR /app | ||
COPY --from=prod-deps /app/node_modules ./node_modules | ||
COPY --from=builder /app/dist ./dist | ||
ENV NODE_ENV=production | ||
ENV HOST=0.0.0.0 | ||
ENV PORT=4321 | ||
ENV NODE_ENV=production | ||
RUN npm i cookie kleur clsx cssesc server-destroy send path-to-regexp@6.2.1 html-escaper | ||
RUN du -sh /app/node_modules | ||
CMD ["node", "/app/dist/server/entry.mjs"] | ||
EXPOSE 4321 | ||
|
||
CMD ["/app/dist/server/entry.mjs"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import { defineConfig } from "astro/config"; | ||
|
||
import node from '@astrojs/node'; | ||
import node from "@astrojs/node"; | ||
import cloudflare from "@astrojs/cloudflare"; | ||
|
||
const buildEnv = process.env.BUILD_ENV; | ||
|
@@ -11,38 +11,19 @@ const buildConfig = { split: true }; | |
if (buildEnv === "production") { | ||
console.log("Building for Cloudflare adapter"); | ||
adapter = cloudflare({ | ||
mode: "advanced", | ||
routes: { | ||
strategy: "include", | ||
include: ["/*"], | ||
exclude: [ | ||
"/content/*", | ||
"/script.js", | ||
"/search_index.json", | ||
"/~pagelist.json", | ||
"/styles/gmod.css", | ||
"/wiki/files/*", | ||
"/rubat/*", | ||
"/lewis/*", | ||
"/garry/*", | ||
"/fonts/*", | ||
"/*.webp", | ||
"/cdn-cgi/*", | ||
"/last_build.txt", | ||
] | ||
} | ||
imageService: "passthrough", | ||
Comment on lines
13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After updating astro + asrojs/cloudflare, it seems like the default behavior is correct for us, which is nice.
It could be cool to use astro+cloudflare's built-in solution for progressive image loading (automatically generates multiple copies of the same image in different resolutions and then progressively loads them) but I don't feel like it's slow enough right now to start relying on Cloudflare's image service. We could actually do this ourselves, at the cost of a larger final bundle size. (We'd skip it for the docker environment). We would probably need to:
Could be a cool enhancement some day |
||
}); | ||
} else { | ||
console.log("Building for Node adapter"); | ||
adapter = node({ mode: "standalone" }); | ||
|
||
buildConfig.rollupOptions = { | ||
external: ["fs", "node:fs", "path", "node:path"] | ||
} | ||
external: ["fs", "node:fs", "path", "node:path"], | ||
}; | ||
} | ||
|
||
export default defineConfig({ | ||
build: buildConfig, | ||
output: "server", | ||
adapter: adapter | ||
adapter: adapter, | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some new static realm assets - right now we're using them in our But hosting them means other people could use them for whatever, too 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> | ||
<ShortName>GMod Wiki Mirror</ShortName> | ||
<Description>A reliable and fast Mirror of the official Garry's Mod Lua Wiki, with delightful improvements aimed at developers</Description> | ||
<InputEncoding>UTF-8</InputEncoding> | ||
<Tags>wiki games game gmod garrys mod glua lua api</Tags> | ||
|
||
<Image width="16" height="16" type="image/png">https://gmodwiki.com/garry/822e60dc-c931-43e4-800f-cbe010b3d4cc.png</Image> | ||
<Image width="32" height="32" type="image/png">https://gmodwiki.com/garry/822e60dc-c931-43e4-800f-cbe010b3d4cc.png</Image> | ||
|
||
<Url method="get" rel="results" type="text/html" template="https://gmodwiki.com/websearch?query={searchTerms}"/> | ||
|
||
<Url type="application/opensearchdescription+xml" rel="self" template="https://gmodwiki.com/~searchmanifest"/> | ||
</OpenSearchDescription> | ||
Comment on lines
+1
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw that the FP wiki has this file. I don't quite understand what it does or how it's supposed to be formatted (very little info about it, wasn't about to read the entire RFC for the feature) but figured we could try having our own copy. Might have something to do with adding the site as a "search engine" in the browser? |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was being treated as a fragment (something that we'd modify and then programmatically put in |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const logo = "/garry/822e60dc-c931-43e4-800f-cbe010b3d4cc.webp"; | ||
|
||
const ogLogo = `${Astro.url.protocol}//${Astro.url.host}${logo}`; | ||
const fullUrl = `${Astro.url.protocol}//${Astro.url.host}${Astro.url.pathname}`; | ||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets plopped into the frontmatter of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separating the stages out into
build-deps
andprod-deps
means we download+store the packages twice, but we don't have to redo the packages every time we make a change to any other file that weCOPY
- faster dev