From 382a9f1848b680b1552a99cf69968922d6abbf71 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 10 Jun 2024 20:17:33 +0300 Subject: [PATCH] add entrypoint to dockerfile Signed-off-by: onur-ozkan --- .github/workflows/build-and-install.yml | 4 +- Dockerfile.ibc | 72 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.ibc diff --git a/.github/workflows/build-and-install.yml b/.github/workflows/build-and-install.yml index 94f71db..75a8868 100644 --- a/.github/workflows/build-and-install.yml +++ b/.github/workflows/build-and-install.yml @@ -62,9 +62,7 @@ jobs: - name: Build and Push run: | - git clone https://github.com/cosmos/relayer - cd relayer - docker build -t komodoofficial/ibc-relayer:latest -f ./Dockerfile . + docker build -t komodoofficial/ibc-relayer:latest -f ./Dockerfile.ibc . docker push komodoofficial/ibc-relayer:latest container-build-and-push: diff --git a/Dockerfile.ibc b/Dockerfile.ibc new file mode 100644 index 0000000..7e7b026 --- /dev/null +++ b/Dockerfile.ibc @@ -0,0 +1,72 @@ +FROM --platform=$BUILDPLATFORM golang:1.21-alpine3.17 AS build-env + +RUN apk add --update --no-cache curl make git libc-dev bash gcc linux-headers eudev-dev + +ARG TARGETARCH +ARG BUILDARCH + +RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \ + wget -c https://musl.cc/aarch64-linux-musl-cross.tgz -O - | tar -xzvv --strip-components 1 -C /usr; \ + elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \ + wget -c https://musl.cc/x86_64-linux-musl-cross.tgz -O - | tar -xzvv --strip-components 1 -C /usr; \ + fi + +ADD . . + +RUN if [ "${TARGETARCH}" = "arm64" ] && [ "${BUILDARCH}" != "arm64" ]; then \ + export CC=aarch64-linux-musl-gcc CXX=aarch64-linux-musl-g++;\ + elif [ "${TARGETARCH}" = "amd64" ] && [ "${BUILDARCH}" != "amd64" ]; then \ + export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++; \ + fi; \ + GOOS=linux GOARCH=$TARGETARCH CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"' make install + +RUN if [ -d "/go/bin/linux_${TARGETARCH}" ]; then mv /go/bin/linux_${TARGETARCH}/* /go/bin/; fi + +# Use minimal busybox from infra-toolkit image for final scratch image +FROM ghcr.io/strangelove-ventures/infra-toolkit:v0.0.6 AS busybox-min +RUN addgroup --gid 1000 -S relayer && adduser --uid 100 -S relayer -G relayer + +# Use ln and rm from full featured busybox for assembling final image +FROM busybox:1.34.1-musl AS busybox-full + +# Build final image from scratch +FROM scratch + +LABEL org.opencontainers.image.source="https://github.com/cosmos/relayer" + +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=busybox-min /busybox/busybox /bin/sh + +# Add hard links for read-only utils, then remove ln and rm +# Will then only have one copy of the busybox minimal binary file with all utils pointing to the same underlying inode +RUN ln sh pwd && \ + ln sh ls && \ + ln sh cat && \ + ln sh less && \ + ln sh grep && \ + ln sh sleep && \ + ln sh env && \ + ln sh tar && \ + ln sh tee && \ + ln sh du && \ + rm ln rm + +# Install chain binaries +COPY --from=build-env /bin/rly /bin + +# Install trusted CA certificates +COPY --from=busybox-min /etc/ssl/cert.pem /etc/ssl/cert.pem + +# Install relayer user +COPY --from=busybox-min /etc/passwd /etc/passwd +COPY --from=busybox-min --chown=100:1000 /home/relayer /home/relayer + +WORKDIR /home/relayer +USER relayer + +ENTRYPOINT ["/bin/sh", "-c" , "rly transact clients nucleus-atom --override && rly start"]