feat(deploy): run Docker application against external RDS
This commit is contained in:
@@ -6,112 +6,67 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDobotAIDingTalkContainerAssetsProvideSafeShortOperatorCommands(t *testing.T) {
|
||||
func TestDockerDeploymentContainsOnlyDobotAIApplication(t *testing.T) {
|
||||
compose, err := os.ReadFile("../deploy/dobotai-dingtalk/compose.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, required := range []string{
|
||||
"dobotai-dingtalk:",
|
||||
"container_name: dobotai-dingtalk",
|
||||
"network_mode: host",
|
||||
"env_file:",
|
||||
"read_only: true",
|
||||
"/var/lib/dobotai/secrets",
|
||||
} {
|
||||
if !strings.Contains(string(compose), required) {
|
||||
source := string(compose)
|
||||
for _, required := range []string{"dobotai-dingtalk:", "container_name: dobotai-dingtalk", "network_mode: host", "env_file:", "read_only: true"} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("compose missing %q", required)
|
||||
}
|
||||
}
|
||||
|
||||
configure, err := os.ReadFile("../deploy/dobotai-dingtalk/dobotai-dingtalk-configure")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, required := range []string{
|
||||
"configure_env.py",
|
||||
"/etc/dobotai-test/dobotai.env",
|
||||
"dobotai-dingtalk-start",
|
||||
} {
|
||||
if !strings.Contains(string(configure), required) {
|
||||
t.Errorf("configure command missing %q", required)
|
||||
}
|
||||
}
|
||||
|
||||
bind, err := os.ReadFile("../deploy/dobotai-dingtalk/dobotai-dingtalk-bind-admin")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, required := range []string{
|
||||
"docker exec -it dobotai-dingtalk",
|
||||
"/usr/local/bin/dobotai bootstrap-admin",
|
||||
} {
|
||||
if !strings.Contains(string(bind), required) {
|
||||
t.Errorf("bind command missing %q", required)
|
||||
for _, forbidden := range []string{"dobotai-postgres", "postgres-data", "name: dobotai-network"} {
|
||||
if strings.Contains(source, forbidden) {
|
||||
t.Errorf("compose must not manage a local database resource %q", forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkCredentialConfigurationNeverPassesSecretsOnCommandLine(t *testing.T) {
|
||||
func TestRootInstallerBuildsImageWithoutOperatorImageArgument(t *testing.T) {
|
||||
data, err := os.ReadFile("../install-docker.sh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{"docker build", "dobotai-dingtalk:local-", "install_docker_if_missing", "DOBOTAI_SOURCE_ROOT", "deploy/dobotai-dingtalk/install-docker.sh"} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("root installer missing %q", required)
|
||||
}
|
||||
}
|
||||
if strings.Contains(source, "${DOBOTAI_IMAGE") {
|
||||
t.Fatal("root installer must not require DOBOTAI_IMAGE")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRDSInitializerOnlyInitializesEmptySchemaAndRejectsInconsistentSchema(t *testing.T) {
|
||||
data, err := os.ReadFile("../deploy/dobotai-dingtalk/rds-schema-init.sh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{"pg_isready", "to_regclass('public.turns')", "empty", "normal", "inconsistent", "*.up.sql", "DATABASE_URL", "postgres:16-alpine"} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("RDS initializer missing %q", required)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{"docker compose", "dobotai-postgres", "pg_dump -Fc", "DROP DATABASE", "DROP SCHEMA"} {
|
||||
if strings.Contains(source, forbidden) {
|
||||
t.Errorf("RDS initializer must not manage or destroy databases: %q", forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRDSCredentialConfiguratorPromptsForExternalDatabase(t *testing.T) {
|
||||
data, err := os.ReadFile("../deploy/dobotai-dingtalk/configure_env.py")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{"getpass.getpass", "os.replace", "0o600", "DINGTALK_CLIENT_SECRET"} {
|
||||
for _, required := range []string{"DATABASE_URL", "阿里云RDS", "getpass.getpass", "os.replace", "0o600"} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("credential configurator missing %q", required)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{"subprocess.run([", "-v", "DINGTALK_CLIENT_SECRET="} {
|
||||
if strings.Contains(source, forbidden) {
|
||||
t.Errorf("credential configurator must not expose secret through process arguments: %q", forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkCredentialConfigurationExplainsEveryInputWithRedactedExamples(t *testing.T) {
|
||||
configurator, err := os.ReadFile("../deploy/dobotai-dingtalk/configure_env.py")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
documentation, err := os.ReadFile("../deploy/dobotai-dingtalk/README.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(configurator), "格式示例:{example}") || !strings.Contains(string(documentation), "格式示例") {
|
||||
t.Fatal("configuration guidance must label every example")
|
||||
}
|
||||
for _, example := range []string{
|
||||
"postgres://USER:<数据库密码>@127.0.0.1:55432/dobotai_test?sslmode=disable",
|
||||
"http://127.0.0.1:8080",
|
||||
`{"dingtalk:*":"你的Agent ID"}`,
|
||||
"DINGTALK_CLIENT_SECRET",
|
||||
} {
|
||||
if !strings.Contains(string(configurator), example) {
|
||||
t.Errorf("configurator missing redacted example %q", example)
|
||||
}
|
||||
if !strings.Contains(string(documentation), example) {
|
||||
t.Errorf("documentation missing redacted example %q", example)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDobotAIDingTalkStartRollsBackToPreviousContainerImage(t *testing.T) {
|
||||
data, err := os.ReadFile("../deploy/dobotai-dingtalk/dobotai-dingtalk-start")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := string(data)
|
||||
for _, required := range []string{
|
||||
"previous_image=",
|
||||
"set_runtime_image",
|
||||
"docker inspect --format",
|
||||
"set_runtime_image \"$previous_image\"",
|
||||
"docker compose --env-file \"$runtime_env\" -f \"$compose_file\" up -d --no-build --force-recreate",
|
||||
} {
|
||||
if !strings.Contains(source, required) {
|
||||
t.Errorf("start script missing container upgrade rollback %q", required)
|
||||
t.Errorf("RDS configurator missing %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user