tremayne-stewart / go-gallery

The engine behind gallery.so

Home Page:https://gallery.so

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-gallery

Pre

  1. Install Go
  2. Install Docker
  3. Install Docker-Compose

Clone and install deps

$ git clone git@github.com:gallery-so/go-gallery.git
$ cd go-gallery
$ go get -u -d ./...

Setup (Mac)

$ go build -o ./bin/main ./cmd/server/main.go

This will generate a binary within ./bin/main. To run the binary, simply:

$ ./bin/main

Redis and Postgres

The app will connect to a local redis and local postgres instance by default. To spin it up, you can use the docker commands below.

[Optional] Shell script to seed NFT data

If you want to seed your local database with real, indexed data from our dev or production clusters, you can "prep" your environment using the following bash script. Running this won't execute the import itself, but rather trigger the import when you run the later docker commands. As a pre-requisite, you must have access to _encrypted_deploy in order to access the dev / prod clusters.

Note that if you run the following command, don't run make g-docker and upload the image to Dockerhub. This will expose the locally migrated data to the public. You can avoid this by opening a new shell. More on make g-docker further below.

Finally: if you are using bash/sh instead of zsh, change the first line of the _import_env.sh file to match your shell.

$ source ./_import_env.sh <path to dev/prod backend app.yaml> <address of dev/prod wallet to import data>

Docker commands

Build the docker containers. If you ran the above shell script, the seed script will be executed. You can re-run this script in the future if you want the latest data:

$ make docker-build

Run the docker containers:

$ make docker-start

To remove running redis and postgres instance:

$ make docker-stop

Deploying our Postgres image

make g-docker will push a new docker image that initializes a postgres instance with our custom schema. To get access to our dockerhub, contact a core team member.

Do not run this script if you've run the shell script for seeding NFT data.

Working with migrations

The migrate cli can be installed via brew (assuming MacOS):

brew install golang-migrate

Create a new migration:

migrate create -ext sql -dir db/migrations -seq <name of migration>

Run a migration on dev:

# Apply an up migration.
migrate -path db/migrations -database "postgresql://postgres:<dev db password here>@34.102.59.201:5432/postgres" up

# Undo the last migration.
migrate -path db/migrations -database "postgresql://postgres:<dev db password here>@34.102.59.201:5432/postgres" down 1

Run a migration locally:

migrate -path db/migrations -database "postgresql://postgres@localhost:5432/postgres?sslmode=disable" up

Healthcheck

Verify that the server is running by calling the /v1/health endpoint.

$ curl localhost:4000/glry/v1/health

Testing services via Cloud Tasks

We use aertje/cloud-tasks-emulator to emulate running Cloud Tasks locally. The emulator is added as a submodule to the repo.

See targeting services for more info on the setup. A typical local setup looks something like below:

+-----------+
|     ui    |
|  (:3000)  |
+-----|-----+
      |
      |
      |
+-----V-----+     +-------------+     +-----------+        +------------+
|   server  ------> cloud tasks ------>   nginx   --------->   feed     |
|  (:4000)  |     |   (:8123)   |     |  (:8080)  |        |  (:4124)   |
+-----------+     +-------------+     +-----|-----+        +------------+
                                            |
                                            |              +------------+
                                            +-------------->  feedbot   |
                                                           |  (:4123)   |
                                                           +------------+

To get started:

# If first time pulling down the submodule
git submodule update --init --recursive

# To update the submodule afterwards
git pull --recurse-submodules

After pulling the repo, start the services you're interested in running:

# Start the cloud task emulator and docker dependencies
make cloud-tasks

# Start each of the services needed in separate sessions
go run cmd/feed/main.go    # Start the feed
go run cmd/feedbot/main.go # Start the feedbot

# Start the backend
go run cmd/server/main.go

Testing

Run all tests in current directory and all of its subdirectories:

$ go test ./...

Run all tests in subdirectory (e.g. /server):

$ go test ./server/...

Run a specific test by passing the name as an option:

go test -run {testName}

Add -v for detailed logs.

Skip longer running tests with the -short flag:

go test -short

Integration Testing

Run integration tests against ethereum mainnet:

go test -run TestIntegrationTest ./server/... -args -chain ethereum -chainID 1

About

The engine behind gallery.so

https://gallery.so

License:MIT License


Languages

Language:Go 96.5%Language:Solidity 1.7%Language:Python 1.2%Language:Makefile 0.3%Language:JavaScript 0.2%Language:Shell 0.1%Language:PLpgSQL 0.1%