Deployment Automation for Goerli testnet in 10 minutes

Subscribe to my newsletter and never miss my upcoming articles

Updated the article to include the installation steps for Terraform to make the process easier.

Hello world, happy new year to everyone. Hope you are having a great start to 2019.

Today, I’m going to share a short tutorial to quickly deploy the new **Goerli Proof-of-Authority cross-client test network which was originally developed at [ETHBerlin](ethberlin.com) in September 2018 and then we, [Afri](twitter.com/5chdn) (@5chdn) and ChainSafe (@chainsafeth), have been actively developing Goerli. As of now, Goerli is supported in [Geth](github.com/ethereum/go-ethereum), Parity, Pantheon, Nethermind and [EthereumJS](github.com/ethereumjs/ethereumjs-client)**.

If you would like to follow the current development of *Goerli, fork the Goerli testnet [repo](github.com/goerli/testnet)*.

ETHBerlin — Goerli DemoETHBerlin — Goerli Demo

Let’s get started. These steps will work on any UNIX system (Mac & Linux). First, go ahead and create a GCP (Google Cloud Platform) account *here *and then create a project. By default, Google gives $300 worth of free credits for a year.

Then, we need **Terraform, **it is an open source tool to easily create reusable and modular infrastructure deployment automation code.

To install it on Mac, you can use **brew, if you don’t have brew**, you can install it using this script. Once, you are done, then go ahead and install using the next command.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install terraform

If you are on any Linux, follow the quick walkthrough *here to install Terraform. *Terraform has some excellent documentation on how to get up and running quickly.

Next step, you have to create a service account key in GCP.

GCP IAMGCP IAM

On the creation screen, give it a name and description. For the role access, make sure you give it Compute Engine Admin role. Next, create your key and download the JSON key. Make sure to securely store this file, this file is very very private and sensitive! And DO NOT EVER PUSH THIS FILE TO YOUR PUBLIC REPO!

GCP service account key creationGCP service account key creation

Now that we have our necessary steps done, we will start writing our Terraform deployment script.

In your project directory, copy the *JSON file which you just downloaded and then create a file called **goerli.tf *(you can name it whatever you want).

provider "google" {
    credentials = "${file("credentials.json")}"
    project     = "ENTER_YOUR_PROJECT_ID_HERE"
}

resource "google_compute_instance" "name" {
  name = "ENTER_YOUR_INSTANCE_NAME_HERE",
  zone = "us-east1-b",
  machine_type = "n1-standard-1",
  min_cpu_platform = "Intel Skylake"
  tags = ["http-server", "https-server"]

  boot_disk {
    initialize_params {
        image = "ubuntu-1804-lts"
        type = "pd-standard"
        size = "40"
    }
  }

  network_interface {
    network = "default"

    access_config {}
  }

  metadata_startup_script = "sudo apt update -y && sudo apt upgrade -y && sudo apt-get install software-properties-common -y && sudo add-apt-repository ppa:ethereum/ethereum -y && sudo apt update -y && sudo apt install ethereum -y && sudo curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh && sudo bash nodesource_setup.sh && sudo apt install -y nodejs"
}

This is what your Terraform file will look like. In the first block, we define the provider which is google for us, inside that we define the location for the credentials.json and your project ID which you will find in your project settings.

Next, we define our virtual instance’s name, region, cpu, ram, hard disk, operating system, firewalls, and other necessary configs.

At the very bottom, we define our startup script where the list of commands will run after the virtual instance is created to do the basic housekeeping stuff like updating the OS, installing **Node.js and [Geth](geth.ethereum.org) (the client which will be running Goerli** at).

Now, in your terminal, run the command:

terraform apply

And, you should see your instance is being created in the GCP compute engine console.

Congratulations, you have successfully deployed your virtual machine on the cloud! 👏 👏 👏

Next, we will SSH into our newly created VM. GCP provides few ways to connect to your remote machine rather than traditional methods; creating and managing your SSH keys like other cloud providers so, we will use the gcloud utils. You need to have gcloud installed on your computer so, go ahead and follow the instructions *here*.

gcloud command in GCP consolegcloud command in GCP console

Once, you SSH’d into your VM, go ahead and clone the Goerli testnet repo from *Github *into your home directory and then we will run a few commands.

geth init ./testnet/geth/goerli.genesis

This is to initialize Goerli’s Genesis block.

We are almost done, next, we will copy the boot nodes (the IP addresses of the peer nodes) to the *geth data directory.*

cp testnet/geth/static-nodes.json .ethereum

Now, we will boot up our Goerli node

nohup geth --networkid 6284 &

This will continue to run in the background. 6284 is the network ID of Goerli so when running Geth we need to specify as the — goerli hasn’t been merged to Geth master yet. Here is the *link* to the PR.

You will see a file called nohup.out, where it stores the log. Now, if you do:

tail -f nohup.out

You should see the terminal output of Geth running the Goerli network.

Congrats, we are done here, you are successfully one of the peers in the Goerli network! 🎉🎉🎉

You can use the same Terraform file by just tweaking a little bit to automate your deployment to any cloud provider like AWS, Azure, AliCloud, DigitalOcean, or even Heroku. You can also customize the current configuration to play with it.

Here is a list of a few useful resources: ethereum/go-ethereum Official Go implementation of the Ethereum protocol - ethereum/go-ethereumgithub.com Provider: Google Cloud Platform - Terraform by HashiCorp The Google provider is used to configure your Google Cloud Platform infrastructureterraform.io Concepts | Compute Engine | Google Cloud Google Cloud delivers secure, open, intelligent, and transformative tools to help enterprises modernize for today's…cloud.google.com

If you like this article, please give some 👏🏻. If you have any questions and feedbacks, please leave comments below. You can also reach me in Twitter at @pri0m and follow me on Github.

Follow ChainSafe Systems, to learn more about Ethereum and upcoming development updates. Reach out to us in Twitter at @chainsafeth.

No Comments Yet