Files
FEDEO/scripts/storage/build-pilot.sh

45 lines
2.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
storage_repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
storage_output="${1:-$storage_repo/.release/storage-pilot}"
test ! -e "$storage_output"
mkdir -p "$storage_output/scripts/storage" "$storage_output/docs"
storage_weed="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["image"])' "$storage_repo/scripts/storage/seaweedfs.json")"
if ! docker image inspect "$storage_weed" >/dev/null 2>&1; then
docker build -f "$storage_repo/scripts/storage/Dockerfile.seaweedfs" -t "$storage_weed" "$storage_repo/scripts/storage"
fi
docker build -t fedeo-storage-tools:pilot "$storage_repo/scripts/storage"
storage_tools_id="$(docker image inspect fedeo-storage-tools:pilot --format '{{.Id}}')"
storage_weed_id="$(docker image inspect "$storage_weed" --format '{{.Id}}')"
storage_tools="fedeo-storage-tools:pilot-${storage_tools_id#sha256:}"
storage_weed_local="fedeo-seaweedfs:pilot-${storage_weed_id#sha256:}"
docker image tag "$storage_tools_id" "$storage_tools"
docker image tag "$storage_weed_id" "$storage_weed_local"
cp "$storage_repo/scripts/selfhost-storage-migrate.py" "$storage_repo/scripts/selfhost-update.py" "$storage_output/scripts/"
cp "$storage_repo/scripts/storage/"{s3.mjs,cli.mjs,seaweedfs.json,start-seaweedfs.sh,package.json,package-lock.json,Dockerfile.seaweedfs,preserve-s3-content-type.patch} "$storage_output/scripts/storage/"
cp "$storage_repo/scripts/storage/pilot.py" "$storage_output/pilot.py"
cp "$storage_repo/docs/minio-umstellung-pilot.md" "$storage_output/docs/"
docker image save -o "$storage_output/images.tar" "$storage_tools" "$storage_weed_local"
python3 - "$storage_output" "$storage_tools" "$storage_weed_local" "$storage_weed" <<'PY'
import hashlib,json,pathlib,sys
root=pathlib.Path(sys.argv[1]).resolve()
spec=root/'scripts/storage/seaweedfs.json'
config=json.loads(spec.read_text()); config['image']=sys.argv[3]
spec.write_text(json.dumps(config,indent=2)+'\n')
checksums={}
for p in sorted(root.rglob('*')):
if p.is_file():
h=hashlib.sha256()
with p.open('rb') as f:
for chunk in iter(lambda:f.read(1024*1024), b''): h.update(chunk)
checksums[str(p.relative_to(root))]=h.hexdigest()
upstream=next(line.split()[1] for line in (root/'scripts/storage/Dockerfile.seaweedfs').read_text().splitlines()
if line.startswith('FROM chrislusf/seaweedfs:'))
(root/'bundle.json').write_text(json.dumps({'schemaVersion':1,'toolsImage':sys.argv[2],
'seaweedImage':sys.argv[3],'upstreamSeaweedImage':upstream,'seaweedBuild':'4.47-fedeo.1',
'sha256':checksums},indent=2)+'\n')
PY
tar -czf "$storage_output.tar.gz" -C "$(dirname "$storage_output")" "$(basename "$storage_output")"
(cd "$(dirname "$storage_output")" && sha256sum "$(basename "$storage_output").tar.gz" > "$(basename "$storage_output").tar.gz.sha256")
printf 'Pilotpaket: %s.tar.gz\n' "$storage_output"