MCPcopy Index your code
hub / github.com/ddev/ddev / CreateSSHAuthComposeFile

Method CreateSSHAuthComposeFile

pkg/ddevapp/ssh_auth.go:116–185  ·  view source on GitHub ↗

CreateSSHAuthComposeFile creates the docker-compose file for the ddev-ssh-agent

()

Source from the content-addressed store, hash-verified

114
115// CreateSSHAuthComposeFile creates the docker-compose file for the ddev-ssh-agent
116func (app *DdevApp) CreateSSHAuthComposeFile() (string, error) {
117 var doc bytes.Buffer
118 f, ferr := os.Create(SSHAuthComposeYAMLPath())
119 if ferr != nil {
120 return "", ferr
121 }
122 defer util.CheckClose(f)
123
124 context := "./.sshimageBuild"
125 err := WriteBuildDockerfile(app, filepath.Join(globalconfig.GetGlobalDdevDir(), context, "Dockerfile"), "", nil, "", "")
126 if err != nil {
127 return "", err
128 }
129
130 uid, gid, username := dockerutil.GetContainerUser()
131 timezone, _ := util.GetLocalTimezone()
132
133 _ = app.DockerEnv()
134
135 templateVars := map[string]any{
136 "ssh_auth_image": versionconstants.SSHAuthImage,
137 "ssh_auth_tag": versionconstants.SSHAuthTag,
138 "Username": username,
139 "UID": uid,
140 "GID": gid,
141 "Timezone": timezone,
142 "BuildContext": context,
143 "IsPodmanRootless": dockerutil.IsPodmanRootless(),
144 }
145 t, err := template.New("ssh_auth_compose_template.yaml").Funcs(getTemplateFuncMap()).ParseFS(bundledAssets, "ssh_auth_compose_template.yaml")
146 if err != nil {
147 return "", err
148 }
149 err = t.Execute(&doc, templateVars)
150 util.CheckErr(err)
151 _, err = f.WriteString(doc.String())
152 util.CheckErr(err)
153
154 fullHandle, err := os.Create(FullRenderedSSHAuthComposeYAMLPath())
155 if err != nil {
156 return "", err
157 }
158
159 userFiles, err := filepath.Glob(filepath.Join(globalconfig.GetGlobalDdevDir(), "ssh-auth-compose.*.yaml"))
160 if err != nil {
161 return "", err
162 }
163 files := append([]string{SSHAuthComposeYAMLPath()}, userFiles...)
164 fullContents, _, err := dockerutil.ComposeCmd(&dockerutil.ComposeCmdOpts{
165 ComposeFiles: files,
166 Action: []string{"config"},
167 })
168 if err != nil {
169 return "", err
170 }
171 project, err := dockerutil.CreateComposeProject(fullContents)
172 if err != nil {
173 return "", err

Callers 1

Calls 15

DockerEnvMethod · 0.95
CheckCloseFunction · 0.92
GetGlobalDdevDirFunction · 0.92
GetContainerUserFunction · 0.92
GetLocalTimezoneFunction · 0.92
IsPodmanRootlessFunction · 0.92
CheckErrFunction · 0.92
ComposeCmdFunction · 0.92
CreateComposeProjectFunction · 0.92
SSHAuthComposeYAMLPathFunction · 0.85
WriteBuildDockerfileFunction · 0.85
getTemplateFuncMapFunction · 0.85

Tested by

no test coverage detected