From 953a504f0391a131275f6cb95b5322388cd5d191 Mon Sep 17 00:00:00 2001 From: Prit Sheth <124409873+psheth9@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:09:31 -0700 Subject: [PATCH] Update docker file to build 2 images based on `BINARY_NAME` (#300) * Update docker file to build 2 images based on argument * Update docker-build and makefile * remove duplicate assignments --- cmd/soroban-rpc/docker/Dockerfile | 15 +++++++++++---- cmd/soroban-rpc/docker/Makefile | 12 +++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/soroban-rpc/docker/Dockerfile b/cmd/soroban-rpc/docker/Dockerfile index cbe03a87..a9608256 100644 --- a/cmd/soroban-rpc/docker/Dockerfile +++ b/cmd/soroban-rpc/docker/Dockerfile @@ -1,6 +1,7 @@ FROM golang:1.22-bullseye as build ARG RUST_TOOLCHAIN_VERSION=stable ARG REPOSITORY_VERSION +ARG BINARY_NAME=soroban-rpc WORKDIR /go/src/github.com/stellar/soroban-rpc @@ -18,11 +19,14 @@ RUN apt-get clean RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUST_TOOLCHAIN_VERSION -RUN make REPOSITORY_VERSION=${REPOSITORY_VERSION} build-soroban-rpc -RUN mv soroban-rpc /bin/soroban-rpc +RUN make REPOSITORY_VERSION=${REPOSITORY_VERSION} build-${BINARY_NAME} + +# Move the binary to a common location +RUN mv ${BINARY_NAME} /bin/${BINARY_NAME} FROM ubuntu:22.04 ARG STELLAR_CORE_VERSION +ARG BINARY_NAME=soroban-rpc ENV STELLAR_CORE_VERSION=${STELLAR_CORE_VERSION:-*} ENV STELLAR_CORE_BINARY_PATH /usr/bin/stellar-core ENV DEBIAN_FRONTEND=noninteractive @@ -35,5 +39,8 @@ RUN echo "deb https://apt.stellar.org focal unstable" >/etc/apt/sources.list.d/S RUN apt-get update && apt-get install -y stellar-core=${STELLAR_CORE_VERSION} RUN apt-get clean -COPY --from=build /bin/soroban-rpc /app/ -ENTRYPOINT ["/app/soroban-rpc"] +# Copy the binary from the build stage +COPY --from=build /bin/${BINARY_NAME} /app/${BINARY_NAME} + +# Set the entrypoint to the specific binary +ENTRYPOINT ["/app/${BINARY_NAME}"] \ No newline at end of file diff --git a/cmd/soroban-rpc/docker/Makefile b/cmd/soroban-rpc/docker/Makefile index f3f39994..1d02a5cd 100644 --- a/cmd/soroban-rpc/docker/Makefile +++ b/cmd/soroban-rpc/docker/Makefile @@ -22,12 +22,22 @@ ifndef STELLAR_CORE_VERSION $(error STELLAR_CORE_VERSION environment variable must be set. For example 19.10.1-1310.6649f5173.focal~soroban) endif -TAG ?= stellar/stellar-soroban-rpc:$(SOROBAN_RPC_VERSION_PACKAGE_VERSION) +# Set default value for BINARY_NAME if not provided +BINARY_NAME ?= soroban-rpc + +# Set the TAG based on the value of BINARY_NAME +ifeq ($(BINARY_NAME),stellar-rpc) + TAG := stellar/stellar-rpc:$(SOROBAN_RPC_VERSION_PACKAGE_VERSION) +else + TAG := stellar/stellar-soroban-rpc:$(SOROBAN_RPC_VERSION_PACKAGE_VERSION) +endif + docker-build: $(SUDO) docker build --pull --platform linux/amd64 $(DOCKER_OPTS) \ --label org.opencontainers.image.created="$(BUILD_DATE)" \ --build-arg STELLAR_CORE_VERSION=$(STELLAR_CORE_VERSION) --build-arg SOROBAN_RPC_VERSION=$(SOROBAN_RPC_VERSION_PACKAGE_VERSION) \ + --build-arg BINARY_NAME=$(BINARY_NAME) \ -t $(TAG) -f Dockerfile.release . docker-push: