Adding Custom Environments to Apollo Configuration Center: A Practical Guide

Adding a Custom Environment (SIT) to Apollo

To extend Apollo with a new environment, such as SIT (System Integration Testing), modify the following core comopnents:

1. Env Enum Class

File: com.ctrip.framework.apollo.core.enums.Env

Add the SIT enumeration value:

public enum Env {
    LOCAL, DEV, FWS, FAT, UAT, LPT, PRO, TOOLS, UNKNOWN, SIT;
    // ... existing fields and methods
}

2. Environment Transformation Logic

File: com.ctrip.framework.apollo.core.enums.EnvUtils

Update the transformEnv method to recognize the SIT environment:

public final class EnvUtils {

    public static Env transformEnv(String envName) {
        if (StringUtils.isBlank(envName)) {
            return Env.UNKNOWN;
        }
        switch (envName.trim().toUpperCase()) {
            case "LPT":
                return Env.LPT;
            case "FAT":
            case "FWS":
                return Env.FAT;
            case "UAT":
                return Env.UAT;
            case "PRO":
            case "PROD":
                return Env.PRO;
            case "DEV":
                return Env.DEV;
            case "LOCAL":
                return Env.LOCAL;
            case "TOOLS":
                return Env.TOOLS;
            case "SIT":
                return Env.SIT;
            default:
                return Env.UNKNOWN;
        }
    }
}

3. Meta Server Address Configuration

File: com.ctrip.framework.apollo.core.internals.LegacyMetaServerProvider

Add logic to read the meta server address for the SIT environment from the apollo-env.properties file:

public class LegacyMetaServerProvider implements MetaServerProvider {

    public static final int ORDER = MetaServerProvider.LOWEST_PRECEDENCE - 1;
    private static final Map<Env, String> domains = new HashMap<>();

    public LegacyMetaServerProvider() {
        initialize();
    }

    private void initialize() {
        Properties prop = new Properties();
        prop = ResourceUtils.readConfigFile("apollo-env.properties", prop);
        
        domains.put(Env.LOCAL, getMetaServerAddress(prop, "local_meta", "local.meta"));
        domains.put(Env.DEV, getMetaServerAddress(prop, "dev_meta", "dev.meta"));
        domains.put(Env.FAT, getMetaServerAddress(prop, "fat_meta", "fat.meta"));
        domains.put(Env.UAT, getMetaServerAddress(prop, "uat_meta", "uat.meta"));
        domains.put(Env.LPT, getMetaServerAddress(prop, "lpt_meta", "lpt.meta"));
        domains.put(Env.PRO, getMetaServerAddress(prop, "pro_meta", "pro.meta"));
        // Add SIT environment mapping
        domains.put(Env.SIT, getMetaServerAddress(prop, "sit_meta", "sit.meta"));
    }
}

4. Log Directory Customization

Update the startup scripts to point log directories to custom paths:

  • apollo-adminservice/scripts/startup.sh:

    LOG_DIR=/usr/local/nlp/logs/apollo-adminservice/100003172
    
  • apollo-configservice/scripts/startup.sh:

    LOG_DIR=/usr/local/nlp/logs/apollo-configservice/100003171
    
  • apollo-portal/scripts/startup.sh:

    LOG_DIR=/usr/local/nlp/logs/apollo-portal/100003173
    

Building Apollo with Multiple Enivronments

When you have DEV, UAT, SIT, and PRO environments, build apollo-configservice and apollo-adminservice separately for each environment, while apollo-portal is built once with all environment meta server addresses.

Environment-Specific Builds for Config and Admin Services

# DEV environment
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am \
  -Dapollo_profile=github \
  -Dspring_datasource_url=jdbc:mysql://127.0.0.1:3306/apollo_configdb_dev?characterEncoding=utf8 \
  -Dspring_datasource_username=root \
  -Dspring_datasource_password=cc123456

# DAILY (UAT) environment
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am \
  -Dapollo_profile=github \
  -Dspring_datasource_url=jdbc:mysql://127.0.0.1:3306/apollo_configdb_daily?characterEncoding=utf8 \
  -Dspring_datasource_username=root \
  -Dspring_datasource_password=cc123456

# SIT environment
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am \
  -Dapollo_profile=github \
  -Dspring_datasource_url=jdbc:mysql://127.0.0.1:3306/apollo_configdb_sit?characterEncoding=utf8 \
  -Dspring_datasource_username=root \
  -Dspring_datasource_password=cc123456

# PRO environment
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am \
  -Dapollo_profile=github \
  -Dspring_datasource_url=jdbc:mysql://127.0.0.1:3306/apollo_configdb_pro?characterEncoding=utf8 \
  -Dspring_datasource_username=root \
  -Dspring_datasource_password=cc123456

Portal Build (Single Build)

mvn clean package -DskipTests -pl apollo-portal -am \
  -Dapollo_profile=github,auth \
  -Dspring_datasource_url=jdbc:mysql://127.0.0.1:3306/apollo_portaldb?characterEncoding=utf8 \
  -Dspring_datasource_username=root \
  -Dspring_datasource_password=cc123456 \
  -Ddev_meta=http://10.xxx.xx.127:8080 \
  -Dsit_meta=http://10.xxx.xx.129:8080 \
  -Duat_meta=http://10.xxx.xx.128:8080 \
  -Dpro_meta=http://10.xxx.xx.130:8080

Deploying Apollo Packages

Create a target directory for each component, e.g., /usr/local/wxt/apollo_adminservice/, and unzip the corresponding build artifacts:

unzip apollo-adminservice-1.4.0-github.zip -d apollo-adminservice-1.4.0-github
unzip apollo-configservice-1.4.0-github.zip -d apollo-configservice-1.4.0-github
unzip apollo-portal-1.4.0-github.zip -d apollo-portal-1.4.0-github

Starting the Services

Each extracted package contains a scripts folder with startup scripts. Start the services in this specific order:

  1. apollo-configservice – execute scripts/startup.sh
  2. apollo-adminservice – execute scripts/startup.sh
  3. apollo-portal – execute scripts/startup.sh

To stop each service, run the corresponding scripts/shutdown.sh script.

Tags: Apollo Configuration Center Custom Environment SIT deployment

Posted on Sat, 18 Jul 2026 16:44:57 +0000 by orion2004