Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(risedev): introduce sql server to risedev #17951

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions risedev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1621,3 +1621,33 @@ template:
# If `user-managed` is true, user is responsible for starting the service
# to serve at the above address and port in any way they see fit.
user-managed: false

# Sql Server service backed by docker.
sqlserver:
# Note: Sql Server is now only for connector purpose.
# Id to be picked-up by services
id: sqlserver-${port}

# address of mssql
address: "127.0.0.1"

# listen port of mssql
port: 1433

# Note:
# - This will be used to initialize the Sql Server instance if it's fresh.
# - In user-managed mode, these configs are not validated by risedev.
# They are passed as-is to risedev-env default user for Sql Server operations.
user: SA
password: "YourPassword123"
database: "master"

# The docker image. Can be overridden to use a different version.
image: "mcr.microsoft.com/mssql/server:2022-latest"

# If set to true, data will be persisted at data/{id}.
persist-data: true

# If `user-managed` is true, user is responsible for starting the service
# to serve at the above address and port in any way they see fit.
user-managed: false
1 change: 1 addition & 0 deletions src/risedevtool/src/bin/risedev-compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ fn main() -> Result<()> {
ServiceConfig::Redis(_)
| ServiceConfig::MySql(_)
| ServiceConfig::Postgres(_)
| ServiceConfig::SqlServer(_)
| ServiceConfig::SchemaRegistry(_) => return Err(anyhow!("not supported")),
};
compose.container_name = service.id().to_string();
Expand Down
20 changes: 19 additions & 1 deletion src/risedevtool/src/bin/risedev-dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use risedev::{
ConfigureTmuxTask, DummyService, EnsureStopService, ExecuteContext, FrontendService,
GrafanaService, KafkaService, MetaNodeService, MinioService, MySqlService, PostgresService,
PrometheusService, PubsubService, RedisService, SchemaRegistryService, ServiceConfig,
SqliteConfig, Task, TempoService, RISEDEV_NAME,
SqlServerService, SqliteConfig, Task, TempoService, RISEDEV_NAME,
};
use tempfile::tempdir;
use thiserror_ext::AsReport;
Expand Down Expand Up @@ -353,6 +353,24 @@ fn task_main(
ctx.pb
.set_message(format!("postgres {}:{}", c.address, c.port));
}
ServiceConfig::SqlServer(c) => {
let mut ctx =
ExecuteContext::new(&mut logger, manager.new_progress(), status_dir.clone());
// only `c.password` will be used in `SqlServerService` as the password for user `sa`.
SqlServerService::new(c.clone()).execute(&mut ctx)?;
if c.user_managed {
let mut task =
risedev::TcpReadyCheckTask::new(c.address.clone(), c.port, c.user_managed)?;
task.execute(&mut ctx)?;
} else {
let mut task = risedev::LogReadyCheckTask::new(
"SQL Server is now ready for client connections.",
)?;
task.execute(&mut ctx)?;
}
ctx.pb
.set_message(format!("sqlserver {}:{}", c.address, c.port));
}
}

