Skip to content

Commit

Permalink
Add update script to Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Feb 26, 2024
1 parent 4b40e20 commit acf12f0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt install -y nodejs
# Deno
RUN apt install -y unzip
RUN curl -fsSL https://deno.land/install.sh | sh
RUN ln -s /root/.deno/bin/deno /usr/bin/deno

# Dependencies for specific vocabularies
## nkostypes
Expand All @@ -30,5 +31,9 @@ RUN npm install -g wikibase-cli@latest

# Make Docker-related scripts available in root folder
COPY .docker/*.sh .
COPY .docker/*.ts .

# Cache Deno dependencies for update script
RUN deno cache --reload --lock=deno.lock update.ts

CMD ["bash", "entrypoint.sh"]
10 changes: 9 additions & 1 deletion .docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This container aims to offer all the tools and dependencies needed to build voca

## To-Dos
- [ ] Test all vocabularies
- [ ] Add script that updates repo and rebuilds vocabularies where files were changed
- [x] Add script that updates repo and rebuilds vocabularies where files were changed
- [ ] Deal with modified files in the repo
- [ ] Error with `nkostypes`
- [ ] Error with `ssg`
- [ ] `rvk`:
Expand Down Expand Up @@ -38,6 +39,13 @@ To run an interactive shell:
docker compose run -it jskos-data bash
```

## Update Data and Rebuild Vocabularies
There is a script provided in the Docker container that updates the repository and rebuilds all vocabularies where files were changed.

```sh
docker compose run -it jskos-data /usr/src/app/update.ts
```

## Publishing the Docker Image

Currently, only the `master` branch will be published by the GitHub workflow, and only whenever Docker-related files (`Dockerfile`, `entrypoint.sh`) are changed.
40 changes: 40 additions & 0 deletions .docker/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env -S deno run --allow-read --allow-run --allow-env --allow-sys --ext=ts --lock=/usr/src/app/deno.lock

import { $, cd } from "npm:zx@7"

console.log("##########", new Date(), "Updating jskos-data repository...", "##########")

const basePath = "/jskos-data"
await cd(basePath)

// Determine updated files before pulling
const updatedFiles = (await $`git fetch --quiet && git diff --name-only @ @{u}`.quiet()).stdout.split("\n").filter(file => file && !file.startsWith("."))

// TODO: Building vocabularies can modify files inside the repo, so we either need to reset it or possibly stash the changes

// Update repo
await $`git pull`
console.log()

if (updatedFiles.includes("package-lock.json")) {
console.log("### package-lock.json was updated, reinstalling Node.js dependencies... ###")
await $`npm ci`
console.log()
}

const builtVocabularies = new Set()
for (const file of updatedFiles) {
const vocabulary = file.match(/^(.*)\//)?.[1]
if (!vocabulary || builtVocabularies.has(vocabulary)) {
continue
}
console.log(`##### ${vocabulary} was updated, rebuilding files... #####\n`)
try {
await cd(`${basePath}/${vocabulary}`)
await $`make -B`
} catch (error) {
console.error(`There was an error rebuilding ${vocabulary}:`, error)
}
console.log()
builtVocabularies.add(vocabulary)
}
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- .docker/Dockerfile
- .docker/entrypoint.sh
- .docker/update.ts

# Adapted from:
# - https://github.com/docker/metadata-action#semver
Expand Down

0 comments on commit acf12f0

Please sign in to comment.