forked from cerc-io/stack-orchestrator
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5beaf69a36 | ||
|
|
06c4a77afe | ||
|
|
aafadbbed6 |
@@ -38,17 +38,21 @@ Initialize deployment and create "spec" file:
|
||||
laconic-so --stack graph-node deploy init --output graph-node-spec.yml
|
||||
```
|
||||
|
||||
We need to assign a fixed port `8000` for subgraph GQL endpoint and `8020` for subgraph deployment. The values can be
|
||||
We need to assign fixed ports: `8000` for subgraph GQL endpoint, `8020` for subgraph deployment and `5001` for IPFS. The values can be
|
||||
customized by editing the "spec" file generated by `laconic-so deploy init`.
|
||||
```
|
||||
$ cat graph-node-spec.yml
|
||||
stack: graph-node
|
||||
ports:
|
||||
graph-node:
|
||||
- '8000:8000'
|
||||
- '8001'
|
||||
- '8020:8020'
|
||||
- '8030'
|
||||
- '8000:8000'
|
||||
- '8001'
|
||||
- '8020:8020'
|
||||
- '8030'
|
||||
ipfs:
|
||||
- '8080'
|
||||
- '4001'
|
||||
- '5001:5001'
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Deploying Subgraph
|
||||
|
||||
## Setup
|
||||
|
||||
We will use the [ethereum-gravatar](https://github.com/graphprotocol/graph-tooling/tree/%40graphprotocol/graph-cli%400.58.0/examples/ethereum-gravatar) example subgraph from `graphprotocol/graph-tooling` repo
|
||||
|
||||
- Clone the repo
|
||||
```bash
|
||||
git clone git@github.com:graphprotocol/graph-tooling.git
|
||||
|
||||
cd graph-tooling
|
||||
```
|
||||
|
||||
- Install dependencies
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
- Change directory to example-subgraph
|
||||
```bash
|
||||
cd examples/ethereum-gravatar
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
||||
The following steps should be similar for every subgraph
|
||||
|
||||
- Change the network and address in `subgraph.yaml`
|
||||
```yaml
|
||||
...
|
||||
dataSources:
|
||||
- kind: ethereum/contract
|
||||
name: Gravity
|
||||
network: <NETWORK_NAME>
|
||||
source:
|
||||
address: '<CONTRACT_ADDRESS>'
|
||||
abi: Gravity
|
||||
startBlock: <START_BLOCK>
|
||||
...
|
||||
```
|
||||
- `CONTRACT_ADDRESS` is the address of the deployed contract on the desired network
|
||||
- `START_BLOCK` is the block number after which we want to process events
|
||||
- `NETWORK_NAME` is the name of the network specified when deploying graph-node
|
||||
- When deploying graph-node `ETH_NETWORKS` env is set to a space-separated list of the networks where each entry has the form `NAME:URL`
|
||||
- The `NAME` can be used in subgraph to specify which network to use
|
||||
- More details can be seen in [Start the stack](./README.md#start-the-stack) section
|
||||
|
||||
- Build the subgraph
|
||||
```bash
|
||||
pnpm codegen
|
||||
pnpm build
|
||||
```
|
||||
|
||||
- Create and deploy the subgraph
|
||||
```bash
|
||||
pnpm graph create example --node <GRAPH_NODE_DEPLOY_ENDPOINT>
|
||||
|
||||
pnpm graph deploy example --ipfs <GRAPH_NODE_IPFS_ENDPOINT> --node <GRAPH_NODE_DEPLOY_ENDPOINT>
|
||||
```
|
||||
- `GRAPH_NODE_DEPLOY_ENDPOINT` and `GRAPH_NODE_IPFS_ENDPOINT` will be available after graph-node has been deployed
|
||||
- More details can be seen in [Create a deployment](./README.md#create-a-deployment) section
|
||||
|
||||
- The subgraph GQL endpoint will be seen after deploy command runs successfully
|
||||
|
||||
- To remove the subgraph
|
||||
```bash
|
||||
pnpm graph remove --node <GRAPH_NODE_DEPLOY_ENDPOINT> example
|
||||
```
|
||||
@@ -0,0 +1,90 @@
|
||||
# Copyright © 2023 Vulcanize
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||
|
||||
import click
|
||||
import datetime
|
||||
import filecmp
|
||||
import os
|
||||
from pathlib import Path
|
||||
import requests
|
||||
import sys
|
||||
import stat
|
||||
import shutil
|
||||
import validators
|
||||
from app.util import get_yaml
|
||||
|
||||
|
||||
def _download_url(url: str, file_path: Path):
|
||||
r = requests.get(url, stream=True)
|
||||
r.raw.decode_content = True
|
||||
with open(file_path, 'wb') as f:
|
||||
shutil.copyfileobj(r.raw, f)
|
||||
|
||||
|
||||
def _error_exit(s: str):
|
||||
print(s)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Note at present this probably won't work on non-Unix based OSes like Windows
|
||||
@click.command()
|
||||
@click.option("--check-only", is_flag=True, default=False, help="only check, don't update")
|
||||
@click.pass_context
|
||||
def command(ctx, check_only):
|
||||
'''update shiv binary from a distribution url'''
|
||||
# Get the distribution URL from config
|
||||
config_key = 'distribution-url'
|
||||
config_file_path = Path(os.path.expanduser("~/.laconic-so/config.yml"))
|
||||
if not config_file_path.exists():
|
||||
_error_exit(f"Error: Config file: {config_file_path} not found")
|
||||
yaml = get_yaml()
|
||||
config = yaml.load(open(config_file_path, "r"))
|
||||
if "distribution-url" not in config:
|
||||
_error_exit(f"Error: {config_key} not defined in {config_file_path}")
|
||||
distribution_url = config[config_key]
|
||||
# Sanity check the URL
|
||||
if not validators.url(distribution_url):
|
||||
_error_exit(f"ERROR: distribution url: {distribution_url} is not valid")
|
||||
# Figure out the filename for ourselves
|
||||
shiv_binary_path = Path(sys.argv[0])
|
||||
timestamp_filename = f"laconic-so-download-{datetime.datetime.now().strftime('%y%m%d-%H%M%S')}"
|
||||
temp_download_path = shiv_binary_path.parent.joinpath(timestamp_filename)
|
||||
# Download the file to a temp filename
|
||||
if ctx.obj.verbose:
|
||||
print(f"Downloading from: {distribution_url} to {temp_download_path}")
|
||||
_download_url(distribution_url, temp_download_path)
|
||||
# Set the executable bit
|
||||
existing_mode = os.stat(temp_download_path)
|
||||
os.chmod(temp_download_path, existing_mode.st_mode | stat.S_IXUSR)
|
||||
# Switch the new file for the path we ran from
|
||||
# Check if the downloaded file is identical to the existing one
|
||||
same = filecmp.cmp(temp_download_path, shiv_binary_path)
|
||||
if same:
|
||||
if not ctx.obj.quiet or check_only:
|
||||
print("No update available, latest version already installed")
|
||||
else:
|
||||
if not ctx.obj.quiet:
|
||||
print("Update available")
|
||||
if check_only:
|
||||
if not ctx.obj.quiet:
|
||||
print("Check-only node, update not installed")
|
||||
else:
|
||||
if not ctx.obj.quiet:
|
||||
print("Installing...")
|
||||
if ctx.obj.verbose:
|
||||
print(f"Replacing: {shiv_binary_path} with {temp_download_path}")
|
||||
os.replace(temp_download_path, shiv_binary_path)
|
||||
if not ctx.obj.quiet:
|
||||
print("Done. Run \"laconic-so version\" to see the newly installed version")
|
||||
@@ -22,6 +22,7 @@ from app import build_npms
|
||||
from app import deploy
|
||||
from app import version
|
||||
from app import deployment
|
||||
from app import update
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
|
||||
@@ -48,3 +49,4 @@ cli.add_command(deploy.command, "deploy") # deploy is an alias for deploy-syste
|
||||
cli.add_command(deploy.command, "deploy-system")
|
||||
cli.add_command(deployment.command, "deployment")
|
||||
cli.add_command(version.command, "version")
|
||||
cli.add_command(update.command, "update")
|
||||
|
||||
@@ -7,3 +7,4 @@ PyYAML>=6.0.1
|
||||
ruamel.yaml>=0.17.32
|
||||
pydantic==1.10.9
|
||||
tomli==2.0.1
|
||||
validators==0.22.0
|
||||
|
||||
@@ -5,6 +5,9 @@ fi
|
||||
|
||||
install_dir=~/bin
|
||||
|
||||
# Skip the package install stuff if so directed
|
||||
if ! [[ -n "$CERC_SO_INSTALL_SKIP_PACKAGES" ]]; then
|
||||
|
||||
# First display a reasonable warning to the user unless run with -y
|
||||
if ! [[ $# -eq 1 && $1 == "-y" ]]; then
|
||||
echo "**************************************************************************************"
|
||||
@@ -128,13 +131,20 @@ sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin d
|
||||
# Allow the current user to use Docker
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
# End of long if block: Skip the package install stuff if so directed
|
||||
fi
|
||||
|
||||
echo "**************************************************************************************"
|
||||
echo "Installing laconic-so"
|
||||
# install latest `laconic-so`
|
||||
distribution_url=https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so
|
||||
install_filename=${install_dir}/laconic-so
|
||||
mkdir -p ${install_dir}
|
||||
curl -L -o ${install_filename} https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so
|
||||
curl -L -o ${install_filename} ${distribution_url}
|
||||
chmod +x ${install_filename}
|
||||
# Set up config file for self-update feature
|
||||
mkdir ~/.laconic-so
|
||||
echo "distribution-url: ${distribution_url}" > ~/.laconic-so/config.yml
|
||||
|
||||
echo "**************************************************************************************"
|
||||
# Check if our PATH line is already there
|
||||
|
||||
Reference in New Issue
Block a user