@@ -7,31 +7,45 @@ ARG BUNDLING_IMAGE=public.ecr.aws/sam/build-python3.12:latest-arm64
77FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
88FROM ${BUNDLING_IMAGE}
99
10- # The default builder scripts depend on a few basic Unix tools that are present
11- # in the SAM build images but may be missing from slimmer custom base images
12- # such as `python:3.12-slim`.
13- # - `bash` is required because `entrypoint.sh` and `export.sh` are bash scripts.
14- # - `coreutils` / `util-linux` provide commands used by the scripts such as
15- # `realpath`, `mktemp`, and `flock`-adjacent utilities across distros.
16- # - `rsync` is used to stage workspace and source files efficiently.
10+ # The default builder scripts need:
11+ # - `bash` because `entrypoint.sh` and `export.sh` are bash scripts
12+ # - `rsync` for efficient source/workspace staging
13+ # - GNU `getopt` for argument parsing in `export.sh`
14+ # - a `realpath` implementation that supports `-m`
1715#
18- # We detect the distro package manager here so `BUNDLING_IMAGE` can point at a
19- # broader range of Debian, RPM, or Alpine-based Python images without requiring
20- # users to maintain a separate custom builder image just to install these tools.
21- RUN if command -v apt-get >/dev/null 2>&1; then \
16+ # Many base images already provide some or all of these. Install only what is
17+ # missing so RPM-based images such as Amazon Linux 2023 can keep using
18+ # `coreutils-single` without conflicting with the full `coreutils` package.
19+ RUN set -eu; \
20+ packages='' ; \
21+ if ! command -v bash >/dev/null 2>&1; then \
22+ packages="$packages bash" ; \
23+ fi; \
24+ if ! command -v rsync >/dev/null 2>&1; then \
25+ packages="$packages rsync" ; \
26+ fi; \
27+ if ! getopt -T >/dev/null 2>&1; then \
28+ packages="$packages util-linux" ; \
29+ fi; \
30+ if ! realpath -m / >/dev/null 2>&1; then \
31+ packages="$packages coreutils" ; \
32+ fi; \
33+ if [ -z "$packages" ]; then \
34+ exit 0; \
35+ elif command -v apt-get >/dev/null 2>&1; then \
2236 apt-get update && \
23- apt-get install -y --no-install-recommends bash coreutils rsync util-linux && \
37+ apt-get install -y --no-install-recommends $packages && \
2438 rm -rf /var/lib/apt/lists/*; \
2539 elif command -v dnf >/dev/null 2>&1; then \
26- dnf install -y bash coreutils rsync util-linux && \
40+ dnf install -y $packages && \
2741 dnf clean all; \
2842 elif command -v yum >/dev/null 2>&1; then \
29- yum install -y bash coreutils rsync util-linux && \
43+ yum install -y $packages && \
3044 yum clean all; \
3145 elif command -v apk >/dev/null 2>&1; then \
32- apk add --no-cache bash coreutils rsync util-linux ; \
46+ apk add --no-cache $packages ; \
3347 else \
34- echo "Unsupported base image: install bash, coreutils, rsync , and util-linux in the custom BUNDLING_IMAGE" >&2; \
48+ echo "Unsupported base image: install bash, rsync, util-linux , and any package providing 'realpath -m' in the custom BUNDLING_IMAGE" >&2; \
3549 exit 1; \
3650 fi
3751
0 commit comments