Преглед изворни кода

Merge pull request #2789 from mnaamani/refactor-devops-infrastructure

Refactor devops infrastructure folder
Mokhtar Naamani пре 3 година
родитељ
комит
6cc2fc2fc9
65 измењених фајлова са 63 додато и 26 уклоњено
  1. 7 5
      .github/workflows/create-ami.yml
  2. 3 3
      .github/workflows/joystream-node-docker.yml
  3. 0 0
      devops/aws/.gitignore
  4. 8 2
      devops/aws/README.md
  5. 0 0
      devops/aws/ansible.cfg
  6. 0 0
      devops/aws/build-arm64-playbook.yml
  7. 0 0
      devops/aws/build-code.yml
  8. 0 0
      devops/aws/chain-spec-pioneer.yml
  9. 10 2
      devops/aws/cloudformation/infrastructure.yml
  10. 6 0
      devops/aws/cloudformation/single-instance-docker.yml
  11. 3 0
      devops/aws/cloudformation/single-instance.yml
  12. 0 0
      devops/aws/common.sh
  13. 0 0
      devops/aws/create-joystream-node-ami-playbook.yml
  14. 1 9
      devops/aws/deploy-infra.sample.cfg
  15. 0 0
      devops/aws/deploy-infra.sh
  16. 0 0
      devops/aws/deploy-single-node-playbook.yml
  17. 18 0
      devops/aws/deploy-single-node.sample.cfg
  18. 1 1
      devops/aws/deploy-single-node.sh
  19. 1 1
      devops/aws/destroy-infra.sh
  20. 0 0
      devops/aws/group_vars/all
  21. 0 0
      devops/aws/library/json_modify.py
  22. 0 0
      devops/aws/requirements.yml
  23. 0 0
      devops/aws/roles/admin/tasks/deploy-pioneer.yml
  24. 0 0
      devops/aws/roles/admin/tasks/main.yml
  25. 0 0
      devops/aws/roles/common/tasks/chain-spec-node-keys.yml
  26. 0 0
      devops/aws/roles/common/tasks/get-code-git.yml
  27. 0 0
      devops/aws/roles/common/tasks/get-code-local.yml
  28. 0 0
      devops/aws/roles/common/tasks/run-setup-build.yml
  29. 0 0
      devops/aws/roles/node/templates/joystream-node.service.j2
  30. 0 0
      devops/aws/roles/rpc/tasks/main.yml
  31. 0 0
      devops/aws/roles/rpc/templates/Caddyfile.j2
  32. 0 0
      devops/aws/roles/rpc/templates/joystream-node.service.j2
  33. 0 0
      devops/aws/roles/validators/tasks/main.yml
  34. 0 0
      devops/aws/roles/validators/templates/joystream-node.service.j2
  35. 0 0
      devops/aws/setup-admin.yml
  36. 1 1
      devops/kubernetes/node-network/.gitignore
  37. 0 0
      devops/kubernetes/node-network/Pulumi.yaml
  38. 0 0
      devops/kubernetes/node-network/README.md
  39. 0 0
      devops/kubernetes/node-network/configMap.ts
  40. 0 0
      devops/kubernetes/node-network/index.ts
  41. 0 0
      devops/kubernetes/node-network/json_modify.py
  42. 0 0
      devops/kubernetes/node-network/nfsVolume.ts
  43. 0 0
      devops/kubernetes/node-network/package.json
  44. 0 0
      devops/kubernetes/node-network/tsconfig.json
  45. 0 0
      devops/kubernetes/node-network/utils.ts
  46. 0 0
      devops/kubernetes/node-network/validator.ts
  47. 0 0
      devops/kubernetes/pulumi-common/caddy.ts
  48. 0 0
      devops/kubernetes/pulumi-common/index.ts
  49. 0 0
      devops/kubernetes/pulumi-common/package.json
  50. 0 0
      devops/kubernetes/pulumi-common/tsconfig.json
  51. 1 1
      devops/kubernetes/query-node/.gitignore
  52. 0 0
      devops/kubernetes/query-node/Pulumi.yaml
  53. 0 0
      devops/kubernetes/query-node/README.md
  54. 0 0
      devops/kubernetes/query-node/configMap.ts
  55. 0 0
      devops/kubernetes/query-node/index.ts
  56. 0 0
      devops/kubernetes/query-node/package.json
  57. 0 0
      devops/kubernetes/query-node/s3Helpers.ts
  58. 0 0
      devops/kubernetes/query-node/tsconfig.json
  59. 1 1
      devops/kubernetes/storage-node/.gitignore
  60. 0 0
      devops/kubernetes/storage-node/Pulumi.yaml
  61. 0 0
      devops/kubernetes/storage-node/README.md
  62. 0 0
      devops/kubernetes/storage-node/index.ts
  63. 0 0
      devops/kubernetes/storage-node/package.json
  64. 0 0
      devops/kubernetes/storage-node/tsconfig.json
  65. 2 0
      setup.sh

