From 13c449f4cb24db2e873c715e9c4e71f3f5acabaa Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Fri, 22 Nov 2024 20:12:42 +0500 Subject: [PATCH] script for running sequencer binaries based on flag --- .github/workflows/build.yml | 20 -------------------- .github/workflows/build_static.yml | 19 +------------------ docker-compose.yaml | 15 +++++++++++---- docker/sequencer-sqlite.Dockerfile | 21 --------------------- docker/sequencer.Dockerfile | 17 +++++++++++++---- scripts/build-docker-images-native | 7 +++---- scripts/build-docker-images-static | 5 ++--- scripts/sequencer-entrypoint | 12 ++++++++++++ sequencer/src/persistence/sql.rs | 2 +- 9 files changed, 43 insertions(+), 75 deletions(-) delete mode 100644 docker/sequencer-sqlite.Dockerfile create mode 100644 scripts/sequencer-entrypoint diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45f530452e..3af5eb5b7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -164,7 +164,6 @@ jobs: marketplace-builder-tag: ${{ steps.marketplace-builder.outputs.tags }} node-validator-tag: ${{ steps.node-validator.outputs.tags }} dev-rollup-tag: ${{ steps.dev-rollup.outputs.tags }} - sequencer-sqlite-tag: ${{ steps.sequencer-sqlite.outputs.tags }} steps: - name: Checkout Repository uses: actions/checkout@v4 @@ -295,13 +294,6 @@ jobs: with: images: ghcr.io/espressosystems/espresso-sequencer/dev-rollup - - name: Generate sequencer-sqlite metadata - uses: docker/metadata-action@v5 - id: sequencer-sqlite - with: - images: ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite - - - name: Build and push sequencer docker uses: docker/build-push-action@v6 with: @@ -471,16 +463,6 @@ jobs: tags: ${{ steps.dev-rollup.outputs.tags }} labels: ${{ steps.dev-rollup.outputs.labels }} - - name: Build and push sequencer-sqlite docker - uses: docker/build-push-action@v6 - with: - context: ./ - file: ./docker/sequencer-sqlite.Dockerfile - platforms: ${{ env.DOCKER_PLATFORMS }} - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.sequencer-sqlite.outputs.tags }} - labels: ${{ steps.sequencer-sqlite.outputs.labels }} - test-demo: if: ${{ github.event_name != 'pull_request' }} runs-on: ubuntu-latest @@ -512,7 +494,6 @@ jobs: docker pull ${{ needs.build-dockers.outputs.marketplace-builder-tag }} docker pull ${{ needs.build-dockers.outputs.node-validator-tag }} docker pull ${{ needs.build-dockers.outputs.dev-rollup-tag }} - docker pull ${{ needs.build-dockers.outputs.sequencer-sqlite-tag }} - name: Tag new docker images run: | @@ -532,7 +513,6 @@ jobs: docker tag ${{ needs.build-dockers.outputs.marketplace-builder-tag }} ghcr.io/espressosystems/espresso-sequencer/marketplace-builder:main docker tag ${{ needs.build-dockers.outputs.node-validator-tag }} ghcr.io/espressosystems/espresso-sequencer/node-validator:main docker tag ${{ needs.build-dockers.outputs.dev-rollup-tag }} ghcr.io/espressosystems/espresso-sequencer/dev-rollup:main - docker tag ${{ needs.build-dockers.outputs.sequencer-sqlite-tag }} ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite:main - name: Test docker demo run: | diff --git a/.github/workflows/build_static.yml b/.github/workflows/build_static.yml index d57da47345..a52d73a83c 100644 --- a/.github/workflows/build_static.yml +++ b/.github/workflows/build_static.yml @@ -231,13 +231,6 @@ jobs: images: ghcr.io/espressosystems/espresso-sequencer/dev-rollup flavor: suffix=musl - - name: Generate sequencer-sqlite metadata - uses: docker/metadata-action@v5 - id: sequencer-sqlite - with: - images: ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite - flavor: suffix=musl - - name: Build and push sequencer docker uses: docker/build-push-action@v6 with: @@ -386,14 +379,4 @@ jobs: platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.dev-rollup.outputs.tags }} - labels: ${{ steps.dev-rollup.outputs.labels }} - - - name: Build and push sequencer-sqlite docker - uses: docker/build-push-action@v6 - with: - context: ./ - file: ./docker/sequencer-sqlite.Dockerfile - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.sequencer-sqlite.outputs.tags }} - labels: ${{ steps.sequencer-sqlite.outputs.labels }} + labels: ${{ steps.dev-rollup.outputs.labels }} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 3b211cf550..a98053b8a2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -222,6 +222,7 @@ services: # Run the full API server with all modules, Postgres storage command: sequencer -- storage-sql -- http -- query -- catchup -- status -- submit -- hotshot-events -- config environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=false - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -278,6 +279,7 @@ services: - "$ESPRESSO_SEQUENCER1_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" command: sequencer -- storage-sql -- http -- query -- catchup -- status -- state -- explorer environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=false - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -334,6 +336,7 @@ services: - "$ESPRESSO_SEQUENCER2_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" command: sequencer -- http -- catchup -- status environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=false - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -384,6 +387,7 @@ services: - "$ESPRESSO_SEQUENCER3_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" command: sequencer -- http -- catchup -- status environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=false - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -433,6 +437,7 @@ services: - "$ESPRESSO_SEQUENCER4_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" command: sequencer -- http -- catchup -- status environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=false - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -476,13 +481,14 @@ services: condition: service_completed_successfully sequencer5: - image: ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite:main + image: ghcr.io/espressosystems/espresso-sequencer/sequencer:main ports: - "$ESPRESSO_SEQUENCER5_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" # Run the full API server with all modules, Sqlite storage - command: sequencer-sqlite -- storage-sql -- http -- query -- catchup -- status -- submit -- config + command: sequencer -- storage-sql -- http -- query -- catchup -- status -- submit -- config environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=true - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT @@ -528,11 +534,12 @@ services: condition: service_completed_successfully sequencer6: - image: ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite:main + image: ghcr.io/espressosystems/espresso-sequencer/sequencer:main ports: - "$ESPRESSO_SEQUENCER6_API_PORT:$ESPRESSO_SEQUENCER_API_PORT" - command: sequencer-sqlite -- storage-sql -- http -- query -- catchup -- status -- state -- explorer + command: sequencer -- storage-sql -- http -- query -- catchup -- status -- state -- explorer environment: + - ESPRESSO_SEQUENCER_EMBEDDED_DB=true - ESPRESSO_SEQUENCER_GENESIS_FILE - ESPRESSO_SEQUENCER_ORCHESTRATOR_URL - ESPRESSO_SEQUENCER_CDN_ENDPOINT diff --git a/docker/sequencer-sqlite.Dockerfile b/docker/sequencer-sqlite.Dockerfile deleted file mode 100644 index 0cb3c359d3..0000000000 --- a/docker/sequencer-sqlite.Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM ubuntu:jammy - -ARG TARGETARCH - -RUN apt-get update \ - && apt-get install -y curl libcurl4 wait-for-it tini \ - && rm -rf /var/lib/apt/lists/* -ENTRYPOINT ["tini", "--"] - -# Download an SRS file to avoid download at runtime -ENV AZTEC_SRS_PATH=/kzg10-aztec20-srs-1048584.bin -RUN curl -LO https://github.com/EspressoSystems/ark-srs/releases/download/v0.2.0/$AZTEC_SRS_PATH - -COPY target/$TARGETARCH/release/sequencer-sqlite /bin/sequencer-sqlite -RUN chmod +x /bin/sequencer-sqlite - -# We run the additional `status` and `catchup` modules by default. These are modules that require -# minimal resources (no persistent storage) but improve the functionality of the network. -CMD ["/bin/sequencer-sqlite", "--", "http", "--", "status", "--", "catchup"] -HEALTHCHECK --interval=1s --timeout=1s --retries=100 CMD curl --fail http://localhost:${ESPRESSO_SEQUENCER_API_PORT}/healthcheck || exit 1 -EXPOSE ${ESPRESSO_SEQUENCER_API_PORT} \ No newline at end of file diff --git a/docker/sequencer.Dockerfile b/docker/sequencer.Dockerfile index 29de81c034..91c87b5dc8 100644 --- a/docker/sequencer.Dockerfile +++ b/docker/sequencer.Dockerfile @@ -11,8 +11,11 @@ ENTRYPOINT ["tini", "--"] ENV AZTEC_SRS_PATH=/kzg10-aztec20-srs-1048584.bin RUN curl -LO https://github.com/EspressoSystems/ark-srs/releases/download/v0.2.0/$AZTEC_SRS_PATH -COPY target/$TARGETARCH/release/sequencer /bin/sequencer -RUN chmod +x /bin/sequencer +COPY target/$TARGETARCH/release/sequencer /bin/sequencer-postgres +RUN chmod +x /bin/sequencer-postgres + +COPY target/$TARGETARCH/release/sequencer-sqlite /bin/sequencer-sqlite +RUN chmod +x /bin/sequencer-sqlite COPY target/$TARGETARCH/release/utils /bin/utils RUN chmod +x /bin/utils @@ -34,6 +37,12 @@ COPY data/genesis /genesis # Set `ESPRESSO_SEQUENCER_GENESIS_SECRET` COPY docker/scripts/sequencer-awssecretsmanager.sh /bin/sequencer-awssecretsmanager.sh +# Copy entrypoint script +COPY scripts/sequencer-entrypoint /bin/sequencer +RUN chmod +x /bin/sequencer + +ENTRYPOINT ["/bin/sequencer"] + # Set a path to save the consensus config on startup. # # Upon restart, the config will be loaded from this file and the node will be able to resume @@ -43,6 +52,6 @@ ENV ESPRESSO_SEQUENCER_STORAGE_PATH=/store/sequencer # We run the additional `status` and `catchup` modules by default. These are modules that require # minimal resources (no persistent storage) but improve the functionality of the network. -CMD ["/bin/sequencer", "--", "http", "--", "status", "--", "catchup"] +CMD ["--", "http", "--", "status", "--", "catchup"] HEALTHCHECK --interval=1s --timeout=1s --retries=100 CMD curl --fail http://localhost:${ESPRESSO_SEQUENCER_API_PORT}/healthcheck || exit 1 -EXPOSE ${ESPRESSO_SEQUENCER_API_PORT} +EXPOSE ${ESPRESSO_SEQUENCER_API_PORT} \ No newline at end of file diff --git a/scripts/build-docker-images-native b/scripts/build-docker-images-native index 026a528dd1..31f0222f24 100755 --- a/scripts/build-docker-images-native +++ b/scripts/build-docker-images-native @@ -103,9 +103,9 @@ done mkdir -p ${WORKDIR}/docker/scripts cp -v docker/scripts/sequencer-awssecretsmanager.sh ${WORKDIR}/docker/scripts -# Copy the dev-node launch script +# Copy the dev-node and sequencer-entrypoint script mkdir -p ${WORKDIR}/scripts -cp -v scripts/launch-dev-node-with-postgres ${WORKDIR}/scripts +cp -v scripts/{launch-dev-node-with-postgres,sequencer-entrypoint} ${WORKDIR}/scripts export DOCKER_BUILDKIT=1 docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/orchestrator:main -f docker/orchestrator.Dockerfile ${WORKDIR} @@ -124,5 +124,4 @@ docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/ docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/marketplace-solver:main -f docker/marketplace-solver.Dockerfile ${WORKDIR} docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/marketplace-builder:main -f docker/marketplace-builder.Dockerfile ${WORKDIR} docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/node-validator:main -f docker/node-validator.Dockerfile ${WORKDIR} -docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/dev-rollup:main -f docker/dev-rollup.Dockerfile ${WORKDIR} -docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite:main -f docker/sequencer-sqlite.Dockerfile ${WORKDIR} +docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/dev-rollup:main -f docker/dev-rollup.Dockerfile ${WORKDIR} \ No newline at end of file diff --git a/scripts/build-docker-images-static b/scripts/build-docker-images-static index c3fd4b5c70..af87a0a2b6 100755 --- a/scripts/build-docker-images-static +++ b/scripts/build-docker-images-static @@ -49,9 +49,9 @@ done mkdir -p ${WORKDIR}/docker/scripts cp -v docker/scripts/sequencer-awssecretsmanager.sh ${WORKDIR}/docker/scripts -# Copy the dev-node launch script +# Copy the dev-node and sequencer script mkdir -p ${WORKDIR}/scripts -cp -v scripts/launch-dev-node-with-postgres ${WORKDIR}/scripts +cp -v scripts/{launch-dev-node-with-postgres,sequencer-entrypoint} ${WORKDIR}/scripts export DOCKER_BUILDKIT=1 docker build -t ghcr.io/espressosystems/espresso-sequencer/orchestrator:main -f docker/orchestrator.Dockerfile ${WORKDIR} @@ -71,4 +71,3 @@ docker build -t ghcr.io/espressosystems/espresso-sequencer/marketplace-solver:ma docker build -t ghcr.io/espressosystems/espresso-sequencer/marketplace-builder:main -f docker/marketplace-builder.Dockerfile ${WORKDIR} docker build -t ghcr.io/espressosystems/espresso-sequencer/node-validator:main -f docker/node-validator.Dockerfile ${WORKDIR} docker build -t ghcr.io/espressosystems/espresso-sequencer/dev-rollup:main -f docker/dev-rollup.Dockerfile ${WORKDIR} -docker build -t ghcr.io/espressosystems/espresso-sequencer/sequencer-sqlite:main -f docker/sequencer-sqlite.Dockerfile ${WORKDIR} diff --git a/scripts/sequencer-entrypoint b/scripts/sequencer-entrypoint new file mode 100644 index 0000000000..0f03b2d066 --- /dev/null +++ b/scripts/sequencer-entrypoint @@ -0,0 +1,12 @@ +#!/bin/sh + +export ESPRESSO_SEQUENCER_EMBEDDED_DB=${ESPRESSO_SEQUENCER_EMBEDDED_DB:-false} + +# Decide which binary to run based on the environment variable +if [ "$ESPRESSO_SEQUENCER_EMBEDDED_DB" = "true" ]; then + echo "Starting sequencer with sqlite..." + exec /bin/sequencer-sqlite "$@" +else + echo "Starting sequencer with postgres..." + exec /bin/sequencer-postgres "$@" +fi diff --git a/sequencer/src/persistence/sql.rs b/sequencer/src/persistence/sql.rs index 3ff646a00c..6dcb5b950c 100644 --- a/sequencer/src/persistence/sql.rs +++ b/sequencer/src/persistence/sql.rs @@ -1028,7 +1028,7 @@ mod testing { type Storage = Arc; async fn tmp_storage() -> Self::Storage { - Arc::new(TmpDb::persistent().await) + Arc::new(TmpDb::init().await) } async fn connect(db: &Self::Storage) -> Self {