-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exp/services/ledgerexporter: Implement Docker based deployment (#5254)
- Loading branch information
Showing
5 changed files
with
130 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo") | ||
|
||
# https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||
BUILD_DATE := $(shell date -u +%FT%TZ) | ||
VERSION ?= $(shell git rev-parse --short HEAD) | ||
DOCKER_IMAGE := stellar/ledger-exporter | ||
|
||
docker-build: | ||
cd ../../../ && \ | ||
$(SUDO) docker build --platform linux/amd64 --pull --label org.opencontainers.image.created="$(BUILD_DATE)" \ | ||
--build-arg VERSION=$(VERSION) \ | ||
$(if $(STELLAR_CORE_VERSION), --build-arg STELLAR_CORE_VERSION=$(STELLAR_CORE_VERSION)) \ | ||
-f exp/services/ledgerexporter/docker/Dockerfile \ | ||
-t $(DOCKER_IMAGE):$(VERSION) \ | ||
-t $(DOCKER_IMAGE):latest . | ||
|
||
docker-test: | ||
# Create temp storage dir | ||
$(SUDO) mkdir -p ${PWD}/storage/exporter-test | ||
|
||
# Create test network for docker | ||
$(SUDO) docker network create test-network | ||
|
||
# Run the fake GCS server | ||
$(SUDO) docker run -d --name fake-gcs-server -p 4443:4443 \ | ||
-v ${PWD}/storage:/data --network test-network fsouza/fake-gcs-server -scheme http | ||
|
||
# Run the ledger-exporter | ||
$(SUDO) docker run --platform linux/amd64 -t --network test-network\ | ||
-e NETWORK=pubnet \ | ||
-e ARCHIVE_TARGET=gcs://exporter-test \ | ||
-e START=1000 \ | ||
-e END=2000 \ | ||
-e STORAGE_EMULATOR_HOST=http://fake-gcs-server:4443 \ | ||
$(DOCKER_IMAGE):$(VERSION) | ||
|
||
$(SUDO) docker stop fake-gcs-server | ||
$(SUDO) docker rm fake-gcs-server | ||
$(SUDO) rm -rf ${PWD}/storage | ||
$(SUDO) docker network rm test-network | ||
|
||
docker-push: | ||
$(SUDO) docker push $(DOCKER_IMAGE):$(VERSION) | ||
$(SUDO) docker push $(DOCKER_IMAGE):latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM golang:1.22-bullseye AS builder | ||
|
||
WORKDIR /go/src/github.com/stellar/go | ||
|
||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
|
||
RUN go mod download | ||
|
||
COPY . ./ | ||
|
||
RUN go install github.com/stellar/go/exp/services/ledgerexporter | ||
|
||
FROM ubuntu:22.04 | ||
ARG STELLAR_CORE_VERSION | ||
ENV STELLAR_CORE_VERSION=${STELLAR_CORE_VERSION:-*} | ||
ENV STELLAR_CORE_BINARY_PATH /usr/bin/stellar-core | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
# ca-certificates are required to make tls connections | ||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl wget gnupg apt-utils | ||
RUN wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true apt-key add - | ||
RUN echo "deb https://apt.stellar.org focal stable" >/etc/apt/sources.list.d/SDF.list | ||
RUN echo "deb https://apt.stellar.org focal unstable" >/etc/apt/sources.list.d/SDF-unstable.list | ||
RUN apt-get update && apt-get install -y stellar-core=${STELLAR_CORE_VERSION} | ||
RUN apt-get clean | ||
|
||
COPY exp/services/ledgerexporter/docker/start / | ||
|
||
RUN ["chmod", "+x", "/start"] | ||
|
||
COPY --from=builder /go/bin/ledgerexporter /usr/bin/ledgerexporter | ||
|
||
ENTRYPOINT ["/start"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#! /usr/bin/env bash | ||
set -e | ||
|
||
# Validation | ||
if [ -z "$ARCHIVE_TARGET" ]; then | ||
echo "error: undefined ARCHIVE_TARGET env variable" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$NETWORK" ]; then | ||
echo "error: undefined NETWORK env variable" | ||
exit 1 | ||
fi | ||
|
||
ledgers_per_file="${LEDGERS_PER_FILE:-1}" | ||
files_per_partition="${FILES_PER_PARTITION:-64000}" | ||
|
||
# Generate TOML configuration | ||
cat <<EOF > config.toml | ||
network = "${NETWORK}" | ||
destination_url = "${ARCHIVE_TARGET}" | ||
[exporter_config] | ||
ledgers_per_file = $ledgers_per_file | ||
files_per_partition = $files_per_partition | ||
EOF | ||
|
||
# Check if START or END variables are set | ||
if [[ -n "$START" || -n "$END" ]]; then | ||
echo "START: $START END: $END" | ||
/usr/bin/ledgerexporter --config-file config.toml --start $START --end $END | ||
# Check if FROM_LAST variable is set | ||
elif [[ -n "$FROM_LAST" ]]; then | ||
echo "FROM_LAST: $FROM_LAST" | ||
/usr/bin/ledgerexporter --config-file config.toml --from-last $FROM_LAST | ||
else | ||
echo "Error: No ledger range provided." | ||
exit 1 | ||
fi |