Skip to content

Commit

Permalink
Use HOMEPAGE_BUILDTIME to revalidate container restart/recreate
Browse files Browse the repository at this point in the history
  • Loading branch information
shamoon committed Apr 5, 2023
1 parent a42c50f commit 6701e3b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ COPY . .

SHELL ["/bin/ash", "-xeo", "pipefail", "-c"]
RUN npm run telemetry \
&& mkdir config && echo '---' > config/settings.yaml \
&& mkdir config \
&& NEXT_PUBLIC_BUILDTIME=$BUILDTIME NEXT_PUBLIC_VERSION=$VERSION NEXT_PUBLIC_REVISION=$REVISION npm run build

# Production image, copy all the files and run next
Expand Down
2 changes: 2 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export PGID=${PGID:-0}
# while also supporting the lscr.io /config directory
[ ! -d "/app/config" ] && ln -s /config /app/config

export HOMEPAGE_BUILDTIME=$(date +%s)

# Set privileges for /app but only if pid 1 user is root and we are dropping privileges.
# If container is run as an unprivileged user, it means owner already handled ownership setup on their own.
# Running chown in that case (as non-root) will cause error
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default async function handler(req, res) {
return hash(readFileSync(configYaml, "utf8"));
});

// this ties hash to specific build which should force revaliation between versions
const buildTime = process.env.NEXT_PUBLIC_BUILDTIME?.length ? process.env.NEXT_PUBLIC_BUILDTIME : '';
// set to date by docker entrypoint, will force revalidation between restarts/recreates
const buildTime = process.env.HOMEPAGE_BUILDTIME?.length ? process.env.HOMEPAGE_BUILDTIME : '';

const combinedHash = hash(hashes.join("") + buildTime);

Expand Down
12 changes: 6 additions & 6 deletions src/utils/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { join } from "path";
import { existsSync, copyFile, readFileSync } from "fs";
import { existsSync, readFileSync, copyFileSync } from "fs";

import cache from "memory-cache";
import yaml from "js-yaml";
Expand All @@ -13,13 +13,13 @@ export default function checkAndCopyConfig(config) {
const configYaml = join(process.cwd(), "config", config);
if (!existsSync(configYaml)) {
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
copyFile(configSkeleton, configYaml, (err) => {
if (err) {
try {
copyFileSync(configSkeleton, configYaml)
console.info("%s was copied to the config folder", config);
} catch (err) {
console.error("error copying config", err);
throw err;
}
console.info("%s was copied to the config folder", config);
});
}

return true;
}
Expand Down

0 comments on commit 6701e3b

Please sign in to comment.