diff --git a/.prettierignore b/.prettierignore index 004c815f..e9ba8f6a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ src/shared/translations lemmy-translations src/assets/css/themes/*.css stats.json +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2b36581d..66a0adda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ COPY src src COPY .git .git # Set UI version -RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts" +RUN echo "export const VERSION = '$(git describe --tag)'; export const COMMIT_HASH = '$(git rev-parse HEAD)';" > "src/shared/version.ts" RUN yarn --production --prefer-offline RUN yarn build:prod diff --git a/dev.dockerfile b/dev.dockerfile index 3bfc10da..e446ba80 100644 --- a/dev.dockerfile +++ b/dev.dockerfile @@ -18,11 +18,13 @@ COPY generate_translations.js \ .babelrc \ ./ + COPY lemmy-translations lemmy-translations COPY src src +COPY .git .git # Set UI version -RUN echo "export const VERSION = 'dev';" > "src/shared/version.ts" +RUN echo "export const VERSION = 'dev'; export const COMMIT_HASH = '$(git rev-parse HEAD)';" > "src/shared/version.ts" RUN yarn --prefer-offline RUN yarn build:dev diff --git a/src/server/index.tsx b/src/server/index.tsx index aed8bca7..5dd83031 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -2,6 +2,7 @@ import { setupDateFns } from "@utils/app"; import express from "express"; import path from "path"; import process from "process"; +import { COMMIT_HASH } from "../shared/version"; import CatchAllHandler from "./handlers/catch-all-handler"; import ManifestHandler from "./handlers/manifest-handler"; import RobotsHandler from "./handlers/robots-handler"; @@ -18,7 +19,7 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"] server.use(express.json()); server.use(express.urlencoded({ extended: false })); -server.use("/static", express.static(path.resolve("./dist"))); +server.use(`/static-${COMMIT_HASH}`, express.static(path.resolve("./dist"))); server.use(setCacheControl); if (!process.env["LEMMY_UI_DISABLE_CSP"] && !process.env["LEMMY_UI_DEBUG"]) { diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index 13775981..d77df26a 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -4,6 +4,7 @@ import serialize from "serialize-javascript"; import sharp from "sharp"; import { favIconPngUrl, favIconUrl } from "../../shared/config"; import { ILemmyConfig, IsoDataOptionalSite } from "../../shared/interfaces"; +import { COMMIT_HASH } from "../../shared/version"; import { buildThemeList } from "./build-themes-list"; import { fetchIconPng } from "./fetch-icon-png"; @@ -87,7 +88,7 @@ export async function createSsrHtml( - + ${helmet.link.toString() || fallbackTheme} @@ -102,7 +103,7 @@ export async function createSsrHtml(
${root}
- + `; diff --git a/src/shared/components/common/icon.tsx b/src/shared/components/common/icon.tsx index 5b6ddf81..7060e9c9 100644 --- a/src/shared/components/common/icon.tsx +++ b/src/shared/components/common/icon.tsx @@ -1,5 +1,6 @@ import classNames from "classnames"; import { Component } from "inferno"; +import { COMMIT_HASH } from "../../../shared/version"; import { I18NextService } from "../../services"; interface IconProps { @@ -23,7 +24,7 @@ export class Icon extends Component { })} >
{this.props.icon} diff --git a/src/shared/components/person/person-listing.tsx b/src/shared/components/person/person-listing.tsx index 6631a8ea..a8fc0dae 100644 --- a/src/shared/components/person/person-listing.tsx +++ b/src/shared/components/person/person-listing.tsx @@ -4,6 +4,7 @@ import classNames from "classnames"; import { Component } from "inferno"; import { Link } from "inferno-router"; import { Person } from "lemmy-js-client"; +import { COMMIT_HASH } from "../../../shared/version"; import { relTags } from "../../config"; import { PictrsImage } from "../common/pictrs-image"; import { CakeDay } from "./cake-day"; @@ -88,7 +89,9 @@ export class PersonListing extends Component { !this.props.person.banned && showAvatars() && ( )} diff --git a/src/shared/config.ts b/src/shared/config.ts index 97b28d25..6b0a190d 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -1,5 +1,7 @@ -export const favIconUrl = "/static/assets/icons/favicon.svg"; -export const favIconPngUrl = "/static/assets/icons/apple-touch-icon.png"; +import { COMMIT_HASH } from "./version"; + +export const favIconUrl = `/static-${COMMIT_HASH}/assets/icons/favicon.svg`; +export const favIconPngUrl = `/static-${COMMIT_HASH}/assets/icons/apple-touch-icon.png`; export const repoUrl = "https://github.com/LemmyNet"; export const joinLemmyUrl = "https://join-lemmy.org"; diff --git a/src/shared/version.ts b/src/shared/version.ts index c1dba35e..a799956b 100644 --- a/src/shared/version.ts +++ b/src/shared/version.ts @@ -1 +1,2 @@ export const VERSION = "unknown version"; +export const COMMIT_HASH = "unknown hash"; diff --git a/webpack.config.js b/webpack.config.js index 4d95a80c..268d9eca 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,6 +14,11 @@ const banner = ` @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 `; +const commitHash = require("child_process") + .execSync("git rev-parse HEAD") + .toString() + .trim(); + const base = { output: { filename: "js/server.js", @@ -96,6 +101,7 @@ const createClientConfig = (_env, mode) => { entry: "./src/client/index.tsx", output: { filename: "js/client.js", + publicPath: `/static-${commitHash}`, }, plugins: [ ...base.plugins, @@ -103,7 +109,7 @@ const createClientConfig = (_env, mode) => { enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct workbox: { modifyURLPrefix: { - "/": "/static/", + "/": `/static-${commitHash}/`, }, cacheId: "lemmy", include: [/(assets|styles)\/.+\..+|client\.js$/g],