Conectores

Pruebas con Couchbase, GitHub Actions y CBSH

Lectura de 5 minutos

I have recently been working on an exciting project, a wasmCloud capability provider for Couchbase. We are building this in the open with the fine folks at Cosmonic. You can checkout the code in our repository.

And early in every project comes the topic of development life cycle and its infrastructure. How do we automatically run tests of our project involving a Couchbase Server? GitHub provides Acciones that allows us to execute code in various moments.

To create an action, you can either click on the Action tab of your repository or add a file under .github/workflows. There are a lot of different ways to trigger the execution of the action. Like on every git push. I just want something simple that makes sure my Couchbase Cluster is still here and accessible through specific secrets or environment variables. So here I will just choose a basic cron expression. The action will be executed every Monday at midnight.

Now, about secrets and environment variables. Of course, some of them are, well, secrets. And must be managed as such. Thankfully GitHub thought of everything and gives us a way to set up secrets or environment variables per repository or organization. If you go under Settings/Secrets and variables/actions, you should see the following page:

This allows you to define any secret or environment variable you may need for your actions, and more. Here you can see I have set up:

  • COUCHBASE_BUCKET – The name of the Bucket I want to use
  • COUCHBASE_CONNECTION_STRING – The full Couchbase connection String, as given in the conectar Capella tab for instance
  • COUCHBASE_USERNAME – The username used to connect to the cluster
  • COUCHBASE_PASSWORD – The password used to connect to the cluster

Now comes the time to write the test. All I want to do is make sure I have a working connection to a cluster, in order to show my collaborators how the secrets/env variables can be used. A simple way to test a connection is to use the Couchbase Shell aka cbsh. It can be installed easily on Ubuntu. All you need is to download and untar it. This can be done in a couple steps:

From there the shell is available simply by running ./cbsh. Notice here that the runs-on option gives us which container to use to run the action, shell is set to bash and env makes the secrets available as environment variables.

Because this shell is based on nushell and a password will be prompted, I could not pipe it straight up after the invocation like this:

Because this does not work, I had to use a cbsh configuration file instead. And sadly the syntax is a bit tricky for multi-line text formatting and piping. Here, I am creating a new variable called CONFIG, that contains the environment variable values, putting the result in $GITHUB_ENV, which allows me to pass it to the next step, which echos it in the config file:

Once the config file is all set, cbsh can be invoked like so:

The complete example is available in our repository as a YML file. And this is what a successful run looks like:

So there you go, you now know how to connect to Couchbase in a GitHub Action. And you also got acquainted with Couchbase Shell – give it a try to do  more fun things like migrating all collections, except the _default collection:

And we have more AI-friendly features coming to Couchbase Shell, stay tuned!

References

Compartir este artículo

Autor

Laurent es un metalero nerd que vive en París. Principalmente escribe código en Java y texto estructurado en AsciiDoc, y a menudo habla sobre datos, programación reactiva y otras cosas llenas de jerga. También es un ex Defensor de Desarrolladores de Clever Cloud y Nuxeo, donde dedicó su tiempo y experiencia a ayudar a que esas comunidades crecieran más grandes y fuertes. Ahora dirige las Relaciones con Desarrolladores en Couchbase.

Deja un comentario

¿Listo para comenzar con Couchbase Capella?

Comenzar a construir

Visita nuestro portal para desarrolladores para explorar NoSQL, consultar recursos y comenzar con los tutoriales.

Usa Capella gratis

Empieza a usar Couchbase en tan solo unos clics. Capella DBaaS es la forma más fácil y rápida de comenzar.

Ponte en contacto

¿Quieres saber más sobre las ofertas de Couchbase? Permítenos ayudarte.