Skip to content

Commit

Permalink
Merge pull request #268 from 4chain-ag/feat/single_command_to_run_bux…
Browse files Browse the repository at this point in the history
…_server

feat(BUX-84): run bux server with single command
  • Loading branch information
mrz1836 authored Aug 1, 2023
2 parents 1210f20 + 9b90434 commit 9776cf5
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ coverage.txt

# Development data dir
data/

# Configuration files
.env.config
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ WORKDIR /go/src/github.com/BuxOrg/bux-server

COPY . ./

ENV CGO_ENABLED=1

# Build binary
RUN GOOS=linux go build -o bux cmd/server/main.go

# Get runtime image
FROM registry.access.redhat.com/ubi8-minimal
FROM registry.access.redhat.com/ubi9-minimal

# Version
LABEL version="1.0" name="Bux"
Expand Down
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,49 @@ Checkout the docker compose quickstart below for a quick way to get started.

## Docker Compose Quickstart

To get started with development, `bux-server` provides a `docker-compose.yml`
file which starts up Bux Server with Redis and PostgreSQL. To start, we need to
tweak the `config/envs/development.json` file with the proper configuration.
First:

```
$ cp config/envs/docker-compose.json config/envs/development.json
```

Then, we need to update the `admin_key` with your xpub. Modify
`config/envs/development.json` with your admin key. Now we can start the
containers:

```
$ docker-compose up
```
To get started with development, `bux-server` provides a `start-bux-server.sh` script
which is using `docker-compose.yml` file to starts up Bux Server with selected database
and cache storage. To start, we need to fill the config json which we want to use,
for example: `config/envs/development.json`.

Main configuration is done when running the script.

There are two way of running this script:
1. with manual configuration - Every option is displayed in terminal and user can choose
which database/cache storage use and configure how to run bux-server.
```bash
./start-bux-server.sh
```
2. with flags which define how to set up docker services. Ever option is displayed when
you ran the script with flag `-h` or `--help`. Possible options:

```bash
./start-bux-server.sh --help

Welcome in Bux Server!
Usage: ./start-bux-server.sh [OPTIONS]

This script helps you to run Bux server with your preferred database and cache storage.

Options:

-db, --database Define database - postgresql, mongodb, sqlite
-c, --cache Define cache storage - freecache(in-memory), redis
-bs, --bux-server Whether the bux-server should be run - true/false
-env, --environment Define bux-server environment - development/staging/production
-b, --background Whether the bux-server should be run in background - true/false
-x, --xpub Define admin xPub
-l, --load Load .env.config file and run bux-server with its settings
```

```bash
./start-bux-server.sh -db postgresql -c redis -bs true -env development -b false
```

`-l/--load` option add possibility to use previously created `.env.config` file and run bux-server with simple command:
```bash
./start-bux-server.sh -l
```

## Contributing

Expand Down
74 changes: 53 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
# !NOTE: This file should be used only by start-bux-server.sh
version: "3.9"

services:
server:
build: .
environment:
- BUX_ENVIRONMENT=development
bux-redis:
image: redis
container_name: bux-redis
hostname: redis
ports:
- "3003:3003"
- "6379:6379"
volumes:
- ./config:/config:Z
links:
- redis
- db
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
redis:
image: redis
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
db:

bux-postgresql:
image: postgres
container_name: bux-postgresql
volumes:
- ./data/db:/var/lib/postgresql/data:Z
- db-data:/var/lib/postgresql/data:Z
environment:
- POSTGRES_NAME=bux
- POSTGRES_USER=bux
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready"]
test: ["CMD-SHELL", "sh -c 'pg_isready -U postgres -d postgres'"]
timeout: 5s
retries: 3

bux-mongodb:
image: mongo
container_name: bux-mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: mongo
MONGO_INITDB_ROOT_PASSWORD: mongo
MONGO_INITDB_DATABASE: xapi
ports:
- '27017:27017'
volumes:
- db-data:/data/db
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
start_period: 40s

bux-server:
build: .
container_name: bux-server
env_file:
- .env.config
ports:
- "3003:3003"
volumes:
- ./config:/config:Z

volumes:
app-data:
driver: local
db-data:
driver: local
redis-data:
driver: local
Loading

0 comments on commit 9776cf5

Please sign in to comment.