Codebase Analyzer

Global Concept

Flagship Code Analyzer is a CLI and a docker image that can analyze your codebase and detect the usage of Flagship flags, in order to synchronize them with your Flag view in the platform.

Prerequisites

The Codebase Analyzer requires the setup of a Client ID and Client Secret for the Remote Control API.
You can find more information here: Remote Control API.

Install

From docker

docker pull flagshipio/code-analyzer

CLI

Download the CLI here for your specific system architecture:

https://github.com/flagship-io/codebase-analyzer/releases/latest

Run

With CLI

export FLAGSHIP_CLIENT_ID=FLAGSHIP_MANAGEMENT_API_CLIENT_ID
export FLAGSHIP_CLIENT_SECRET=FLAGSHIP_MANAGEMENT_API_CLIENT_SECRET
export ACCOUNT_ID=FLAGSHIP_ACCOUNT_ID
export ENVIRONMENT_ID=FLAGSHIP_ENVIRONMENT_ID
export REPOSITORY_URL=https://gitlab.com/org/repo
export REPOSITORY_BRANCH=master
export DIRECTORY=./
./code-analyzer

With docker

docker run -v $(pwd)/your_repo:/your_repo -e FLAGSHIP_CLIENT_ID=FLAGSHIP_MANAGEMENT_API_CLIENT_ID -e FLAGSHIP_CLIENT_SECRET=FLAGSHIP_MANAGEMENT_API_CLIENT_SECRET -e ACCOUNT_ID=FLAGSHIP_ACCOUNT_ID -e ENVIRONMENT_ID=your_env_id -e REPOSITORY_URL=https://gitlab.com/org/repo -e REPOSITORY_BRANCH=master -e DIRECTORY=/your_repo flagshipio/code-analyzer

Supported file languages

  • .js, .jsx
  • .go
  • .py
  • .java
  • .swift
  • .kt
  • .m

Environment variables

Flagship client ID (required)

This environment variable contains the Flagship client id necessary to authenticate request and send flags infos to the Flagship Platform

  • example : FLAGSHIP_CLIENT_ID=FLAGSHIP_MANAGEMENT_API_CLIENT_ID

Flagship client secret (required)

This environment variable contains the Flagship client secret necessary to authenticate request and send flags infos to the Flagship Platform

  • example : FLAGSHIP_CLIENT_SECRET=FLAGSHIP_MANAGEMENT_API_CLIENT_SECRET

See Public Management Api] for more details about client ID / client secret.

Account ID (required)

This environment variable contains the Flagship account ID to synchronize flags usage for the matching environment

example : ACCOUNT_ID=your_flagship_env_id

Environment ID (required)

This environment variable contains the Flagship environment ID to synchronize flags usage for the matching environment

  • example : ENVIRONMENT_ID=your_flagship_env_id

Repository URL (required)

This environment variable should be set to the root URL of your repository, and is used to track the links of the files where your flags are used

  • example : REPOSITORY_URL=https://gitlab.com/org/repo
  • default value: ""

Repository branch (required)

This environment variable should be set to the branch of the code you want to analyse, and is used to track the links of the files where your flags are used

  • example : REPOSITORY_BRANCH=master
  • default value: ""

Files to exclude (optional)

This environment variable should contain a comma separated list of glob to exclude

  • example : FILES_TO_EXCLUDE=".git/*,go.mod,go.sum,main.go,internal/*,example/*"
  • default value: ""

Directory to analyse (optional)

This environment variable should contain the directory you want to analyse

  • example : DIRECTORY="."
  • default value: "."

Use with Gitlab CI

You can use the code analyzer to push flags references to your Flagship environment when code is pushed to a specific branch or tag

analyze_flag_references:
  image: flagshipio/code-analyzer:master
  stage: analyze
  variables:
    REPOSITORY_URL: $CI_PROJECT_URL
    REPOSITORY_BRANCH: $CI_COMMIT_BRANCH
    FLAGSHIP_CLIENT_ID: FLAGSHIP_MANAGEMENT_API_CLIENT_ID
    FLAGSHIP_CLIENT_SECRET: FLAGSHIP_MANAGEMENT_API_CLIENT_SECRET
    ACCOUNT_ID: YOUR_ACCOUNT_ID
    ENVIRONMENT_ID: YOUR_ENVIRONMENT_ID
  script:
    - /root/code-analyser
  only:
    - master

Contribute

The Codebase Analyzer is an open-source software.
See the Github link for the contribution guide: https://github.com/flagship-io/codebase-analyzer

Any feedback? We would be really happy to have a quick chat!


Did this page help you?