defaultContainerEnvs returns environment variables that should always be passed to the inner container.
(ctx context.Context, agentToken string)
| 940 | // defaultContainerEnvs returns environment variables that should always |
| 941 | // be passed to the inner container. |
| 942 | func defaultContainerEnvs(ctx context.Context, agentToken string) []string { |
| 943 | const agentSubsystemEnv = "CODER_AGENT_SUBSYSTEM" |
| 944 | env := xunix.Environ(ctx) |
| 945 | existingSubsystem := "" |
| 946 | for _, e := range env { |
| 947 | if strings.HasPrefix(e, agentSubsystemEnv+"=") { |
| 948 | existingSubsystem = strings.TrimPrefix(e, agentSubsystemEnv+"=") |
| 949 | break |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | // We should append to the existing agent subsystem if it exists. |
| 954 | agentSubsystem := "envbox" |
| 955 | if existingSubsystem != "" { |
| 956 | split := strings.Split(existingSubsystem, ",") |
| 957 | split = append(split, "envbox") |
| 958 | |
| 959 | tidy := make([]string, 0, len(split)) |
| 960 | seen := make(map[string]struct{}) |
| 961 | for _, s := range split { |
| 962 | s := strings.TrimSpace(s) |
| 963 | if _, ok := seen[s]; s == "" || ok { |
| 964 | continue |
| 965 | } |
| 966 | seen[s] = struct{}{} |
| 967 | tidy = append(tidy, s) |
| 968 | } |
| 969 | |
| 970 | sort.Strings(tidy) |
| 971 | agentSubsystem = strings.Join(tidy, ",") |
| 972 | } |
| 973 | |
| 974 | return []string{ |
| 975 | fmt.Sprintf("%s=%s", EnvAgentToken, agentToken), |
| 976 | fmt.Sprintf("%s=%s", "CODER_AGENT_SUBSYSTEM", agentSubsystem), |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | // defaultMounts are bind mounts that are always provided to the inner |
| 981 | // container. |
no test coverage detected