Spring Boot

This document provides instructions for working with Spring Boot and the CommandK CLI for both Maven and Gradle projects. It explains how to run your Spring Boot application, manage secrets effectively, and utilize both build tools with the CommandK CLI.

Prerequisites

Before you begin the integration process, make sure you have the following:

  1. API Access Token: To authenticate your Spring Boot application with CommandK, you'll need an API access token. If you haven't obtained one yet, refer to this link for instructions on how to acquire it.

Integration Steps

Follow these steps to integrate CommandK with your Spring Boot application, regardless of whether you are using Maven or Gradle as your build tool:

Step 1: Create a Spring Boot Application

If you haven't already created a Spring Boot application, you can set up a new project using the Spring Initializr or any other preferred method. Here, we'll use the Spring Initializr for demonstration:

  1. Visit the Spring Initializr web page.
  2. Configure your project by selecting options such as project type, language, and packaging. You can also add dependencies as needed.
  3. Click the "Generate" button to generate a Spring Boot project archive.
  4. Extract the generated archive to a directory for your project.

Step 2: Access Secrets in Your Spring Boot Application

Inside your Spring Boot application, you can access secrets as environment variables or properties. Open the appropriate file (e.g., application.properties or application.yml) and add the following configuration to access an environment variable:

For application.properties:

secretKey=${COMMANDK_SECRET_KEY}

For application.yml:

secretKey: ${COMMANDK_SECRET_KEY}

In this code, ${COMMANDK_SECRET_KEY} is a placeholder for your actual secret key, which you'll retrieve using the CommandK CLI.

Running Your Spring Boot Application

To run your Spring Boot application with the CommandK CLI and your preferred build tool (Maven or Gradle), follow the respective instructions below:

For Maven:

$ cmdk run <application-name> --environment development -- ./mvnw spring-boot:run

Replace <application-name> with the actual name of your Spring Boot application. This command will execute your Spring Boot application using Maven's spring-boot:run goal.

For Gradle:

$ cmdk run <application-name> --environment development -- ./gradlew bootRun

Replace <application-name> with the actual name of your Spring Boot application. This command will execute your Spring Boot application using Gradle's bootRun task.

Leveraging Spring Profiles

You can also leverage Spring profiles to load secrets from a YAML file seamlessly:

$ SPRING_PROFILES_ACTIVE=my-secrets cmdk run <application-name> --environment development \
     --run-type file-store \
     --file-name config/application-my-secrets.yaml \
     --file-format yaml \
     -- ./gradlew bootRun

In the above example, secrets are stored in a file called application-my-secrets.yaml, and the my-secrets profile is activated when running Spring Boot. Depending on how your application handles profiles, the setup might have to change accordingly to accommodate additional profiles.

By following these instructions, you can seamlessly integrate the CommandK CLI with your Spring Boot application, making it easy to manage secrets and run your application securely, whether you are using Maven or Gradle as your build tool.