Skip to main content

risedev/task/
starrocks_service.rs

1// Copyright 2026 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::io::Write;
16
17use anyhow::{Result, ensure};
18
19use super::docker_service::{DockerService, DockerServiceConfig};
20use super::{ExecuteContext, Task};
21use crate::StarrocksConfig;
22
23pub const STARROCKS_CONTAINER_HOST: &str = "127.0.0.1";
24pub const STARROCKS_CONTAINER_HTTP_PORT: u16 = 8030;
25pub const STARROCKS_CONTAINER_BE_HTTP_PORT: u16 = 8040;
26pub const STARROCKS_CONTAINER_QUERY_PORT: u16 = 9030;
27
28impl DockerServiceConfig for StarrocksConfig {
29    fn id(&self) -> String {
30        self.id.clone()
31    }
32
33    fn is_user_managed(&self) -> bool {
34        self.user_managed
35    }
36
37    fn image(&self) -> String {
38        self.image.clone()
39    }
40
41    fn ports(&self) -> Vec<(String, String)> {
42        vec![
43            (
44                self.http_port.to_string(),
45                STARROCKS_CONTAINER_HTTP_PORT.to_string(),
46            ),
47            // StarRocks includes the BE HTTP port in stream-load redirects. The port therefore
48            // cannot be remapped by Docker without making the redirected URL unreachable.
49            (
50                STARROCKS_CONTAINER_BE_HTTP_PORT.to_string(),
51                STARROCKS_CONTAINER_BE_HTTP_PORT.to_string(),
52            ),
53            (
54                self.query_port.to_string(),
55                STARROCKS_CONTAINER_QUERY_PORT.to_string(),
56            ),
57        ]
58    }
59}
60
61/// Docker-backed `StarRocks` service.
62pub struct StarrocksService(DockerService<StarrocksConfig>);
63
64impl StarrocksService {
65    pub fn new(config: StarrocksConfig) -> Result<Self> {
66        ensure!(
67            config.user_managed
68                || (config.admin_user == "root" && config.admin_password.is_empty()),
69            "custom StarRocks admin credentials are only supported when `user-managed` is `true`"
70        );
71
72        Ok(Self(DockerService::new(config)))
73    }
74}
75
76impl Task for StarrocksService {
77    fn execute(&mut self, ctx: &mut ExecuteContext<impl Write>) -> Result<()> {
78        self.0.execute(ctx)
79    }
80}