Skip to content

Commit

Permalink
Update to cosmopolitan 3.1.1, simplify bootstrap
Browse files Browse the repository at this point in the history
We now only use "uname" from busybox... Everything else is pulled from
cosmos binaries themselves.
  • Loading branch information
ajbouh committed Nov 29, 2023
1 parent 2e4c670 commit fab54be
Showing 1 changed file with 126 additions and 27 deletions.
153 changes: 126 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,136 @@
# syntax=docker/dockerfile:1-labs

FROM busybox as unpack-cosmos
ADD --checksum=sha256:ce256ededf106748a09f13bf47ace9ef0e6f115d963353d3d63c21302c5f28f4 https://github.com/jart/cosmopolitan/releases/download/3.0.1/cosmos-3.0.1.zip /dl/
FROM busybox as busybox

# define a starting point "scratch" image that can run APEs
FROM scratch as cosmos-scratch
COPY --from=busybox /bin/uname /usr/bin/
ADD --chmod=0755 https://cosmo.zip/pub/cosmos/bin/assimilate-x86_64.elf /usr/bin/
ADD --chmod=0755 https://cosmo.zip/pub/cosmos/bin/dash /bin/sh
RUN ["/usr/bin/assimilate-x86_64.elf", "-c", "/bin/sh"]
ADD --checksum=sha256:abf3b1bb7182935bf48d98dc143c51ee563d29a1fd2c3930ff5a8d8c8d823817 --chmod=0755 https://justine.lol/ape.elf /usr/bin/ape
ENV PATH=/bin:/usr/bin

# download and unpack all the cosmos binaries
FROM cosmos-scratch as unpack-cosmos
ADD --chmod=0755 https://cosmo.zip/pub/cosmos/bin/unzip /usr/bin/
RUN ["/usr/bin/assimilate-x86_64.elf", "-c", "/usr/bin/unzip"]
ADD https://cosmo.zip/pub/cosmos/zip/cosmos.zip /dl/

