makeimage.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -xeo pipefail
  3. cd "$(dirname "$0")"
  4. source util/vars.sh
  5. TMPCFG="$(mktemp --suffix=.toml)"
  6. cat <<EOF >"$TMPCFG"
  7. [worker.oci]
  8. max-parallelism = 4
  9. EOF
  10. trap "rm -f '$TMPCFG'" EXIT
  11. docker buildx inspect ffbuilder &>/dev/null || docker buildx create \
  12. --bootstrap \
  13. --name ffbuilder \
  14. --config "$TMPCFG" \
  15. --driver-opt network=host \
  16. --driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \
  17. --driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1
  18. if [[ -z "$QUICKBUILD" ]]; then
  19. BASE_IMAGE_TARGET="${PWD}/.cache/images/base"
  20. if [[ ! -d "${BASE_IMAGE_TARGET}" ]]; then
  21. docker buildx --builder ffbuilder build \
  22. --cache-from=type=local,src=.cache/"${BASE_IMAGE/:/_}" \
  23. --cache-to=type=local,mode=max,dest=.cache/"${BASE_IMAGE/:/_}" \
  24. --load --tag "${BASE_IMAGE}" \
  25. "images/base"
  26. mkdir -p "${BASE_IMAGE_TARGET}"
  27. docker image save "${BASE_IMAGE}" | tar -x -C "${BASE_IMAGE_TARGET}"
  28. fi
  29. IMAGE_TARGET="${PWD}/.cache/images/base-${TARGET}"
  30. if [[ ! -d "${IMAGE_TARGET}" ]]; then
  31. docker buildx --builder ffbuilder build \
  32. --cache-from=type=local,src=.cache/"${TARGET_IMAGE/:/_}" \
  33. --cache-to=type=local,mode=max,dest=.cache/"${TARGET_IMAGE/:/_}" \
  34. --build-arg GH_REPO="${REGISTRY}/${REPO}" \
  35. --build-context "${BASE_IMAGE}=oci-layout://${BASE_IMAGE_TARGET}" \
  36. --load --tag "${TARGET_IMAGE}" \
  37. "images/base-${TARGET}"
  38. mkdir -p "${IMAGE_TARGET}"
  39. docker image save "${TARGET_IMAGE}" | tar -x -C "${IMAGE_TARGET}"
  40. fi
  41. CONTEXT_SRC="oci-layout://${IMAGE_TARGET}"
  42. else
  43. CONTEXT_SRC="docker-image://${TARGET_IMAGE}"
  44. fi
  45. ./download.sh
  46. ./generate.sh "$TARGET" "$VARIANT" "${ADDINS[@]}"
  47. docker buildx --builder ffbuilder build \
  48. --cache-from=type=local,src=.cache/"${IMAGE/:/_}" \
  49. --cache-to=type=local,mode=max,dest=.cache/"${IMAGE/:/_}" \
  50. --build-context "${TARGET_IMAGE}=${CONTEXT_SRC}" \
  51. --load --tag "$IMAGE" .
  52. if [[ -z "$NOCLEAN" ]]; then
  53. docker buildx rm -f ffbuilder
  54. rm -rf .cache/images
  55. fi