Integrate Walrus CLI with CI/CD Tools to Deploy the 2048 Game
Tags: cicd, devops, tutorial, platformengineering
Published: 2023-11-01 17:00:00

[Walrus](https://github.com/seal-io/walrus), an open-source application management platform, simplifies the deployment process and seamlessly integrates with your existing CI/CD pipelines. In this tutorial, we will guide you on integrating the Walrus CLI with your CI/CD tools to deploy the 2048 Game.

## Prerequisites

Before you begin, ensure you have the following:

1. A GitHub repository where you can fork [our Demo project](https://github.com/seal-demo/2048).
2. [Walrus installed](https://seal-io.github.io/docs/deploy/standalone).
3. A project set up in Walrus.
4. Creation of a K8s connector within the project.
5. An environment established, and the K8s connector added to it.

Let's get started with the integration process!

![establish-env](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnkwaxaolm6cild2kn29.png)

## Generating an API Key

To enable communication between the Walrus CLI and the Walrus server, you'll need to create an API key. Here's how you can do it:

1. Navigate to your `User information`  and select `API Keys`
2. Click on `Add new key`, then provide a name for your key and set an expiration time.
3. Once you've configured the key, make sure to copy the generated key for future use. This key will facilitate the CLI's interaction with the Walrus server.

![generating-APIKey](https://raw.githubusercontent.com/Aleegra/seallogo/main/imggenerating-API-key.png)

## Integrating Walrus CLI with GitHub Actions

Here, we'll illustrate the integration of the Walrus CLI with GitHub Actions. Follow these steps:

- Head to your GitHub repository and access the `Settings` menu. Then, navigate to `Security > Secrets` and `Variables > Actions`. Configure your repository secrets with the following variables to securely store sensitive information: `CI_REGISTRY_USERNAME`, `CI_REGISTRY_PASSWORD`, `CD_WALRUS_SERVER`, and `CD_WALRUS_TOKEN`. For `CD_WALRUS_SERVER`, ensure the format is `https://domain:port/`. These secrets will enable secure communication between GitHub Actions and Walrus CLI.

![repo-secrets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfsa860kmuir2ip9qaam.png)

- Next, in your GitHub repository, create a `ci.yaml` file under the `.github/workflows` directory. This file will define your CI/CD workflow.

Here's an example of a `ci.yaml` file for deploying the 2048 Game. You can copy and customize it according to your specific environment variables and requirements:

```
name: CICD

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  CI_REGISTRY: '' # Use Docker Hub when empty
  CI_IMAGE_NAME: sealdemo/game2048
  CD_WALRUS_PROJECT: demo
  CD_WALRUS_PROJECT_ENV: dev
  CD_WALRUS_SERVICE_NAME: game2048
  
jobs:
  delivery:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 8
      uses: actions/setup-java@v3
      with:
        java-version: '8'
        distribution: 'temurin'
        cache: maven
    - name: Build with Maven
      run: mvn -B clean package --file pom.xml
    - name: Docker Login
      uses: docker/login-action@v3.0.0
      with:
        registry: ${{ env.CI_REGISTRY }}
        username: ${{ secrets.CI_REGISTRY_USERNAME }}
        password: ${{ secrets.CI_REGISTRY_PASSWORD }}
    - name: Build and push Docker image
      run: |
        docker build . --file Dockerfile --tag ${{ env.CI_IMAGE_NAME }}:${{ github.run_id }}
        docker push ${{ env.CI_IMAGE_NAME }}:${{ github.run_id }}
    - name: Download CLI
      run: |
        # Download walrus CLI
        curl -v -k -o walrus -LO "${{ secrets.CD_WALRUS_SERVER }}/cli?arch=amd64&os=linux"
        chmod +x ./walrus
    - name: Deploy
      run: |
        # Setup CLI config
        ./walrus config setup --insecure --server ${{ secrets.CD_WALRUS_SERVER }} --token ${{ secrets.CD_WALRUS_TOKEN }} --project ${{ env.CD_WALRUS_PROJECT }} --environment ${{ env.CD_WALRUS_PROJECT_ENV }}
       
        # Deploy app
        ./walrus service create --debug --name ${{ env.CD_WALRUS_SERVICE_NAME }} --template '{"name": "webservice", "version": "v0.0.2"}' --attributes '{"image": "${{ env.CI_IMAGE_NAME }}:${{ github.run_id }}", "ports": ["8080"]}'
```

Now, try triggering the workflow execution and checking the results.


![workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltzqq0udjedygwa5yc2m.png)

If you encounter any errors during the workflow execution, the first step should be to check your GitHub Actions permissions and configurations to ensure that everything is set up correctly.

![permissions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itgepk4cgxxix6kjaoe0.png)

Once the deployment is complete, you can access and view the 2048 Game within Walrus.


![2048-in-walrus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnuzcojnzf5o134bo6zs.png)


![2048-in-walrus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0r63epr1mavkj5b95mo.png)
You can access the 2048 Game using the following URL format: `http://domain:port/2048/`. This confirms that you have successfully integrated the Walrus CLI with your CI/CD tools to deploy the 2048 game.


![2048](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fdlrarzh8wrc4k0fcm1.png)