let service_id = service.id().to_string();
Expand Down
1 change: 1 addition & 0 deletions src/risedevtool/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl ConfigExpander {
"redpanda" => ServiceConfig::RedPanda(serde_yaml::from_str(&out_str)?),
"mysql" => ServiceConfig::MySql(serde_yaml::from_str(&out_str)?),
"postgres" => ServiceConfig::Postgres(serde_yaml::from_str(&out_str)?),
"sqlserver" => ServiceConfig::SqlServer(serde_yaml::from_str(&out_str)?),
"schema-registry" => {
ServiceConfig::SchemaRegistry(serde_yaml::from_str(&out_str)?)
}
Expand Down
18 changes: 18 additions & 0 deletions src/risedevtool/src/risedev_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ pub fn generate_risedev_env(services: &Vec<ServiceConfig>) -> String {
writeln!(env, r#"PGPASSWORD="{password}""#,).unwrap();
writeln!(env, r#"PGDATABASE="{database}""#,).unwrap();
}
ServiceConfig::SqlServer(c) => {
let host = &c.address;
let port = &c.port;
let user = &c.user;
let password = &c.password;
let database = &c.database;
// These envs are used by `sqlcmd`.
writeln!(env, r#"SQLCMDSERVER="{host}""#,).unwrap();
writeln!(env, r#"SQLCMDPORT="{port}""#,).unwrap();
writeln!(env, r#"SQLCMDUSER="{user}""#,).unwrap();
writeln!(env, r#"SQLCMDPASSWORD="{password}""#,).unwrap();
writeln!(env, r#"SQLCMDDBNAME="{database}""#,).unwrap();
writeln!(
env,
r#"RISEDEV_SQLSERVER_WITH_OPTIONS_COMMON="connector='sqlserver-cdc',hostname='{host}',port='{port}',username='{user}',password='{password}',database.name='{database}'""#,
)
.unwrap();
}
KeXiangWang marked this conversation as resolved.
Show resolved Hide resolved
_ => {}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/risedevtool/src/service_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ pub struct PostgresConfig {
pub persist_data: bool,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
pub struct SqlServerConfig {
#[serde(rename = "use")]
phantom_use: Option<String>,
pub id: String,

pub port: u16,
pub address: String,

pub user: String,
pub password: String,
pub database: String,

pub image: String,
pub user_managed: bool,
pub persist_data: bool,
}

/// All service configuration
#[derive(Clone, Debug, PartialEq)]
pub enum ServiceConfig {
Expand All @@ -434,6 +454,7 @@ pub enum ServiceConfig {
RedPanda(RedPandaConfig),
MySql(MySqlConfig),
Postgres(PostgresConfig),
SqlServer(SqlServerConfig),
}

impl ServiceConfig {
Expand All @@ -457,6 +478,7 @@ impl ServiceConfig {
Self::Opendal(c) => &c.id,
Self::MySql(c) => &c.id,
Self::Postgres(c) => &c.id,
Self::SqlServer(c) => &c.id,
Self::SchemaRegistry(c) => &c.id,
}
}
Expand All @@ -482,6 +504,7 @@ impl ServiceConfig {
Self::Opendal(_) => None,
Self::MySql(c) => Some(c.port),
Self::Postgres(c) => Some(c.port),
Self::SqlServer(c) => Some(c.port),
Self::SchemaRegistry(c) => Some(c.port),
}
}
Expand All @@ -506,6 +529,7 @@ impl ServiceConfig {
Self::Opendal(_c) => false,
Self::MySql(c) => c.user_managed,
Self::Postgres(c) => c.user_managed,
Self::SqlServer(c) => c.user_managed,
Self::SchemaRegistry(c) => c.user_managed,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/risedevtool/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod prometheus_service;
mod pubsub_service;
mod redis_service;
mod schema_registry_service;
mod sql_server_service;
mod task_configure_minio;
mod task_etcd_ready_check;
mod task_kafka_ready_check;
Expand Down Expand Up @@ -70,6 +71,7 @@ pub use self::prometheus_service::*;
pub use self::pubsub_service::*;
pub use self::redis_service::*;
pub use self::schema_registry_service::SchemaRegistryService;
pub use self::sql_server_service::*;
pub use self::task_configure_minio::*;
pub use self::task_etcd_ready_check::*;
pub use self::task_kafka_ready_check::*;
Expand Down
50 changes: 50 additions & 0 deletions src/risedevtool/src/task/sql_server_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::task::docker_service::{DockerService, DockerServiceConfig};
use crate::SqlServerConfig;

impl DockerServiceConfig for SqlServerConfig {
fn id(&self) -> String {
self.id.clone()
}

fn is_user_managed(&self) -> bool {
self.user_managed
}

fn image(&self) -> String {
self.image.clone()
}

fn envs(&self) -> Vec<(String, String)> {
vec![
("ACCEPT_EULA".to_owned(), "Y".to_owned()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By passing the value "Y" to the environment variable "ACCEPT_EULA", you are expressing that you have a valid and existing license for the edition and version of SQL Server that you intend to use. You also agree that your use of SQL Server software running in a Docker container image will be governed by the terms of your SQL Server license.

https://arc.net/l/quote/uetmwpuy

🤔 Looks dangerous

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, developer edition (the default) looks OK.

SQL Server Developer edition lets developers build any kind of application on top of SQL Server. It includes all the functionality of Enterprise edition, but is licensed for use as a development and test system, not as a production server.

("MSSQL_AGENT_ENABLED".to_owned(), "true".to_owned()),
("MSSQL_SA_PASSWORD".to_owned(), self.password.clone()),
]
}

fn ports(&self) -> Vec<(String, String)> {
vec![(self.port.to_string(), "1433".to_owned())]
}

fn data_path(&self) -> Option<String> {
self.persist_data
.then(|| "/var/lib/sqlserver/data".to_owned())
}
}

/// Docker-backed Sql Server service.
pub type SqlServerService = DockerService<SqlServerConfig>;
Loading