Agave-cli

Agave-cli

Agave-cli is a Golang package that allows building services and applications with the command line interface. Its goal is to give an easy and standardized way to develop TI team’s projects in 99minutos.

Installation

Prerequisites

  • Go environment is required to install and run this package.

  • For golang developers, you will need to follow these instructions to use all functionalities of this package.

  • For grpc projects, you will need protoc

Once you have these requirements installed, you can just run:

go install github.com/99minutos/agave-cli@latest

Getting Started

(Go) GRPC project

In this tutorial, we will build a service from scratch that register drivers in our mongo database and gets driver by id.

Step 1. Initialize grpc project

Run agave-cli new grpc to create project files. You’ll be asked for the name of the repo and whether your service will use databases or not.

This will create the following file tree (and if you are working in existing project, make sure it has this structure):

📦drivers-module ┣ 📂build ┃ ┗ 📂package ┃ ┃ ┣ docs.Dockerfile ┃ ┃ ┗ server.Dockerfile ┣ 📂cmd ┃ ┗ 📂server ┃ ┃ ┗ main.go ┣ 📂internal ┃ ┣ 📂config ┃ ┃ ┗ config.go ┃ ┗ 📂server ┃ ┃ ┗ 📂testservice ┃ ┃ ┃ ┗ server.go ┣ 📂protobuff ┃ ┗ main.proto ┣ .gitignore ┣ Makefile ┣ README.md ┣ dev.env ┣ go.mod ┗ prod.env

Step 2. Add project to GitHub

To do so, you can follow “Adding a project to GitHub without GitHub CLI” to create empty GitHub repo and add the project files.

cd drivers-module # Initialize the local directory git init -b main git add . git commit -m "First commit" # Add the URL for the remote repository git remote add origin git@github.com:99minutos/drivers-module.git git push -u origin main

Step 3. Adding go.sum file

To be able to compile, we need to add the go.sum file.

Step 4. Create a new grpc service

Run agave-cli grpc new service to create a new service.

This will add service to proto file and create internal/server/driversservice/server.go file with a dummy Hello rpc.

Step 5. Create rpc for the service

To add a new procedure in our service, run agave-cli grpc new rpc. For example, we need two methods for our service: RegisterDriver and GetDriverById.

This will add the rpc service with a dummy request and response. Let’s change proto file and implement both methods.

  • In protobuff/main.proto, create necessary objects and change dummy request/response.

  • Run make protos to generate proto changes.

  • In internal/server/driversservice/server.go implement procedures.

  • Test your changes. To do so, make sure you have the correct environment variables. In this case, we need mongo database configuration. Then, you can run cmd/server/main.go and test your rpcs with BloomRPC

Step 6. Create deployment files

When the service is ready to deploy, you can generate or update the deployment files by running agave-cli grpc deploy setup.

  • For cloud-run deployment, you need to first set all environment variables needed inside <env>.env.

Step 7. Create Cloud Build Trigger

When you have deployment files ready, you can create or update a cloud build trigger. Simply run agave-cli grpc deploy trigger.

This will create a trigger by tag in GitHub.

Step 8. Create a tag to actually make a deployment

To actually deploy your service you just need to push a GitHub tag that matches regex v\d+\.\d+\.\d+\-<env>. Make sure all your changes are published and that you are in the correct branch for deploy.

This will activate the trigger and make the deployment.

Document your project

You need to manually create a page for your documentation and get page id from: 99minutosworkspace.atlassian.net/wiki/spaces/~x/pages/<confluence-page>/

When creating a trigger for your service, agave-cli asks you for a confluence-page to push what’s on your README.md into confluence. By default, this value is 0 that means you don’t have a page to push your documentation.

You can also add it manually in Google Cloud Platform, by changing _DOCS_PAGE_ID substitution variable.

Then, after each prod deployment you’ll have your documentation push to a confluence page like this


Check the full list of commands here


Autogenerated page from GitHub repository.