Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support directory copying to final images for cosmos chains #285

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions dockerfile/cosmos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ ENV LIBRARIES_ENV ${LIBRARIES}
RUN bash -c 'set -eux;\
LIBRARIES_ARR=($LIBRARIES_ENV); for LIBRARY in "${LIBRARIES_ARR[@]}"; do cp $LIBRARY /root/lib/; done'

# Copy over directories
RUN mkdir -p /root/dir_abs && touch /root/dir_abs.list
ARG DIRECTORIES
ENV DIRECTORIES_ENV ${DIRECTORIES}
RUN bash -c 'set -eux;\
DIRECTORIES_ARR=($DIRECTORIES_ENV);\
i=0;\
for DIRECTORY in "${DIRECTORIES_ARR[@]}"; do \
cp -R $DIRECTORY /root/dir_abs/$i;\
echo $DIRECTORY >> /root/dir_abs.list;\
((i = i + 1));\
done'

# Use minimal busybox from infra-toolkit image for final scratch image
FROM ghcr.io/strangelove-ventures/infra-toolkit:v0.1.4 AS infra-toolkit
RUN addgroup --gid 1025 -S heighliner && adduser --uid 1025 -S heighliner -G heighliner
Expand All @@ -138,7 +151,7 @@ LABEL org.opencontainers.image.source="https://github.com/strangelove-ventures/h
WORKDIR /bin

# Install ln (for making hard links) and rm (for cleanup) from full busybox image (will be deleted, only needed for image assembly)
COPY --from=busybox-full /bin/ln /bin/rm ./
COPY --from=busybox-full /bin/ln /bin/mv /bin/rm ./

# Install minimal busybox image as shell binary (will create hardlinks for the rest of the binaries to this data)
COPY --from=infra-toolkit /busybox/busybox /bin/sh
Expand Down Expand Up @@ -174,8 +187,21 @@ RUN for b in \
which \
; do ln sh $b; done

# Copy over absolute path directories
COPY --from=build-env /root/dir_abs /root/dir_abs
COPY --from=build-env /root/dir_abs.list /root/dir_abs.list

# Move absolute path directories to their absolute locations.
RUN sh -c 'i=0; while read DIR; do\
echo "$i: $DIR";\
PLACEDIR="$(dirname "$DIR")";\
mkdir -p "$PLACEDIR";\
mv /root/dir_abs/$i $DIR;\
i=$((i+1));\
done < /root/dir_abs.list'

# Remove write utils
RUN rm ln rm
RUN rm ln rm mv

# Install chain binaries
COPY --from=build-env /root/bin /bin
Expand Down
136 changes: 79 additions & 57 deletions dockerfile/cosmos/local.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,61 +53,6 @@ FROM busybox:1.34.1-musl AS busybox-full
# Use alpine to source the latest CA certificates
FROM alpine:3 as alpine-3

# Build part 1 of the final image
FROM scratch AS final-part1

LABEL org.opencontainers.image.source="https://github.com/strangelove-ventures/heighliner"

WORKDIR /bin

# Install ln (for making hard links) and rm (for cleanup) from full busybox image (will be deleted, only needed for image assembly)
COPY --from=busybox-full /bin/ln /bin/rm ./

# Install minimal busybox image as shell binary (will create hardlinks for the rest of the binaries to this data)
COPY --from=infra-toolkit /busybox/busybox /bin/sh

# Install jq
COPY --from=infra-toolkit /usr/local/bin/jq /bin/

# Add hard links for read-only utils
# Will then only have one copy of the busybox minimal binary file with all utils pointing to the same underlying inode
RUN for b in \
cat \
date \
df \
du \
env \
grep \
head \
less \
ls \
md5sum \
pwd \
sha1sum \
sha256sum \
sha3sum \
sha512sum \
sleep \
stty \
tail \
tar \
tee \
tr \
watch \
which \
; do ln sh $b; done

# Remove write utils
RUN rm ln rm

# Install trusted CA certificates
COPY --from=alpine-3 /etc/ssl/cert.pem /etc/ssl/cert.pem

# Install heighliner user
COPY --from=infra-toolkit /etc/passwd /etc/passwd
COPY --from=infra-toolkit --chown=1025:1025 /home/heighliner /home/heighliner
COPY --from=infra-toolkit --chown=1025:1025 /tmp /tmp

