Skip to content

Commit

Permalink
Link static files instead of copying them (gbv/coli-conc-server#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Nov 4, 2024
1 parent 81fef30 commit f3022a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ["/bin/bash", "-c"]

RUN apt update
# Install dependencies
RUN apt install -y curl git wget unzip jq task-spooler rsync
RUN apt install -y curl git wget unzip jq task-spooler
# Install dependencies for building manual
RUN apt install -y pandoc make
# Install fnm for managing Node.js versions
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ docker compose exec cocoda bash setup.sh

### Custom Instances

You can also specify custom Cocoda configurations as `{instance-name}.json` or `{instance-name}/cocoda.json` in the container's `/configs` directory. These will be built in addition to the defined `TAGS`. Custom configurations will use branch `master` by default; a different branch for a particular instance can be specific inside its configuration file as `_branch`. If the latter format is used, all other files (except `cocoda.json`) will be copied into the target build folder (e.g. for logo files).
You can also specify custom Cocoda configurations as `{instance-name}.json` or `{instance-name}/cocoda.json` in the container's `/configs` directory. These will be built in addition to the defined `TAGS`. Custom configurations will use branch `master` by default; a different branch for a particular instance can be specific inside its configuration file as `_branch`. If the latter format is used, all other files (except `cocoda.json`) will be linked into the target build folder (e.g. for logo files). **Note** that static files given in the configuration folder will overwrite files in the build!

## Maintainers

Expand Down
37 changes: 28 additions & 9 deletions setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,37 @@ for (const tag of tags) {

for (const { name, directory, configFile, branch } of instances) {
console.log(`Cocoda Instance: ${name} (branch/tag: ${branch}, config: ${configFile ?? "none"})`)

async function relinkStaticFiles() {
if (directory) {
console.log("- relinking static files...")
// Link static files into root path if configuration is in a directory and includes static files
// Note that `cocoda.json` is one of these files and doesn't need special handling.
const files = await glob([`${directory}/**/*`])
for (const file of files) {
const source = file, target = path.join(targetFolder, name, path.relative(directory, file))
if (await fs.pathExists(target)) {
await $`rm ${target}`
}
await $`ln -s ${source} ${target}`
}
} else if (configFile) {
// Link config file only
console.log("- relinking config file...")
const target = path.join(targetFolder, name, "cocoda.json")
if (await fs.pathExists(target)) {
await $`rm ${target}`
}
await $`ln -s ${configFile} ${target}`
}
}

try {
if (await fs.pathExists(`${targetFolder}/${name}`)) {
// No updates for non-branches
if (branch.match(/^\d/)) {
console.log("- instance already built and no updates necessary")
await relinkStaticFiles()
continue
}

Expand All @@ -92,6 +118,7 @@ for (const { name, directory, configFile, branch } of instances) {

if (currentCommit === buildCommit) {
console.log("- instance already built and no updates necessary")
await relinkStaticFiles()
continue
}

Expand All @@ -104,15 +131,7 @@ for (const { name, directory, configFile, branch } of instances) {
await $`rm -r ${targetFolder}/${name}`
}
await $`mv releases/${branch} ${targetFolder}/${name}`
// Link config file if needed
if (configFile) {
await $`rm ${targetFolder}/${name}/cocoda.json`
await $`ln -s ${configFile} ${targetFolder}/${name}/cocoda.json`
}
// Copy static files into root path if necessary
if (directory) {
await $`rsync -a ${directory}/* ${targetFolder}/${name} --exclude=cocoda.json`
}
await relinkStaticFiles()
console.log(`- Successfully built instance ${name}!`)
} catch (error) {
console.error(`- Error building instance ${name}: ${error}`)
Expand Down

0 comments on commit f3022a3

Please sign in to comment.