커넥터

GitHub Actions와 CBSH로 Couchbase 테스트하기

5 분 읽기

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 Actions 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 연결하다 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 카우치베이스 셸 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 환경 makes the secrets available as environment variables.

Because this shell is based on 누쉘 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!

참고문헌

이 기사 공유하기

작가

로랑은 파리에 사는 찌질한 매니아 기질이 있는 헤비메탈 마니아입니다. 그는 주로 자바(Java)로 코드를 작성하고 AsciiDoc으로 구조화된 텍스트를 작성하며, 데이터, 리액티브 프로그래밍 및 기타 유행어 같은 주제에 대해 자주 이야기합니다. 그는 또한 Clever Cloud와 Nuxeo의 전직 개발자 애드보케이트로 활동하며 해당 커뮤니티가 더 크고 강하게 성장하도록 시간과 전문 지식을 쏟아부었습니다. 현재는 카우치베이스(Couchbase)에서 개발자 관계(Developer Relations)를 총괄하고 있습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.