# Install chain binary
FROM init-env AS build-env

Expand Down Expand Up @@ -171,10 +116,87 @@ ENV LIBRARIES_ENV ${LIBRARIES}
RUN bash -c 'set -eux;\
LIBRARIES_ARR=($LIBRARIES_ENV); for LIBRARY in "${LIBRARIES_ARR[@]}"; do cp $LIBRARY /root/lib/; done'

# Move final binary to the final image
FROM final-part1 as final
# Copy over directories
RUN mkdir -p /root/dir_abs && touch /root/dir_abs.list
ARG DIRECTORIES
ENV DIRECTORIES_ENV ${DIRECTORIES}
RUN bash -c 'set -eux;\
DIRECTORIES_ARR=($DIRECTORIES_ENV);\
i=0;\
for DIRECTORY in "${DIRECTORIES_ARR[@]}"; do \
cp -R $DIRECTORY /root/dir_abs/$i;\
echo $DIRECTORY >> /root/dir_abs.list;\
((i = i + 1));\
done'

# Build final image
FROM scratch

LABEL org.opencontainers.image.source="https://github.com/strangelove-ventures/heighliner"

WORKDIR /bin

# Install ln (for making hard links) and rm (for cleanup) from full busybox image (will be deleted, only needed for image assembly)
COPY --from=busybox-full /bin/ln /bin/mv /bin/rm ./

# Install minimal busybox image as shell binary (will create hardlinks for the rest of the binaries to this data)
COPY --from=infra-toolkit /busybox/busybox /bin/sh

# Install jq
COPY --from=infra-toolkit /usr/local/bin/jq /bin/

# Add hard links for read-only utils
# Will then only have one copy of the busybox minimal binary file with all utils pointing to the same underlying inode
RUN for b in \
cat \
date \
df \
du \
env \
grep \
head \
less \
ls \
md5sum \
pwd \
sha1sum \
sha256sum \
sha3sum \
sha512sum \
sleep \
stty \
tail \
tar \
tee \
tr \
watch \
which \
; do ln sh $b; done

# Copy over absolute path directories
COPY --from=build-env /root/dir_abs /root/dir_abs
COPY --from=build-env /root/dir_abs.list /root/dir_abs.list

# Move absolute path directories to their absolute locations.
RUN sh -c 'i=0; while read DIR; do\
echo "$i: $DIR";\
PLACEDIR="$(dirname "$DIR")";\
mkdir -p "$PLACEDIR";\
mv /root/dir_abs/$i $DIR;\
i=$((i+1));\
done < /root/dir_abs.list'

# Remove write utils
RUN rm ln rm mv

# Install trusted CA certificates
COPY --from=alpine-3 /etc/ssl/cert.pem /etc/ssl/cert.pem

# Install heighliner user
COPY --from=infra-toolkit /etc/passwd /etc/passwd
COPY --from=infra-toolkit --chown=1025:1025 /home/heighliner /home/heighliner
COPY --from=infra-toolkit --chown=1025:1025 /tmp /tmp

# Install chain binaries
COPY --from=build-env /root/bin /bin

Expand Down
30 changes: 28 additions & 2 deletions dockerfile/cosmos/localcross.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ ENV LIBRARIES_ENV ${LIBRARIES}
RUN bash -c 'set -eux;\
LIBRARIES_ARR=($LIBRARIES_ENV); for LIBRARY in "${LIBRARIES_ARR[@]}"; do cp $LIBRARY /root/lib/; done'

# Copy over directories
RUN mkdir -p /root/dir_abs && touch /root/dir_abs.list
ARG DIRECTORIES
ENV DIRECTORIES_ENV ${DIRECTORIES}
RUN bash -c 'set -eux;\
DIRECTORIES_ARR=($DIRECTORIES_ENV);\
i=0;\
for DIRECTORY in "${DIRECTORIES_ARR[@]}"; do \
cp -R $DIRECTORY /root/dir_abs/$i;\
echo $DIRECTORY >> /root/dir_abs.list;\
((i = i + 1));\
done'

