risingwave_common/util/deployment.rs
1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::LazyLock;
16
17use enum_as_inner::EnumAsInner;
18
19use super::env_var::env_var_is_true;
20
21/// The deployment environment detected from environment variables.
22#[derive(Debug, Clone, Copy, EnumAsInner)]
23pub enum Deployment {
24 /// Running in CI.
25 Ci,
26 /// Running in cloud.
27 Cloud,
28 /// Running in other environments.
29 // TODO: may distinguish between local development and on-premises production.
30 Other,
31}
32
33impl Deployment {
34 /// Returns the deployment environment detected from current environment variables.
35 pub fn current() -> Self {
36 static CURRENT: LazyLock<Deployment> = LazyLock::new(|| {
37 if env_var_is_true("RISINGWAVE_CI") {
38 Deployment::Ci
39 } else if env_var_is_true("RISINGWAVE_CLOUD") {
40 Deployment::Cloud
41 } else {
42 Deployment::Other
43 }
44 });
45 *CURRENT
46 }
47}