+ 7 - 5
.github/workflows/create-ami.yml

@@ -1,3 +1,5 @@
+# Creates an AWS AMI (system image) with compiled joystream-node and subkey
+# 
 name: Create AWS AMI
 
 on:
@@ -8,7 +10,7 @@ jobs:
     name: Build the code and run setup
     runs-on: ubuntu-latest
     env:
-      STACK_NAME: joystream-github-action-${{ github.run_number }}
+      STACK_NAME: create-joystream-node-ami-ga-${{ github.run_number }}
       KEY_NAME: joystream-github-action-key
     steps:
       - name: Extract branch name
@@ -18,7 +20,7 @@ jobs:
 
       - name: Set AMI Name environment variable
         shell: bash
-        run: echo "ami_name=joystream-${{ steps.extract_branch.outputs.branch }}-${{ github.run_number }}" >> $GITHUB_ENV
+        run: echo "ami_name=joystream-node-${{ steps.extract_branch.outputs.branch }}-${{ github.run_number }}" >> $GITHUB_ENV
         id: ami_name
 
       - name: Checkout
@@ -36,7 +38,7 @@ jobs:
         id: deploy_stack
         with:
           name: ${{ env.STACK_NAME }}
-          template: devops/infrastructure/cloudformation/single-instance.yml
+          template: devops/aws/cloudformation/single-instance.yml
           no-fail-on-empty-changeset: '1'
           parameter-overrides: 'KeyName=${{ env.KEY_NAME }}'
 
@@ -46,8 +48,8 @@ jobs:
       - name: Run playbook
         uses: dawidd6/action-ansible-playbook@v2
         with:
-          playbook: github-action-playbook.yml
-          directory: devops/infrastructure
+          playbook: create-joystream-node-ami-playbook.yml
+          directory: devops/aws
           requirements: requirements.yml
           key: ${{ secrets.SSH_PRIVATE_KEY }}
           inventory: |

+ 3 - 3
.github/workflows/joystream-node-docker.yml

@@ -71,7 +71,7 @@ jobs:
             platform_tag: 'arm'
             file: 'joystream-node-armv7.Dockerfile'
     env:
-      STACK_NAME: joystream-ga-docker-${{ github.run_number }}-${{ matrix.platform_tag }}
+      STACK_NAME: build-joystream-node-docker-ga-${{ github.run_number }}-${{ matrix.platform_tag }}
     steps:
       - name: Extract branch name
         shell: bash
@@ -120,7 +120,7 @@ jobs:
         id: deploy_stack
         with:
           name: ${{ env.STACK_NAME }}
-          template: devops/infrastructure/cloudformation/single-instance-docker.yml
+          template: devops/aws/cloudformation/single-instance-docker.yml
           no-fail-on-empty-changeset: '1'
           parameter-overrides: 'KeyName=${{ env.KEY_NAME }},EC2AMI=ami-00d1ab6b335f217cf,EC2InstanceType=t4g.xlarge'
         if: ${{ steps.compute_image_exists.outputs.image_exists == 1 }}
@@ -129,7 +129,7 @@ jobs:
         uses: dawidd6/action-ansible-playbook@v2
         with:
           playbook: build-arm64-playbook.yml
-          directory: devops/infrastructure
+          directory: devops/aws
           requirements: requirements.yml
           key: ${{ secrets.SSH_PRIVATE_KEY }}
           inventory: |

+ 0 - 0
devops/infrastructure/.gitignore → devops/aws/.gitignore


+ 8 - 2
devops/infrastructure/README.md → devops/aws/README.md

@@ -26,10 +26,16 @@ On Mac run the command:
 Follow [the official installation guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) for your system.
 
 # How to run
-Copy and edit the file `deploy-config.sample.cfg` and update parameters like AWS_KEY_PAIR_NAME, KEY_PATH
+Copy and edit the file `deploy-infra.sample.cfg` and update parameters like AWS_KEY_PAIR_NAME, KEY_PATH
 Run the `deploy-infra.sh` script to deploy the infrastructure
 
 ```
-cd devops/infrastructure
+cd devops/aws
 ./deploy-infra.sh your-deploy-config.cfg
 ```
