Skip to content

Commit

Permalink
feat(docker-container): create docker image from Dockerfile (#90)
Browse files Browse the repository at this point in the history
* feat(docker-container): Draft: create docker image from Dockerfile

* feat(docker-container): Solved bug when building image #89

* feat(use-docker): run soroban-preview docker container in quickstart

* feat(docker): add instructions to readme

* feat(docker): solve soroban-cli config network bug

* Review feedback

* Pass cli args through to quickstart

---------

Co-authored-by: Paul Bellamy <[email protected]>
  • Loading branch information
esteblock and Paul Bellamy authored Mar 6, 2023
1 parent 7b714ea commit ff0e4d2
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 11 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Based on Preview 7
# https://soroban.stellar.org/docs/reference/releases

FROM ubuntu:20.04

RUN apt update && apt install -y curl

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust_install.sh
RUN sh rust_install.sh -y
RUN echo $PATH
ENV PATH="$PATH:/root/.cargo/bin"
RUN rustup target add wasm32-unknown-unknown

RUN apt install -y build-essential
RUN cargo install --locked --version 0.6.0 soroban-cli
# WORKDIR /
RUN mkdir /workspace
WORKDIR /workspace
ENV IS_USING_DOCKER=true
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ build-optimized: fmt
ls -l "$$i"; \
done

build-docker:
docker build . --tag soroban-preview:7

check: fmt
cargo clippy --all-targets
cargo clippy --release --target wasm32-unknown-unknown
Expand Down
37 changes: 33 additions & 4 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,39 @@ This is a [Next.js](https://nextjs.org/) project, demoing how to build a dapp fr
backed by smart contracts on Stellar.

## Getting Started
___

### Dependencies

1. `soroban-cli v0.4.0`. See https://soroban.stellar.org/docs/getting-started/setup#install-the-soroban-cli
1. `soroban-cli v0.6.0`. See https://soroban.stellar.org/docs/getting-started/setup#install-the-soroban-cli
2. `docker` (both Standalone and Futurenet backends require it).
3. `Node.js v17`
4. `Freighter wallet v2.9.1`. Download it from https://github.com/stellar/freighter/releases/tag/2.9.1 and Enable "Experimental Mode" in the settings (gear icon).
5. Build the `soroban-preview` docker image:
```
make build-docker
```
Building the docker image lets you avoid installing the specific version of soroban-cli in step (1), if desired.
___

### Backend (Local Standalone Network)

1. Run the backend docker container with `./quickstart.sh standalone`, and wait for it to start.
2. Run `./initialize.sh standalone` to load the contracts and initialize it.
1. Run the backend docker containers and wait for them to start:

```
./quickstart.sh standalone
```

2. Load the contracts and initialize them:

You can use your own local soroban-cli:
```
./initialize.sh standalone
```
Or run it inside the soroban-preview docker container:
```
docker exec soroban-preview ./initialize.sh standalone
```
- Note: this state will be lost if the quickstart docker container is removed.
3. Add the Standalone custom network in Freighter
| | |
Expand All @@ -38,7 +59,15 @@ backed by smart contracts on Stellar.
working by visiting http://localhost:8000/, and look at the
`ingest_latest_ledger`, field. If it is `0`, the quickstart image is not
ready yet.
2. Run `./initialize.sh futurenet` to load the contracts and initialize it.
2. Load the contracts and initialize it:
You can use your own local soroban-cli:
```
./initialize.sh futurenet
```
Or run it inside the soroban-preview docker container:
```
docker exec soroban-preview ./initialize.sh futurenet
```
3. Add the Futurenet custom network in Freighter
(Note, the out-of-the-box "Future Net" network in
Freighter will not work with a local quickstart container, so we need to add
Expand Down
7 changes: 7 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Build image and tag it with image name and version
docker build . \
--tag soroban-preview:7 \
--force-rm \
--rm
21 changes: 15 additions & 6 deletions initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ set -e

NETWORK="$1"

# If soroban-cli is called inside the soroban-preview docker containter,
# it can call the stellar standalone container just using its name "stellar"
if [[ "$IS_USING_DOCKER" == "true" ]]; then
SOROBAN_RPC_HOST="http://stellar:8000"
else
SOROBAN_RPC_HOST="http://localhost:8000"
fi

SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"

case "$1" in
standalone)
echo "Using standalone network"
SOROBAN_RPC_HOST="http://localhost:8000"
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
FRIENDBOT_URL="$SOROBAN_RPC_HOST/friendbot"
;;
futurenet)
echo "Using Futurenet network"
SOROBAN_RPC_HOST="http://localhost:8000"
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
SOROBAN_NETWORK_PASSPHRASE="Test SDF Future Network ; October 2022"
FRIENDBOT_URL="https://friendbot-futurenet.stellar.org/"
;;
Expand All @@ -25,12 +31,13 @@ futurenet)
;;
esac

if !(soroban config network ls | grep "$NETWORK" 2>&1 >/dev/null); then
#if !(soroban config network ls | grep "$NETWORK" 2>&1 >/dev/null); then
# Always set a net configuration
echo Add the $NETWORK network to cli client
soroban config network add "$NETWORK" \
--rpc-url "$SOROBAN_RPC_URL" \
--network-passphrase "$SOROBAN_NETWORK_PASSPHRASE"
fi
#fi

TOKEN_ADMIN_SECRET="SAKCFFFNCE7XAWYMYVRZQYKUK6KMUCDIINLWISJYTMYJLNR2QLCDLFVT"
if !(soroban config identity ls | grep token-admin 2>&1 >/dev/null); then
Expand All @@ -56,6 +63,8 @@ ARGS="--network $NETWORK --identity token-admin"
echo Wrap the Stellar asset
mkdir -p .soroban
TOKEN_ID=$(soroban lab token wrap $ARGS --asset "EXT:$TOKEN_ADMIN_ADDRESS")
echo "Token wrapped succesfully with TOKEN_ID: $TOKEN_ID"

echo -n "$TOKEN_ID" > .soroban/token_id

echo Build the crowdfund contract
Expand Down
34 changes: 33 additions & 1 deletion quickstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,43 @@ futurenet)
;;
esac

shift

# Run the soroban-preview container
# Remember to do:
# make build-docker

echo "Creating docker soroban network"
(docker network inspect soroban-network -f '{{.Id}}' 2>/dev/null) \
|| docker network create soroban-network

echo "Searching for a previous soroban-preview docker container"
containerID=$(docker ps --filter="name=soroban-preview" --all --quiet)
if [[ ${containerID} ]]; then
echo "Start removing soroban-preview container."
docker rm --force soroban-preview
echo "Finished removing soroban-preview container."
else
echo "No previous soroban-preview container was found"
fi

currentDir=$(pwd)
docker run -dti \
--volume ${currentDir}:/workspace \
--name soroban-preview \
-p 8001:8000 \
--ipc=host \
--network soroban-network \
soroban-preview:7

# Run the stellar quickstart image
docker run --rm -ti \
--platform linux/amd64 \
--name stellar \
--network soroban-network \
-p 8000:8000 \
stellar/quickstart:soroban-dev@sha256:81c23da078c90d0ba220f8fc93414d0ea44608adc616988930529c58df278739 \
$ARGS \
--enable-soroban-rpc \
--protocol-version 20
--protocol-version 20 \
"$@" # Pass through args from the CLI

0 comments on commit ff0e4d2

Please sign in to comment.