diff --git a/deploy/.registry.env.example b/deploy/.registry.env.example new file mode 100644 index 0000000..dc814bf --- /dev/null +++ b/deploy/.registry.env.example @@ -0,0 +1,10 @@ +# ENV for registry operations + +# Bond to use +REGISTRY_BOND_ID= + +# Target deployer LRN +DEPLOYER_LRN= + +# Authority to deploy the app under +AUTHORITY= diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..a120b22 --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,40 @@ +ARG VARIANT=20-bullseye +FROM node:${VARIANT} + +ARG USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global + +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} + +RUN \ + # Configure global npm install location, use group to adapt to UID/GID changes + if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \ + && usermod -a -G npm ${USERNAME} \ + && umask 0002 \ + && mkdir -p ${NPM_GLOBAL} \ + && touch /usr/local/etc/npmrc \ + && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \ + && chmod g+s ${NPM_GLOBAL} \ + && npm config -g set prefix ${NPM_GLOBAL} \ + && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ + # Install eslint + && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ + && npm cache clean --force > /dev/null 2>&1 + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends jq bash + +# laconic-so +RUN curl -LO https://git.vdb.to/cerc-io/stack-orchestrator/releases/download/latest/laconic-so && \ +chmod +x ./laconic-so && \ +mv ./laconic-so /usr/bin/laconic-so + +# Configure the npm registry +RUN npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/ + +# DEBUG, remove +RUN yarn info @cerc-io/laconic-registry-cli + +# Globally install the cli package +RUN yarn global add @cerc-io/laconic-registry-cli diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..1332428 --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,64 @@ +# Deploy + +## Setup + +### gor-deploy + +* Clone the repo: + + ```bash + git clone git@git.vdb.to:LaconicNetwork/gor-deploy.git + cd gor-deploy/deploy + ``` + +* Build registry CLI image: + + ```bash + docker build -t cerc/laconic-registry-cli . + + # Builds image cerc/laconic-registry-cli:latest + ``` + +* Configure `userKey` and `bondId` in the registry CLI config: + + ```bash + nano config.yml + ``` + +* Add configuration for registry operations: + + ```bash + cp .registry.env.example .registry.env + + # Fill in the required values + nano .registry.env + ``` + +* Add configuration for the app: + + + ```bash + curl -s https://git.vdb.to/LaconicNetwork/gor-deploy/raw/branch/sk-gor-deploy/.env.example -o .app.env + + # Fill in the required values + nano .app.env + ``` + +## Run + +### gor-deploy + +* Deploy `gor-deploy` App: + + ```bash + # In gor-deploy/deploy dir + docker run -it \ + -v ./:/app/deploy -w /app/deploy \ + -e DEPLOYMENT_DNS=mtm-deploy \ + cerc/laconic-registry-cli:latest \ + ./deploy.sh + ``` + +* Check deployment logs on deployer UI: + +* Visit deployed app: diff --git a/deploy/config.yml b/deploy/config.yml new file mode 100644 index 0000000..0ae673d --- /dev/null +++ b/deploy/config.yml @@ -0,0 +1,9 @@ +# Registry CLI config +services: + registry: + rpcEndpoint: 'https://laconicd-mainnet-1.laconic.com' + gqlEndpoint: 'https://laconicd-mainnet-1.laconic.com/api' + userKey: + bondId: + chainId: laconic-mainnet + gasPrice: 0.001alnt diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100755 index 0000000..608deb0 --- /dev/null +++ b/deploy/deploy.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +# Fail on error +set -e + +source .registry.env +echo "Using REGISTRY_BOND_ID: $REGISTRY_BOND_ID" +echo "Using DEPLOYER_LRN: $DEPLOYER_LRN" +echo "Using AUTHORITY: $AUTHORITY" + +# Repository URL +REPO_URL="https://git.vdb.to/LaconicNetwork/gor-deploy" + +# Get the latest commit hash from the repository +LATEST_HASH=$(git ls-remote $REPO_URL HEAD | awk '{print $1}') + +# TODO: Use a release +PACKAGE_VERSION=$(curl -s $REPO_URL/raw/branch/sk-gor-deploy/package.json | jq -r .version) + +# TODO: Update app name +APP_NAME=mtm-deploy + +echo "Repo: ${REPO_URL}" +echo "Latest hash: ${LATEST_HASH}" +echo "App version: ${PACKAGE_VERSION}" +echo "Deployment DNS: ${DEPLOYMENT_DNS}" + +# Current date and time for note +CURRENT_DATE_TIME=$(date -u) + +CONFIG_FILE=config.yml + +# Reference: https://git.vdb.to/cerc-io/test-progressive-web-app/src/branch/main/scripts + +# Get latest version from registry and increment application-record version +NEW_APPLICATION_VERSION=$(laconic -c $CONFIG_FILE registry record list --type ApplicationRecord --all --name "$APP_NAME" 2>/dev/null | jq -r -s ".[] | sort_by(.createTime) | reverse | [ .[] | select(.bondId == \"$REGISTRY_BOND_ID\") ] | .[0].attributes.version" | awk -F. -v OFS=. '{$NF += 1 ; print}') + +if [ -z "$NEW_APPLICATION_VERSION" ] || [ "1" == "$NEW_APPLICATION_VERSION" ]; then + # Set application-record version if no previous records were found + NEW_APPLICATION_VERSION=0.0.1 +fi + +# Generate application-record.yml with incremented version +mkdir -p records +RECORD_FILE=./records/application-record.yml + +cat >$RECORD_FILE <