+
+# To tear down a network
+
+```
+./destroy-infra.sh your-deploy-config.cfg
+```

+ 0 - 0
devops/infrastructure/ansible.cfg → devops/aws/ansible.cfg


+ 0 - 0
devops/infrastructure/build-arm64-playbook.yml → devops/aws/build-arm64-playbook.yml


+ 0 - 0
devops/infrastructure/build-code.yml → devops/aws/build-code.yml


+ 0 - 0
devops/infrastructure/chain-spec-pioneer.yml → devops/aws/chain-spec-pioneer.yml


+ 10 - 2
devops/infrastructure/cloudformation/infrastructure.yml → devops/aws/cloudformation/infrastructure.yml

@@ -1,3 +1,9 @@
+# Deploy inftrastructure required to run a new joystream chain.
+# This is comprised of:
+#   - N validators
+#   - One RPC node
+#   - s3 bucket with a build of Pionner
+
 AWSTemplateFormatVersion: 2010-09-09
 
 Parameters:
@@ -116,8 +122,10 @@ Resources:
             # Update all packages
             apt-get update -y
 
-            # Install the updates except docker, to avoid interactive prompt which blocks the flow of the script
-            apt-mark hold docker.io
+            # Prevent interactive prompts that would interrupt the installation
+            export DEBIAN_FRONTEND=noninteractive
+
+            # Install the updates
             apt-get upgrade -y
 
             # Get latest cfn scripts and install them;

+ 6 - 0
devops/infrastructure/cloudformation/single-instance-docker.yml → devops/aws/cloudformation/single-instance-docker.yml

@@ -1,3 +1,6 @@
+# Deploys and EC2 node with docker tools suitable for
+# building joystream node docker images
+
 AWSTemplateFormatVersion: 2010-09-09
 
 Parameters:
@@ -58,6 +61,9 @@ Resources:
             # Update all packages
             apt-get update -y
 
+            # Prevent interactive prompts that would interrupt the installation
+            export DEBIAN_FRONTEND=noninteractive
+
             # Install the updates
             apt-get upgrade -y
 

+ 3 - 0
devops/infrastructure/cloudformation/single-instance.yml → devops/aws/cloudformation/single-instance.yml

@@ -59,6 +59,9 @@ Resources:
             # Update all packages
             apt-get update -y
 
+            # Prevent interactive prompts that would interrupt the installation
+            export DEBIAN_FRONTEND=noninteractive
+
             # Install the updates
             apt-get upgrade -y
 

+ 0 - 0
devops/infrastructure/common.sh → devops/aws/common.sh


+ 0 - 0
devops/infrastructure/github-action-playbook.yml → devops/aws/create-joystream-node-ami-playbook.yml


+ 1 - 9
devops/infrastructure/deploy-config.sample.cfg → devops/aws/deploy-infra.sample.cfg

@@ -1,6 +1,6 @@
 #### PARAMETERS USED BY AWS
 
-STACK_NAME=joystream-node
+STACK_NAME=joystream-network
 REGION=us-east-1
 CLI_PROFILE=joystream-user
 KEY_PATH="/Users/joystream/Joystream/joystream-key.pem"
@@ -23,14 +23,6 @@ INVENTORY_PATH="$DATA_PATH/inventory"
 
 NUMBER_OF_VALIDATORS=2
 
-## Used for Deploying a new node
-DATE_TIME=$(date +"%d-%b-%Y-%H-%M-%S")
-
-SINGLE_NODE_STACK_NAME="new-node-$DATE_TIME"
-
-BINARY_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joystream-node-5.1.0-9d9e77751-x86_64-linux-gnu.tar.gz"
-CHAIN_SPEC_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joy-testnet-5.json"
-
 #### PARAMETERS USED BY ANSIBLE
 
 LOCAL_CODE_PATH="~/Joystream/joystream"

+ 0 - 0
devops/infrastructure/deploy-infra.sh → devops/aws/deploy-infra.sh


+ 0 - 0
devops/infrastructure/single-node-playbook.yml → devops/aws/deploy-single-node-playbook.yml


+ 18 - 0
devops/aws/deploy-single-node.sample.cfg