# list of binaries that must be assimilated and manifest for /bin as described in https://justine.lol/cosmos.txt (as of 2023-11-29)
WORKDIR /opt/cosmos
RUN ["/bin/unzip", "/dl/cosmos-3.0.1.zip"]
RUN ["/bin/cp", "bin/dash", "bin/sh"]
RUN unzip /dl/cosmos.zip
RUN /usr/bin/assimilate-x86_64.elf -c bin/dd \
&& /usr/bin/assimilate-x86_64.elf -c bin/cp \
&& /usr/bin/assimilate-x86_64.elf -c bin/mv \
&& /usr/bin/assimilate-x86_64.elf -c bin/echo \
&& /usr/bin/assimilate-x86_64.elf -c bin/uname \
&& /usr/bin/assimilate-x86_64.elf -c bin/mkdir \
&& /usr/bin/assimilate-x86_64.elf -c bin/chmod \
&& /usr/bin/assimilate-x86_64.elf -c bin/gzip \
&& /usr/bin/assimilate-x86_64.elf -c bin/printf \
# assimilate these so the build works on github actions...
&& /usr/bin/assimilate-x86_64.elf -c bin/rmdir
RUN bin/mv 'bin/[' \
bin/bash \
bin/cat \
bin/chgrp \
bin/chmod \
bin/chown \
bin/cksum \
bin/cp \
bin/date \
bin/df \
bin/echo \
bin/false \
bin/grep \
bin/kill \
bin/ln \
bin/ls \
bin/mkdir \
bin/mknod \
bin/mktemp \
bin/mv \
bin/nice \
bin/printenv \
bin/pwd \
bin/rm \
bin/rmdir \
bin/sed \
bin/sleep \
bin/stat \
bin/sync \
bin/touch \
bin/true \
bin/uname \
/bin/
RUN mv bin/* /usr/bin/
WORKDIR /
RUN rmdir /opt/cosmos/bin /opt/cosmos

FROM busybox as unpack-cosmo
ADD --checksum=sha256:2872d2f06ef5fd13a206d3ba7a9ef29eb9bd8ebfe9600a35d5c55a88ffd112df https://github.com/jart/cosmopolitan/releases/download/3.0.1/cosmopolitan-3.0.1.tar.gz /dl/
ADD --checksum=sha256:e222b38b53b999e3310a2e172a75992a28b1594af5c1e954c913fc54405c1135 https://github.com/jart/cosmopolitan/releases/download/3.0.1/cosmocc-0.0.16.zip /dl/
WORKDIR /opt/cosmo
RUN ["/bin/tar", "-xf", "/dl/cosmopolitan-3.0.1.tar.gz", "--strip-components=1"]
RUN ["/bin/unzip", "/dl/cosmocc-0.0.16.zip"]
WORKDIR /usr/bin
RUN ["/bin/ln", "-s", "/opt/cosmo/bin/cosmocc", "cc"]
RUN ["/bin/ln", "-s", "/opt/cosmo/bin/cosmocc", "gcc"]
ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh"]
CMD ["/bin/bash"]

FROM busybox as busybox
# download and unpack the cosmo source code
FROM cosmos-scratch as unpack-cosmo
ADD --checksum=sha256:8d1058afcd6f32f5e7edb708c0a3014d544a4b17d35449be71fbfdd2a1eb39ba https://github.com/jart/cosmopolitan/releases/download/3.1.1/cosmopolitan-3.1.1.tar.gz /dl/
WORKDIR /opt/cosmo
COPY --from=unpack-cosmos /usr/bin/tar /usr/bin/gzip /usr/bin/
RUN /usr/bin/tar --strip-components=1 -xf /dl/cosmopolitan-3.1.1.tar.gz

# Create the final image from scratch
FROM scratch
# We need sh and uname for cosmos at runtime.
COPY --from=busybox /bin/uname /bin/
ADD --checksum=sha256:e67d07bb3010cad678c02fbc787c360340060467ebb39d681b58389df40fc904 --chmod=0755 https://justine.lol/dash /bin/sh
ADD --checksum=sha256:2789991dd41483961a753040ffc083c0c5ff24b84c09a02892e5c584a3f8effa --chmod=0755 https://justine.lol/ape.elf /usr/bin/ape
# download and unpack the cosmocc toolchain
FROM cosmos-scratch as unpack-cosmocc
ADD --checksum=sha256:fa982741f52a2199194b9f06229729eb1eb220d065b0a65cca6dec3b36a9c7df https://github.com/jart/cosmopolitan/releases/download/3.1.1/cosmocc-3.1.1.zip /dl/
WORKDIR /opt/cosmocc
COPY --from=unpack-cosmos /usr/bin/unzip /bin/ln /bin/
RUN unzip /dl/cosmocc-3.1.1.zip \
&& ln -s /opt/cosmocc/bin/cosmocc /usr/bin/cc \
&& ln -s /opt/cosmocc/bin/cosmocc /usr/bin/gcc

# define the final image in as few layers as possible
FROM cosmos-scratch as cosmos
LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
COPY --from=unpack-cosmos /bin /bin
COPY --from=unpack-cosmos /usr/bin /usr/bin
COPY --from=unpack-cosmo /opt/cosmo /opt/cosmo
COPY --from=unpack-cosmo /usr/bin/cc /usr/bin/gcc /usr/bin/
COPY --from=unpack-cosmos /opt/cosmos /opt/cosmos
COPY --from=unpack-cosmocc /usr/bin/cc /usr/bin/gcc /usr/bin/
COPY --from=unpack-cosmocc /opt/cosmocc /opt/cosmocc

ENV PATH=/bin:/usr/bin:/opt/cosmo/bin:/opt/cosmos/bin
# RUN ["/opt/cosmo/bin/cosmocc", "--update"]
ENV PATH=/bin:/usr/bin:/opt/cosmocc/bin

ENTRYPOINT ["/bin/sh", "-c"]
CMD ["/opt/cosmos/bin/bash"]
LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh"]
CMD ["/bin/bash"]

# FROM cosmos-scratch as lua
# LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
# COPY --from=unpack-cosmos /usr/bin/lua /usr/bin/lua
# ENV PATH=/bin:/usr/bin
# ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh"]
# CMD ["/usr/bin/lua"]

# FROM cosmos-scratch as qjs
# LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
# COPY --from=unpack-cosmos /usr/bin/qjs /usr/bin/qjs
# ENV PATH=/bin:/usr/bin
# ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh"]
# CMD ["/usr/bin/qjs"]

# FROM cosmos-scratch as sqlite3
# LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
# COPY --from=unpack-cosmos /usr/bin/sqlite3 /usr/bin/sqlite3
# ENV PATH=/bin:/usr/bin
# ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh"]
# CMD ["/usr/bin/sqlite3"]

# FROM cosmos-scratch as python
# LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
# COPY --from=unpack-cosmos /usr/bin/python /usr/bin/python
# ENV PATH=/bin:/usr/bin
# ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh", "/usr/bin/python"]

# FROM cosmos-scratch as huggingface-hub
# LABEL org.opencontainers.image.source https://github.com/ajbouh/cosmos
# COPY --from=unpack-cosmos /usr/bin/python /usr/bin/python
# ENV PATH=/bin:/usr/bin
# RUN python -m pip install --no-cache-dir huggingface_hub[cli]
# ENTRYPOINT ["/bin/sh", "-c", "exec \"$@\"", "sh", "/usr/bin/python", "/ahgamut/testing/superconfigure/cosmos/x86_64/bin/huggingface-cli"]

0 comments on commit fab54be

Please sign in to comment.