Skip to content

Commit

Permalink
Simplify demo instructions (#18)
Browse files Browse the repository at this point in the history
Remove docker compose because it's simpler to show docker run commands.
  • Loading branch information
caike authored Feb 20, 2025
1 parent b6f2c05 commit 039ff56
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 52 deletions.
15 changes: 0 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
FROM elixir:1.18.1-alpine

RUN mix local.hex --force

WORKDIR /app

COPY mix.exs .
COPY mix.lock .

RUN mix deps.get

COPY . .

RUN mix compile

CMD ["elixir", "run_with_demeter.exs"]
#CMD ["elixir", "run.exs"]
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,46 @@ For a more detailed description of different ways to use this library, read the

## Running via Docker

### Using Demeter.run
In order to run the application via Docker, you need to build the image first:

The demo application can connect to a Cardano node at [Demeter.run](https://demeter.run/) 🪄
```
docker build -t xander .
```

First, create a Node on Demeter. Then, set your Node's url in the `DEMETER_URL` environment variable in the `.env` file.
With the image built, you can now connect to either a local Cardano node via a UNIX socket or to a node at Demeter.run.

For example:
#### 1. Connecting via a local UNIX socket

```bash
DEMETER_URL=https://your-node-at.demeter.run
```
This assumes you have access to a fully synced Cardano node.

🚨 **Note:** Socket files mapped via socat/ssh tunnels **DO NOT WORK** when using containers on OS X.

Then, run the application using Docker Compose:
Run the previously built Docker image with the `-v` argument, which mounts the path of your local socket path to
the container's default socket path (`/tmp/cardano-node.socket`):

```bash
docker compose up --build
```
docker run --rm \
-v /your/local/node.socket:/tmp/cardano-node.socket \
xander elixir run.exs
```

#### Via local UNIX socket
#### 2. Connecting to a node at Demeter.run

🚨 **Note:** Socket files mapped via socat/ssh tunnels **DO NOT WORK** when using containers on OS X.
The demo application can connect to a Cardano node at [Demeter.run](https://demeter.run/) 🪄

Uncomment the `volumes` section in the `compose.yml` file to mount the local UNIX socket to the container's socket path.
First, create a Node on Demeter and grab the Node's URL.

```yml
volumes:
- /path/to/node.socket:/tmp/cardano-node.socket
```
Then, run the Docker image with the `DEMETER_URL` environment variable set to your Node's URL:

Then, run the application using Docker Compose:
```bash
docker compose up --build
docker run --rm \
-e DEMETER_URL=https://your-node-at.demeter.run \
xander elixir run_with_demeter.exs
```

## Running natively with an Elixir local dev environment

#### Via local UNIX socket
#### a) Via local UNIX socket

Run the following command using your own Cardano node's socket path:

Expand Down Expand Up @@ -107,10 +110,16 @@ socat UNIX-LISTEN:/tmp/cardano_node.socket,reuseaddr,fork TCP:localhost:3002
ssh -N -L 3002:localhost:3002 user@remote-server-ip
```

#### Using Demeter.run
4. Run the example script:

```bash
CARDANO_NODE_PATH=/tmp/cardano_node.socket elixir run.exs
```

#### b) Using Demeter.run

To connect to a node at Demeter.run, set `DEMETER_URL` to your Node Demeter URL.

```bash
DEMETER_URL=https://your-node-at.demeter.run mix query_current_era
DEMETER_URL=https://your-node-at.demeter.run elixir run_with_demeter.exs
```
12 changes: 0 additions & 12 deletions compose.yml

This file was deleted.

6 changes: 3 additions & 3 deletions run.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Mix.install([
{:xander, path: Path.expand(".")}
])

socket_path = System.get_env("CARDANO_NODE_SOCKET_PATH")
socket_path = System.get_env("CARDANO_NODE_SOCKET_PATH", "/tmp/cardano-node.socket")

if socket_path == nil do
IO.puts("Error: CARDANO_NODE_SOCKET_PATH environment variable is not set")
if !File.exists?(socket_path) do
IO.puts("Error: socket file path #{socket_path} does not exist")
System.halt(1)
end

Expand Down

0 comments on commit 039ff56

Please sign in to comment.