# Use minimal busybox from infra-toolkit image for final scratch image
FROM ghcr.io/strangelove-ventures/infra-toolkit:v0.1.4 AS infra-toolkit
RUN addgroup --gid 1025 -S heighliner && adduser --uid 1025 -S heighliner -G heighliner
Expand All @@ -132,7 +145,7 @@ LABEL org.opencontainers.image.source="https://github.com/strangelove-ventures/h
WORKDIR /bin

# Install ln (for making hard links) and rm (for cleanup) from full busybox image (will be deleted, only needed for image assembly)
COPY --from=busybox-full /bin/ln /bin/rm ./
COPY --from=busybox-full /bin/ln /bin/mv /bin/rm ./

# Install minimal busybox image as shell binary (will create hardlinks for the rest of the binaries to this data)
COPY --from=infra-toolkit /busybox/busybox /bin/sh
Expand Down Expand Up @@ -168,8 +181,21 @@ RUN for b in \
which \
; do ln sh $b; done

# Copy over absolute path directories
COPY --from=build-env /root/dir_abs /root/dir_abs
COPY --from=build-env /root/dir_abs.list /root/dir_abs.list

# Move absolute path directories to their absolute locations.
RUN sh -c 'i=0; while read DIR; do\
echo "$i: $DIR";\
PLACEDIR="$(dirname "$DIR")";\
mkdir -p "$PLACEDIR";\
mv /root/dir_abs/$i $DIR;\
i=$((i+1));\
done < /root/dir_abs.list'

# Remove write utils
RUN rm ln rm
RUN rm ln rm mv

# Install chain binaries
COPY --from=build-env /root/bin /bin
Expand Down
30 changes: 28 additions & 2 deletions dockerfile/cosmos/native.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ ENV LIBRARIES_ENV ${LIBRARIES}
RUN bash -c 'set -eux;\
LIBRARIES_ARR=($LIBRARIES_ENV); for LIBRARY in "${LIBRARIES_ARR[@]}"; do cp $LIBRARY /root/lib/; done'

# Copy over directories
RUN mkdir -p /root/dir_abs && touch /root/dir_abs.list
ARG DIRECTORIES
ENV DIRECTORIES_ENV ${DIRECTORIES}
RUN bash -c 'set -eux;\
DIRECTORIES_ARR=($DIRECTORIES_ENV);\
i=0;\
for DIRECTORY in "${DIRECTORIES_ARR[@]}"; do \
cp -R $DIRECTORY /root/dir_abs/$i;\
echo $DIRECTORY >> /root/dir_abs.list;\
((i = i + 1));\
done'

# Use minimal busybox from infra-toolkit image for final scratch image
FROM ghcr.io/strangelove-ventures/infra-toolkit:v0.1.4 AS infra-toolkit
RUN addgroup --gid 1025 -S heighliner && adduser --uid 1025 -S heighliner -G heighliner
Expand All @@ -110,7 +123,7 @@ LABEL org.opencontainers.image.source="https://github.com/strangelove-ventures/h
WORKDIR /bin

# Install ln (for making hard links) and rm (for cleanup) from full busybox image (will be deleted, only needed for image assembly)
COPY --from=busybox-full /bin/ln /bin/rm ./
COPY --from=busybox-full /bin/ln /bin/mv /bin/rm ./

# Install minimal busybox image as shell binary (will create hardlinks for the rest of the binaries to this data)
COPY --from=infra-toolkit /busybox/busybox /bin/sh
Expand Down Expand Up @@ -146,8 +159,21 @@ RUN for b in \
which \
; do ln sh $b; done

# Copy over absolute path directories
COPY --from=build-env /root/dir_abs /root/dir_abs
COPY --from=build-env /root/dir_abs.list /root/dir_abs.list

# Move absolute path directories to their absolute locations.
RUN sh -c 'i=0; while read DIR; do\
echo "$i: $DIR";\
PLACEDIR="$(dirname "$DIR")";\
mkdir -p "$PLACEDIR";\
mv /root/dir_abs/$i $DIR;\
i=$((i+1));\
done < /root/dir_abs.list'

# Remove write utils
RUN rm ln rm
RUN rm ln rm mv

# Install chain binaries
COPY --from=build-env /root/bin /bin
Expand Down
Loading