Guestbook is a sample application that records visitors' messages, displays a cloud banner, and an administrative message. The main business logic is written in a cloud-agnostic manner using MySQL, the generic blob API, and the generic runtimevar API. Each of the platform-specific code is set up by Wire.
You will need to install the following software to run this sample:
gowire
is not compatible with vgo
yet, so you must run vgo vendor
first to download all the dependencies in go.mod
. Running gowire
generates the Wire code.
# First time, for gowire.
$ vgo vendor
# Now build:
$ gowire && vgo build
You will need to run a local MySQL database server using Docker, and then you can run the server.
./start-localdb.sh
./guestbook -env=local
Stop the MySQL database server with:
$ docker stop guestbook-sql
If you want to run this sample on GCP, you need to create a project, download the gcloud SDK, and log in. You can then use Terraform, a tool for initializing cloud resources, to set up your project. Finally, this sample provides a script for building the Guestbook binary and deploying it to the Kubernetes cluster created by Terraform.
gcloud auth application-default login
cd gcp
terraform init
terraform apply
./deploy.sh
To clean up the created resources, run terraform destroy
inside the gcp
directory using the same variables you entered during terraform apply
.
If you want to run this sample on AWS, you need to set up an account, download the AWS command line interface, and log in. You can then use Terraform, a tool for initializing cloud resources, to set up your project. This will create an EC2 instance you can connect to and run your binary, copying over the configuration
aws configure
vgo build
cd aws
terraform init
terraform apply -var region=us-west-1
# SSH into the EC2 instance.
ssh "admin@$( terraform output instance_host )"
When you're connected to the server, run the server binary. Replace the
command-line flag values with values from the output of terraform apply
.
AWS_REGION=us-west-1 ./guestbook -env=aws \
-bucket=... -db_host=... -motd_var=...
To clean up the created resources, run terraform destroy
inside the aws
directory using the same variables you entered during terraform apply
.