@@ -0,0 +1,18 @@
+#### PARAMETERS USED BY AWS
+
+REGION=us-east-1
+CLI_PROFILE=joystream-user
+KEY_PATH="/Users/joystream/Joystream/joystream-key.pem"
+AWS_KEY_PAIR_NAME="joystream-key"
+
+DEFAULT_EC2_INSTANCE_TYPE=t2.micro
+
+ACCOUNT_ID=$(aws sts get-caller-identity --profile $CLI_PROFILE --query Account --output text)
+
+## Used for Deploying a new node
+DATE_TIME=$(date +"%d-%b-%Y-%H-%M-%S")
+
+SINGLE_NODE_STACK_NAME="joystream-node-$DATE_TIME"
+
+BINARY_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joystream-node-5.1.0-9d9e77751-x86_64-linux-gnu.tar.gz"
+CHAIN_SPEC_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joy-testnet-5.json"

+ 1 - 1
devops/infrastructure/deploy-single-node.sh → devops/aws/deploy-single-node.sh

@@ -46,6 +46,6 @@ if [ $? -eq 0 ]; then
   echo -e "New Node Public IP: $SERVER_IP"
 
   echo -e "\n\n=========== Configuring node ==========="
-  ansible-playbook -i $SERVER_IP, --private-key $KEY_PATH single-node-playbook.yml \
+  ansible-playbook -i $SERVER_IP, --private-key $KEY_PATH deploy-single-node-playbook.yml \
     --extra-vars "binary_file=$BINARY_FILE chain_spec_file=$CHAIN_SPEC_FILE"
 fi

+ 1 - 1
devops/infrastructure/delete-stack.sh → devops/aws/destroy-infra.sh

@@ -6,7 +6,7 @@ source common.sh
 
 if [ -z "$1" ]; then
   echo "ERROR: Configuration file not passed"
-  echo "Please use ./delete-stack.sh PATH/TO/CONFIG to run this script"
+  echo "Please use ./destroy-infra.sh PATH/TO/CONFIG to run this script"
   exit 1
 else
   echo "Using $1 file for config"

+ 0 - 0
devops/infrastructure/group_vars/all → devops/aws/group_vars/all


+ 0 - 0
devops/infrastructure/library/json_modify.py → devops/aws/library/json_modify.py


+ 0 - 0
devops/infrastructure/requirements.yml → devops/aws/requirements.yml


+ 0 - 0
devops/infrastructure/roles/admin/tasks/deploy-pioneer.yml → devops/aws/roles/admin/tasks/deploy-pioneer.yml


+ 0 - 0
devops/infrastructure/roles/admin/tasks/main.yml → devops/aws/roles/admin/tasks/main.yml


+ 0 - 0
devops/infrastructure/roles/common/tasks/chain-spec-node-keys.yml → devops/aws/roles/common/tasks/chain-spec-node-keys.yml


+ 0 - 0
devops/infrastructure/roles/common/tasks/get-code-git.yml → devops/aws/roles/common/tasks/get-code-git.yml


+ 0 - 0
devops/infrastructure/roles/common/tasks/get-code-local.yml → devops/aws/roles/common/tasks/get-code-local.yml


+ 0 - 0
devops/infrastructure/roles/common/tasks/run-setup-build.yml → devops/aws/roles/common/tasks/run-setup-build.yml


+ 0 - 0
devops/infrastructure/roles/node/templates/joystream-node.service.j2 → devops/aws/roles/node/templates/joystream-node.service.j2


+ 0 - 0
devops/infrastructure/roles/rpc/tasks/main.yml → devops/aws/roles/rpc/tasks/main.yml


+ 0 - 0
devops/infrastructure/roles/rpc/templates/Caddyfile.j2 → devops/aws/roles/rpc/templates/Caddyfile.j2


+ 0 - 0
devops/infrastructure/roles/rpc/templates/joystream-node.service.j2 → devops/aws/roles/rpc/templates/joystream-node.service.j2


+ 0 - 0
devops/infrastructure/roles/validators/tasks/main.yml → devops/aws/roles/validators/tasks/main.yml


+ 0 - 0
devops/infrastructure/roles/validators/templates/joystream-node.service.j2 → devops/aws/roles/validators/templates/joystream-node.service.j2


+ 0 - 0
devops/infrastructure/setup-admin.yml → devops/aws/setup-admin.yml


+ 1 - 1
devops/infrastructure/node-network/.gitignore → devops/kubernetes/node-network/.gitignore

@@ -1,6 +1,6 @@
 /bin/
 /node_modules/
