Skip to content

Commit

Permalink
add ark-network/ark and gitignore volumes dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Dec 27, 2024
1 parent 32bd838 commit 231e664
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.env

cmd/nigiri/resources/volumes/
vendor/
build/
dist/
9 changes: 8 additions & 1 deletion cmd/nigiri/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var datadirFlag = cli.StringFlag{
Value: config.DefaultDatadir,
}

var arkFlag = cli.BoolFlag{
Name: "ark",
Usage: "enable Ark Network",
Value: false,
}

//go:embed resources/docker-compose.yml
//go:embed resources/bitcoin.conf
//go:embed resources/elements.conf
Expand All @@ -54,7 +60,7 @@ func main() {
app.Version = formatVersion()
app.Name = "nigiri CLI"
app.Usage = "one-click bitcoin development environment"
app.Flags = append(app.Flags, &datadirFlag)
app.Flags = append(app.Flags, &datadirFlag, &arkFlag)
app.Commands = append(
app.Commands,
&rpc,
Expand Down Expand Up @@ -132,6 +138,7 @@ func provisionResourcesToDatadir(datadir string) error {
filepath.Join(datadir, "volumes", "lnd"),
filepath.Join(datadir, "volumes", "lightningd"),
filepath.Join(datadir, "volumes", "tapd"),
filepath.Join(datadir, "volumes", "ark"),
}

for _, dir := range volumeDirs {
Expand Down
26 changes: 26 additions & 0 deletions cmd/nigiri/resources/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,32 @@ services:
- ./volumes/lightningd:/.lightning
- ./volumes/bitcoin:/etc/bitcoin

ark:
container_name: ark
image: ghcr.io/ark-network/ark:v0.4.2
user: "${UID:-1000}:${GID:-1000}"
depends_on:
- bitcoin
environment:
ARK_ROUND_INTERVAL: "15"
ARK_LOG_LEVEL: "5"
ARK_NETWORK: "regtest"
ARK_PORT: "7070"
ARK_NO_TLS: "true"
ARK_NO_MACAROONS: "true"
ARK_TX_BUILDER_TYPE: "covenantless"
ARK_BITCOIND_RPC_USER: "admin1"
ARK_BITCOIND_RPC_PASS: "123"
ARK_BITCOIND_RPC_HOST: "bitcoin:18443"
ARK_BITCOIND_ZMQ_BLOCK: "tcp://bitcoin:28332"
ARK_BITCOIND_ZMQ_TX: "tcp://bitcoin:28333"
ARK_DATADIR: "/data"
volumes:
- ./volumes/ark:/data
ports:
- "7070:7070"
restart: unless-stopped

networks:
default:
name: nigiri
77 changes: 16 additions & 61 deletions cmd/nigiri/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package main

import (
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/urfave/cli/v2"
"github.com/vulpemventures/nigiri/internal/config"
"github.com/vulpemventures/nigiri/internal/docker"
)

var start = cli.Command{
Expand All @@ -20,11 +17,7 @@ var start = cli.Command{
Flags: []cli.Flag{
&liquidFlag,
&lnFlag,
&cli.BoolFlag{
Name: "ci",
Usage: "runs in headless mode without esplora for continuous integration environments",
Value: false,
},
&arkFlag,
},
}

Expand All @@ -34,80 +27,42 @@ func startAction(ctx *cli.Context) error {
return errors.New("nigiri is already running, please stop it first")
}

isLiquid := ctx.Bool("liquid")
isLN := ctx.Bool("ln")
isCI := ctx.Bool("ci")
datadir := ctx.String("datadir")
composePath := filepath.Join(datadir, config.DefaultCompose)

// spin up all the services in the compose file
servicesToRun := []string{"esplora"}
if isLiquid {
//this will only run chopsticks & chopsticks-liquid and servives they depends on
servicesToRun = append(servicesToRun, "esplora-liquid")
}
// Build the docker-compose command with appropriate services
services := []string{"bitcoin", "electrs", "chopsticks", "esplora"}

if isLN {
// LND
servicesToRun = append(servicesToRun, "tap")
// Core Lightning Network
servicesToRun = append(servicesToRun, "cln")
if ctx.Bool("liquid") {
services = append(services, "liquid", "electrs-liquid", "chopsticks-liquid", "esplora-liquid")
}

if isCI {
//this will only run chopsticks and servives it depends on
servicesToRun = []string{"chopsticks"}
if isLiquid {
//this will only run chopsticks & chopsticks-liquid and servives they depends on
servicesToRun = append(servicesToRun, "chopsticks-liquid")
}
// add also LN services if needed
if isLN {
// LND
servicesToRun = append(servicesToRun, "tap")
// Core Lightning Network
servicesToRun = append(servicesToRun, "cln")
}
if ctx.Bool("ln") {
services = append(services, "lnd", "tap", "cln")
}

args := []string{"up", "-d"}
args = append(args, servicesToRun...)
if ctx.Bool("ark") {
services = append(services, "ark")
}

bashCmd := runDockerCompose(composePath, args...)
// Start the services
bashCmd := runDockerCompose(composePath, append([]string{"up", "-d"}, services...)...)
bashCmd.Stdout = os.Stdout
bashCmd.Stderr = os.Stderr

if err := bashCmd.Run(); err != nil {
return err
}

// Update state
if err := nigiriState.Set(map[string]string{
"running": strconv.FormatBool(true),
"ci": strconv.FormatBool(isCI),
"liquid": strconv.FormatBool(isLiquid),
"ln": strconv.FormatBool(isLN),
"liquid": strconv.FormatBool(ctx.Bool("liquid")),
"ln": strconv.FormatBool(ctx.Bool("ln")),
"ark": strconv.FormatBool(ctx.Bool("ark")),
}); err != nil {
return err
}

services, err := docker.GetServices(composePath)
if err != nil {
return err
}

fmt.Println()
fmt.Println("ENDPOINTS")

for _, nameAndEndpoint := range services {
name := nameAndEndpoint[0]
endpoint := nameAndEndpoint[1]

if !isLiquid && strings.Contains(name, "liquid") {
continue
}

fmt.Println(name + " " + endpoint)
}

return nil
}
11 changes: 10 additions & 1 deletion cmd/nigiri/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ func stopAction(ctx *cli.Context) error {

bashCmd := runDockerCompose(composePath, "stop")
if delete {
cleanupCmd := runDockerCompose(composePath, "run", "--rm", "--entrypoint", "sh", "bitcoin", "-c", "chown -R $(id -u):$(id -g) /data/.bitcoin")
cleanupCmd := runDockerCompose(composePath, "run", "-T", "--rm", "--entrypoint", "sh", "bitcoin", "-c", "chown -R $(id -u):$(id -g) /data/.bitcoin")
cleanupCmd.Stdout = os.Stdout
cleanupCmd.Stderr = os.Stderr
if err := cleanupCmd.Run(); err != nil {
fmt.Printf("Warning: cleanup container failed: %v\n", err)
}

if ctx.Bool("ark") {
arkCleanupCmd := runDockerCompose(composePath, "run", "-T", "--rm", "--entrypoint", "sh", "ark", "-c", "chown -R $(id -u):$(id -g) /data")
arkCleanupCmd.Stdout = os.Stdout
arkCleanupCmd.Stderr = os.Stderr
if err := arkCleanupCmd.Run(); err != nil {
fmt.Printf("Warning: ark cleanup container failed: %v\n", err)
}
}

bashCmd = runDockerCompose(composePath, "down", "--volumes")
}

Expand Down

0 comments on commit 231e664

Please sign in to comment.