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.
|
1 2 3 4 |
이름: test 카우치베이스 Credential ~에: schedule: – cron: ‘0 0 * * 1’ |
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:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
jobs: test_credential: runs–~에: ubuntu–latest 이름: Test that given 환경 variable works 단계: shell: bash 환경: COUCHBASE_CONNECTION_STRING: ${{ secrets.COUCHBASE_CONNECTION_STRING }} COUCHBASE_USERNAME: ${{ secrets.COUCHBASE_USERNAME }} COUCHBASE_PASSWORD: ${{ secrets.COUCHBASE_PASSWORD }} – 실행: Wget https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-unknown-linux-gnu.tar.gz – 실행: tar –xvzf cbsh–x86_64–unknown–리눅스–gnu.tar.gz |
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:
|
1 |
메아리 $COUCHBASE_PASSWORD | ./cbsh —사용자 이름 $COUCHBASE_USERNAME—연결 문자열 $COUCHASE_CONNECTION_STRING |
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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
– 실행: | CONFIG=$(cat << EOF 버전 = 1 [[클러스터]] 식별자 = “로컬” 연결 문자열 = “$COUCHBASE_CONNECTION_STRING” 사용자 이름 = “$COUCHBASE_USERNAME” 비밀번호 = “$COUCHBASE_PASSWORD” EOF ) 메아리 “CONFIG<<EOF” >> $GITHUB_ENV 메아리 “$CONFIG” >> $GITHUB_ENV 메아리 “EOF” >> $GITHUB_ENV – 실행: 메아리 “$CONFIG” >> 설정 |
Once the config file is all set, cbsh can be invoked like so:
|
1 |
– 실행: ./cbsh —설정–dir . –c 씨비–환경 |
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:
|
1 |
컬렉션 —clusters “On-Prem-Cluster” —양동이 “트래블 샘플” | 선택 범위 컬렉션 | where $그것.범위 != “_default” | where $그것.컬렉션 != “_default” | 각각 { |그것| 컬렉션 만들다 $그것.컬렉션 —clusters “Capella-Cluster” —양동이 “travel-sample-import” —범위 $그것.범위 |
And we have more AI-friendly features coming to Couchbase Shell, stay tuned!

댓글 남기기
댓글을 달기 위해서는 로그인해야합니다.