Skip to content

Commit 520a2c7

Browse files
nrissclaude
andcommitted
use fhir-package-installer to pre-load FHIR packages in Docker image
Replace manual curl/tar approach with the fhir-package-installer library which handles correct ~/.fhir/packages/<id>#<version>/ storage, latest version resolution, and rate limiting automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 95aa7bd commit 520a2c7

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

Dockerfile

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,12 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
4848

4949
RUN java -version && node --version && sushi --version && jekyll --version && dot -V && python3 --version
5050

51-
# Pré-chargement du cache FHIR depuis fhir-packages.txt
52-
# Chaque package est stocké sous /root/.fhir/packages/<id>#<version>/
53-
COPY fhir-packages.txt /tmp/fhir-packages.txt
54-
RUN while IFS=' ' read -r pkg_id pkg_ver || [ -n "$pkg_id" ]; do \
55-
case "$pkg_id" in ''|\#*) continue ;; esac; \
56-
if [ "$pkg_ver" = "latest" ]; then \
57-
pkg_ver=$(curl -s "https://packages2.fhir.org/packages/${pkg_id}" | \
58-
python3 -c " \
59-
import sys, json, re; \
60-
d = json.load(sys.stdin); \
61-
versions = list(d.get('versions', {}).keys()); \
62-
stable = [v for v in versions if re.match(r'^\d+\.\d+\.\d+$', v)]; \
63-
print(stable[-1] if stable else versions[-1]) \
64-
"); \
65-
fi; \
66-
echo "Downloading ${pkg_id}#${pkg_ver} ..."; \
67-
mkdir -p /root/.fhir/packages/${pkg_id}\#${pkg_ver}; \
68-
curl -sL "https://packages2.fhir.org/packages/${pkg_id}/${pkg_ver}" \
69-
| tar -xz -C /root/.fhir/packages/${pkg_id}\#${pkg_ver}; \
70-
echo " -> OK"; \
71-
done < /tmp/fhir-packages.txt
51+
# Pré-chargement du cache FHIR via fhir-package-installer
52+
# Installe les packages listés dans fhir-packages.txt dans /root/.fhir/packages/
53+
WORKDIR /opt/fhir-setup
54+
RUN npm init -y && npm install fhir-package-installer
55+
COPY scripts/install-fhir-packages.mjs .
56+
COPY fhir-packages.txt .
57+
RUN node install-fhir-packages.mjs fhir-packages.txt
7258

7359
WORKDIR /workspace

scripts/install-fhir-packages.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fpi from 'fhir-package-installer';
2+
import { readFileSync } from 'fs';
3+
4+
const lines = readFileSync(process.argv[2] || 'fhir-packages.txt', 'utf8').split('\n');
5+
6+
for (const line of lines) {
7+
const trimmed = line.trim();
8+
if (!trimmed || trimmed.startsWith('#')) continue;
9+
const [id, version = 'latest'] = trimmed.split(/\s+/);
10+
const packageId = version === 'latest' ? id : `${id}@${version}`;
11+
console.log(`Installing ${packageId}...`);
12+
await fpi.install(packageId);
13+
}

0 commit comments

Comments
 (0)