-kubeconfig.yml
+kubeconfig*
 package-lock.json
 .env
 Pulumi.*.yaml

+ 0 - 0
devops/infrastructure/node-network/Pulumi.yaml → devops/kubernetes/node-network/Pulumi.yaml


+ 0 - 0
devops/infrastructure/node-network/README.md → devops/kubernetes/node-network/README.md


+ 0 - 0
devops/infrastructure/node-network/configMap.ts → devops/kubernetes/node-network/configMap.ts


+ 0 - 0
devops/infrastructure/node-network/index.ts → devops/kubernetes/node-network/index.ts


+ 0 - 0
devops/infrastructure/node-network/json_modify.py → devops/kubernetes/node-network/json_modify.py


+ 0 - 0
devops/infrastructure/node-network/nfsVolume.ts → devops/kubernetes/node-network/nfsVolume.ts


+ 0 - 0
devops/infrastructure/node-network/package.json → devops/kubernetes/node-network/package.json


+ 0 - 0
devops/infrastructure/node-network/tsconfig.json → devops/kubernetes/node-network/tsconfig.json


+ 0 - 0
devops/infrastructure/node-network/utils.ts → devops/kubernetes/node-network/utils.ts


+ 0 - 0
devops/infrastructure/node-network/validator.ts → devops/kubernetes/node-network/validator.ts


+ 0 - 0
devops/infrastructure/pulumi-common/caddy.ts → devops/kubernetes/pulumi-common/caddy.ts


+ 0 - 0
devops/infrastructure/pulumi-common/index.ts → devops/kubernetes/pulumi-common/index.ts


+ 0 - 0
devops/infrastructure/pulumi-common/package.json → devops/kubernetes/pulumi-common/package.json


+ 0 - 0
devops/infrastructure/pulumi-common/tsconfig.json → devops/kubernetes/pulumi-common/tsconfig.json


+ 1 - 1
devops/infrastructure/query-node/.gitignore → devops/kubernetes/query-node/.gitignore

@@ -1,6 +1,6 @@
 /bin/
 /node_modules/
-kubeconfig.yml
+kubeconfig*
 package-lock.json
 .env
 Pulumi.*.yaml

+ 0 - 0
devops/infrastructure/query-node/Pulumi.yaml → devops/kubernetes/query-node/Pulumi.yaml


+ 0 - 0
devops/infrastructure/query-node/README.md → devops/kubernetes/query-node/README.md


+ 0 - 0
devops/infrastructure/query-node/configMap.ts → devops/kubernetes/query-node/configMap.ts


+ 0 - 0
devops/infrastructure/query-node/index.ts → devops/kubernetes/query-node/index.ts


+ 0 - 0
devops/infrastructure/query-node/package.json → devops/kubernetes/query-node/package.json


+ 0 - 0
devops/infrastructure/query-node/s3Helpers.ts → devops/kubernetes/query-node/s3Helpers.ts


+ 0 - 0
devops/infrastructure/query-node/tsconfig.json → devops/kubernetes/query-node/tsconfig.json


+ 1 - 1
devops/infrastructure/storage-node/.gitignore → devops/kubernetes/storage-node/.gitignore

@@ -1,5 +1,5 @@
 /bin/
 /node_modules/
-kubeconfig.yml
+kubeconfig*
 package-lock.json
 Pulumi.*.yaml

+ 0 - 0
devops/infrastructure/storage-node/Pulumi.yaml → devops/kubernetes/storage-node/Pulumi.yaml


+ 0 - 0
devops/infrastructure/storage-node/README.md → devops/kubernetes/storage-node/README.md


+ 0 - 0
devops/infrastructure/storage-node/index.ts → devops/kubernetes/storage-node/index.ts


+ 0 - 0
devops/infrastructure/storage-node/package.json → devops/kubernetes/storage-node/package.json


+ 0 - 0
devops/infrastructure/storage-node/tsconfig.json → devops/kubernetes/storage-node/tsconfig.json


+ 2 - 0
setup.sh

@@ -3,6 +3,8 @@
 set -e
 
 if [[ "$OSTYPE" == "linux-gnu" ]]; then
+    # Prevent interactive prompts that would interrup the installation
+    export DEBIAN_FRONTEND=noninteractive
     # code build tools
     sudo apt-get update
     sudo apt-get install -y coreutils clang llvm jq curl gcc xz-utils sudo pkg-config unzip libc6-dev make libssl-dev python