Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obscuro Gateway Database Deploy #1514

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/manual-deploy-obscuro-gateway-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Deploys Obscuro Gateway's Database on Azure for Testnet
# Starts the Obscuro Gateway's database on Azure VM

name: '[M] Deploy Obscuro Gateway Database'
run-name: '[M] Deploy Obscuro Gateway Database ( ${{ github.event.inputs.testnet_type }} )'
on:
workflow_dispatch:
inputs:
testnet_type:
description: 'Testnet Type'
required: true
default: 'dev-testnet'
type: choice
options:
- 'dev-testnet'
- 'testnet'

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: 'Extract branch name'
shell: bash
run: |
echo "Branch Name: ${GITHUB_REF_NAME}"
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV

- name: 'Set Obscuro Gateway variables for testnet'
if: ${{ github.event.inputs.testnet_type == 'testnet' }}
run: |
echo "OBSCURO_GATEWAY_DB_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/obscuro_gateway_mariadb_testnet:latest" >> $GITHUB_ENV
echo "RESOURCE_STARTING_NAME=testnet" >> $GITHUB_ENV
echo "RESOURCE_TAG_NAME=obscurogatewaydbtestnetlatest" >> $GITHUB_ENV

- name: 'Set Obscuro Gateway variables for dev-testnet'
if: ${{ github.event.inputs.testnet_type == 'dev-testnet' }}
run: |
echo "OBSCURO_GATEWAY_DB_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/dev_obscuro_gateway_mariadb_testnet:latest" >> $GITHUB_ENV
echo "RESOURCE_STARTING_NAME=dev-testnet" >> $GITHUB_ENV
echo "RESOURCE_TAG_NAME=obscurogatewaydbdevtestnetlatest" >> $GITHUB_ENV


- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

# This will fail some deletions due to resource dependencies ( ie. you must first delete the vm before deleting the disk)
- name: 'Delete deployed VMs'
uses: azure/CLI@v1
with:
inlineScript: |
$(az resource list --tag ${{env.RESOURCE_TAG_NAME}}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true

# This will clean up any lingering dependencies - might fail if there are no resources to cleanup
- name: 'Delete VMs dependencies'
uses: azure/CLI@v1
with:
inlineScript: |
$(az resource list --tag ${{env.RESOURCE_TAG_NAME}}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true


- name: 'Create VM for Gateway database node on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm create -g Testnet -n "${{env.RESOURCE_STARTING_NAME}}-OG-MariaDB-${{ GITHUB.RUN_NUMBER }}" \
--admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \
--public-ip-address-dns-name "obscurogateway-mariadb-${{env.RESOURCE_STARTING_NAME}}" \
--tags deploygroup=ObscuroGateway-mariaDB-${{env.RESOURCE_STARTING_NAME}}-${{ GITHUB.RUN_NUMBER }} ${{env.RESOURCE_TAG_NAME}}=true \
--size Standard_D4_v5 --image Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest \
--public-ip-sku Basic --authentication-type password

- name: 'Open Obscuro Gateway db ports on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm open-port -g Testnet -n "${{env.RESOURCE_STARTING_NAME}}-OG-MariaDB-${{ GITHUB.RUN_NUMBER }}" --port 3306

# To overcome issues with critical VM resources being unavailable, we need to wait for the VM to be ready
- name: 'Allow time for VM initialization'
shell: bash
run: sleep 30

- name: 'Start Obscuro gateway on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm run-command invoke -g Testnet -n "${{env.RESOURCE_STARTING_NAME}}-OG-MariaDB-${{ GITHUB.RUN_NUMBER }}" \
--command-id RunShellScript \
--scripts 'mkdir -p /home/obscuro \
&& sudo apt-get update \
&& sudo apt-get install -y gcc \
&& sudo snap refresh && sudo snap install --channel=1.18 go --classic \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh ./get-docker.sh \
&& git clone --depth 1 -b ${{ env.BRANCH_NAME }} https://github.com/obscuronet/go-obscuro.git /home/obscuro/go-obscuro \
&& docker network create --driver bridge node_network || true \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| true suppresses any errors. Is there any purpose for doing it?
I guess if any of the steps fail the deployment will not be sucessful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
It does suppress errors but only for that if clause, so if other clauses fail then the command fails.

We want to forcibly create a node_network so that if we do create more containers they can intra-container communicate between them.

It's more of a standard, everywhere that we create docker containers we create the node-network (it then guarantees that all containers can communicate between them). Not sure if it's worth removing. Will remove it if you feel strongly about it.

&& docker run -d --name datadog-agent \
--network node_network \
-e DD_API_KEY=${{ secrets.DD_API_KEY }} \
-e DD_LOGS_ENABLED=true \
-e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
-e DD_LOGS_CONFIG_AUTO_MULTI_LINE_DETECTION=true \
-e DD_CONTAINER_EXCLUDE_LOGS="name:datadog-agent" \
-e DD_SITE="datadoghq.eu" \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /opt/datadog-agent/run:/opt/datadog-agent/run:rw \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
datadog/agent:latest \
&& cd /home/obscuro/go-obscuro/ \
&& docker run \
--name db \
-e MARIADB_ROOT_PASSWORD=${{ secrets.OBSCURO_GATEWAY_MARIADB_ROOT_PWD }} \
-e MARIADB_USER=obscurouser \
-e MARIADB_PASSWORD=${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }} \
-v /home/obscuro/go-obscuro/tools/walletextension/storage/database/001_init.sql:/docker-entrypoint-initdb.d/schema.sql \
mariadb'
16 changes: 16 additions & 0 deletions tools/walletextension/storage/database/001_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE DATABASE ogdb;

USE ogdb;

GRANT SELECT, INSERT, UPDATE, DELETE ON ogdb.* TO 'obscurouser';

CREATE TABLE IF NOT EXISTS ogdb.users (
user_id binary(32) PRIMARY KEY,
private_key binary(32)
);
CREATE TABLE IF NOT EXISTS ogdb.accounts (
user_id binary(32),
account_address binary(20),
signature binary(65),
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE
);
Loading