Skip to content

Commit

Permalink
Merge branch 'main' into fix/build-osmo-26-2024-09-20
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer authored Oct 6, 2024
2 parents 70c33d8 + 9885965 commit 51049ff
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 63 deletions.
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 @@ -54,61 +54,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 @@ -172,10 +117,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 @@ -115,6 +115,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 @@ -133,7 +146,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 @@ -169,8 +182,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 @@ -93,6 +93,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 @@ -111,7 +124,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 @@ -147,8 +160,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

0 comments on commit 51049ff

Please sign in to comment.