@@ -37,7 +37,7 @@ func (m *bacpac) BringOnline(
3737 m .setDefaultDatabaseToMaster (options .Username , query )
3838
3939 m .RunCommand ([]string {
40- ". /.dotnet/tools/sqlpackage" ,
40+ "/home/mssql /.dotnet/tools/sqlpackage" ,
4141 "/Diagnostics:true" ,
4242 "/Action:import" ,
4343 "/SourceFile:" + m .CopyToLocation () + "/" + options .Filename ,
@@ -62,29 +62,35 @@ func (m *bacpac) installSqlPackage() {
6262 panic ("controller is nil" )
6363 }
6464
65- //BUG(stuartpa): Can this be done in the mssql user, don't think it needs root
66- m .RunCommand ([]string {"wget" , "https://dot.net/v1/dotnet-install.sh" , "-O" , "/tmp/dotnet-install.sh" })
67- m .RunCommand ([]string {"chmod" , "+x" , "/tmp/dotnet-install.sh" })
68- m .RunCommand ([]string {"/tmp/dotnet-install.sh" , "--install-dir" , "/opt/dotnet" })
65+ _ , stderr := m .RunCommand ([]string {"/opt/dotnet/dotnet" , "--version" })
66+ if len (stderr ) > 0 {
67+ m .RunCommand ([]string {"wget" , "https://dot.net/v1/dotnet-install.sh" , "-O" , "/tmp/dotnet-install.sh" })
68+ m .RunCommand ([]string {"chmod" , "+x" , "/tmp/dotnet-install.sh" })
69+ m .RunCommand ([]string {"/tmp/dotnet-install.sh" , "--install-dir" , "/opt/dotnet" })
6970
70- // The SQL Server container doesn't have a /home/mssql directory (which is ~), this
71- // causes all sorts of things to break in the container that expect to create .toolname folders
72- m .RunCommandAsRoot ([]string {"mkdir" , "-p" , "/home/mssql" })
73- m .RunCommandAsRoot ([]string {"chown" , "mssql:root" , "/home/mssql" })
71+ // The SQL Server container doesn't have a /home/mssql directory (which is ~), this
72+ // causes all sorts of things to break in the container that expect to create .toolname folders
73+ m .RunCommandAsRoot ([]string {"mkdir" , "-p" , "/home/mssql" })
74+ m .RunCommandAsRoot ([]string {"chown" , "mssql:root" , "/home/mssql" })
7475
75- m .RunCommand ([]string {"touch" , "/home/mssql/.bashrc" })
76- m .RunCommand ([]string {"sed" , "-i" , "$ a/export DOTNET_ROOT=/opt/dotnet" , "/home/mssql/.bashrc" })
77- m .RunCommand ([]string {"sed" , "-i" , "$ a/export PATH=$PATH:$DOTNET_ROOT:~/.dotnet/tools" , "/home/mssql/.bashrc" })
78- m .RunCommand ([]string {"/opt/dotnet/dotnet" , "tool" , "install" , "-g" , "microsoft.sqlpackage" })
76+ m .RunCommand ([]string {"/bin/bash" , "-c" , "echo 'export DOTNET_ROOT=/opt/dotnet' > /home/mssql/.bashrc" })
77+ m .RunCommand ([]string {"/bin/bash" , "-c" , "echo 'export PATH=$PATH:$DOTNET_ROOT:/home/mssql/.dotnet/tools' >> /home/mssql/.bashrc" })
78+ }
79+
80+ _ , stderr = m .RunCommand ([]string {"/home/mssql/.dotnet/tools/sqlpackage" , "/version" })
81+ if len (stderr ) > 0 {
82+ m .RunCommand ([]string {"/opt/dotnet/dotnet" , "tool" , "install" , "-g" , "microsoft.sqlpackage" })
83+ }
7984}
8085
8186func (m * bacpac ) RunCommand (s []string ) ([]byte , []byte ) {
82- return m .controller .RunCmdInContainer (m .containerId , s , container.ExecOptions {})
87+ return m .controller .RunCmdInContainer (m .containerId , s , container.ExecOptions {
88+ Env : []string {"DOTNET_ROOT=/opt/dotnet" },
89+ })
8390}
8491
8592func (m * bacpac ) RunCommandAsRoot (s []string ) ([]byte , []byte ) {
8693 return m .controller .RunCmdInContainer (m .containerId , s , container.ExecOptions {
8794 User : "root" ,
88- Env : nil ,
8995 })
9096}
0 commit comments