1- package csvapp
1+ package cvm
22
33/*
44#include <unistd.h>
@@ -7,11 +7,10 @@ package csvapp
77*/
88import "C"
99import (
10+ "apploader/internal/secret"
1011 "apploader/pkg/conversion"
1112 "apploader/pkg/file"
12- "apploader/secret_server"
1313 "fmt"
14- "io/ioutil"
1514 "log"
1615 "os"
1716 "os/exec"
@@ -36,42 +35,13 @@ const (
3635 SUPERVISOR_PATH = "/workplace/supervisord/apploader"
3736)
3837
39- type CsvApp struct {
40- Kind string `yaml:"kind"`
41- AppInfo []* TaskInfo `yaml:"app"`
42- CsvAssistants []* TaskInfo `yaml:"csvAssistants"`
43- }
44-
45- type TaskInfo struct {
46- TLSInfo * TLSInfo `yaml:"tls"`
47- Name string `yaml:"name"`
48- Type string `yaml:"type"`
49- Entrypoint string `yaml:"entrypoint"`
50- Env interface {} `yaml:"env"`
51- Priority int `yaml:"-"`
52- Args []string `yaml:"args"`
53- }
54-
55- type SupervisorConf struct {
56- Name string
57- Command string
58- Workplace string
59- Environment string
60- Priority int
61- }
62-
63- type TLSInfo struct {
64- CertPath string `yaml:"certPath"`
65- CommonName string `yaml:"commonName"`
66- }
67-
6838func DoJob (ca * TaskInfo ) error {
6939 if ca .Type != JOB {
7040 return fmt .Errorf ("this task is not a job" )
7141 }
7242
7343 envs := make ([]string , 0 )
74- for k , v := range secret_server .Secret {
44+ for k , v := range secret .Secret {
7545 envs = append (envs , fmt .Sprintf ("%s=%s" , k , v ))
7646 }
7747
@@ -86,43 +56,6 @@ func DoJob(ca *TaskInfo) error {
8656 }
8757 }
8858
89- if ca .TLSInfo != nil {
90- encryptedDir := "/workplace/encryptedData"
91- log .Printf ("[warning] use PKI, please make sure %s is an encrypted disk" , encryptedDir )
92- caPath := path .Join (encryptedDir , "pki" )
93- if ! file .Exists (path .Join (caPath , "existed" )) {
94- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "ca" , "-a" , caPath , "-c" , "/workplace/csv-agent/csvassistants/pkitool/conf/cert-conf" )
95- if err != nil {
96- return fmt .Errorf ("init pki ca failed, error: %s" , err .Error ())
97- }
98- err = ioutil .WriteFile (path .Join (caPath , "existed" ), []byte ("existed" ), os .ModePerm )
99- if err != nil {
100- os .RemoveAll (caPath )
101- return fmt .Errorf ("mark ca existed faield, error: %s" , err .Error ())
102- }
103- }
104- if ! file .Exists (path .Join (ca .TLSInfo .CertPath , "existed" )) {
105- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "server" , "-a" , caPath , "-o" , ca .TLSInfo .CertPath , "-n" , ca .TLSInfo .CommonName )
106- if err != nil {
107- return fmt .Errorf ("create tls cert failed, error: %s\n " , err .Error ())
108- }
109-
110- err = ioutil .WriteFile (path .Join (ca .TLSInfo .CertPath , "existed" ), []byte ("existed" ), os .ModePerm )
111- if err != nil {
112- os .RemoveAll (ca .TLSInfo .CertPath )
113- return fmt .Errorf ("mark ca existed faield, error: %s" , err .Error ())
114- }
115- }
116-
117- caString , err := ioutil .ReadFile (path .Join (caPath , "ca.crt" ))
118- if err != nil {
119- return fmt .Errorf ("read ca.crt failed, error: %s" , err .Error ())
120- }
121- log .Println ("the ca.crt is as follow" )
122- fmt .Printf ("%s" , caString )
123- log .Println ("*********************************" )
124- }
125-
12659 log .Printf ("entrypoint is %s" , ca .Entrypoint )
12760 return RunCommand (ca .Entrypoint , envs , ca .Args ... )
12861
@@ -189,36 +122,7 @@ func ExecvDockerApp(ca *TaskInfo) {
189122 log .Fatalf ("task is not a docker app" )
190123 }
191124
192- if ca .TLSInfo != nil {
193- encryptedDir := "/workplace/encryptedData"
194- log .Printf ("[warning] use PKI, please make sure %s is an encrypted disk" , encryptedDir )
195- caPath := path .Join (encryptedDir , "pki" )
196- if ! file .Exists (path .Join (caPath , "existed" )) {
197- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "ca" , "-a" , caPath , "-c" , "/workplace/csv-agent/csvassistants/pkitool/conf/cert-conf" )
198- if err != nil {
199- log .Fatalf ("init pki ca failed, error: %s" , err .Error ())
200- }
201- err = ioutil .WriteFile (path .Join (caPath , "existed" ), []byte ("existed" ), os .ModePerm )
202- if err != nil {
203- os .RemoveAll (caPath )
204- log .Fatalf ("mark ca existed faield, error: %s" , err .Error ())
205- }
206- }
207- if ! file .Exists (path .Join (ca .TLSInfo .CertPath , "existed" )) {
208- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "server" , "-a" , caPath , "-o" , ca .TLSInfo .CertPath , "-n" , ca .TLSInfo .CommonName )
209- if err != nil {
210- log .Fatalf ("create tls cert failed, error: %s\n " , err .Error ())
211- }
212-
213- err = ioutil .WriteFile (path .Join (ca .TLSInfo .CertPath , "existed" ), []byte ("existed" ), os .ModePerm )
214- if err != nil {
215- os .RemoveAll (ca .TLSInfo .CertPath )
216- log .Fatalf ("mark ca existed faield, error: %s" , err .Error ())
217- }
218- }
219- }
220-
221- for k , v := range secret_server .Secret {
125+ for k , v := range secret .Secret {
222126 err := os .Setenv (k , v )
223127 if err != nil {
224128 log .Fatalf ("set secret env failed, error: %s\n " , err .Error ())
@@ -246,42 +150,6 @@ func CreateSevers(ca *TaskInfo) error {
246150 if ca .Type != SERVER {
247151 return fmt .Errorf ("task is not a server" )
248152 }
249- if ca .TLSInfo != nil {
250- encryptedDir := "/workplace/encryptedData"
251- log .Printf ("[warning] use PKI, please make sure %s is an encrypted disk" , encryptedDir )
252- caPath := path .Join (encryptedDir , "pki" )
253- if ! file .Exists (path .Join (caPath , "existed" )) {
254- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "ca" , "-a" , caPath , "-c" , "/workplace/csv-agent/csvassistants/pkitool/conf/cert-conf" )
255- if err != nil {
256- return fmt .Errorf ("init pki ca failed, error: %s" , err .Error ())
257- }
258- err = ioutil .WriteFile (path .Join (caPath , "existed" ), []byte ("existed" ), os .ModePerm )
259- if err != nil {
260- os .RemoveAll (caPath )
261- return fmt .Errorf ("mark ca existed faield, error: %s" , err .Error ())
262- }
263- }
264- if ! file .Exists (path .Join (ca .TLSInfo .CertPath , "existed" )) {
265- err := RunCommand ("/workplace/csv-agent/csvassistants/pkitool/pkitool" , nil , "cert" , "-m" , "server" , "-a" , caPath , "-o" , ca .TLSInfo .CertPath , "-n" , ca .TLSInfo .CommonName )
266- if err != nil {
267- return fmt .Errorf ("create tls cert failed, error: %s\n " , err .Error ())
268- }
269-
270- err = ioutil .WriteFile (path .Join (ca .TLSInfo .CertPath , "existed" ), []byte ("existed" ), os .ModePerm )
271- if err != nil {
272- os .RemoveAll (ca .TLSInfo .CertPath )
273- return fmt .Errorf ("mark ca existed faield, error: %s" , err .Error ())
274- }
275- }
276-
277- caString , err := ioutil .ReadFile (path .Join (caPath , "ca.crt" ))
278- if err != nil {
279- return fmt .Errorf ("read ca.crt failed, error: %s" , err .Error ())
280- }
281- log .Println ("the ca.crt is as follow" )
282- fmt .Printf ("%s" , caString )
283- log .Println ("*********************************" )
284- }
285153
286154 envs := make ([]string , 0 )
287155
@@ -332,22 +200,22 @@ func CreateSevers(ca *TaskInfo) error {
332200}
333201
334202func Start () {
335- appfile , err := ioutil .ReadFile ("conf/app.yml" )
203+ appfile , err := os .ReadFile ("conf/app.yml" )
336204 if err != nil {
337205 log .Fatalf ("read app.yml failed, error: %s\n " , err .Error ())
338206 }
339- csvApp := new (CsvApp )
340- err = yaml .Unmarshal (appfile , & csvApp )
207+ cvmApp := new (CvmApp )
208+ err = yaml .Unmarshal (appfile , & cvmApp )
341209 if err != nil {
342210 log .Fatalf ("unmarshal app.yml failed, error: %s\n " , err .Error ())
343211 }
344212 time .Sleep (5 * time .Second )
345213
346214 log .Println ("do all the job over" )
347215
348- startTask (csvApp . CsvAssistants )
216+ startTask (cvmApp . CvmAssistants )
349217
350- startTask (csvApp .AppInfo )
218+ startTask (cvmApp .AppInfo )
351219}
352220
353221func startTask (tasks []* TaskInfo ) {
0 commit comments