61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net"
|
|
"net/http"
|
|
|
|
"gitlab.com/infektcommon/settings"
|
|
)
|
|
|
|
var (
|
|
isGuidelinesApp = map[string]bool{"api": true, "web": true, "filestore": true, "html2pdf": true}
|
|
guidelinesRegistry = "registry.gitlab.com/infektweb/glv5/"
|
|
containersSocket string
|
|
socketHttpTransport = &http.Transport{
|
|
Dial: func(n, a string) (conn net.Conn, err error) { return net.Dial("unix", containersSocket) },
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
containersSocket = settings.GetSetting("CONTAINERS_SOCKET", "/tmp/podman/podman.sock")
|
|
}
|
|
|
|
type podmanClient struct {
|
|
httpClient *http.Client
|
|
}
|
|
|
|
func (pc *podmanClient) pullImages(deploymentSpec DeploymentSpec, httpClient *http.Client, api string) error {
|
|
for _, spec := range deploymentSpec {
|
|
app := spec.App
|
|
version := spec.Version
|
|
|
|
if version == "" {
|
|
version = "latest"
|
|
}
|
|
|
|
if isGuidelinesApp[app] {
|
|
app = guidelinesRegistry + app
|
|
}
|
|
|
|
pc.httpClient = httpClient
|
|
|
|
if response, err := pc.httpClient.Post(fmt.Sprintf("%s/images/pull?reference=%s:%s", api, app, version), jsonContentType, nil); err == nil {
|
|
responseBody, _ := ioutil.ReadAll(response.Body)
|
|
//ioutil.ReadAll(response.Body)
|
|
fmt.Println(string(responseBody))
|
|
if response, err := pc.httpClient.Get(fmt.Sprintf("%s/images/%s:%s/exists", api, app, version)); err != nil {
|
|
return err
|
|
} else if response.StatusCode != 204 {
|
|
return errors.New(fmt.Sprintf("The Podman API has not returned an error, but the image \"%s:%s\" could not be found on this server. Likely the image could not be pulled from remote because it does not exist. It's best to check the logs of the deployment agent.", app, version))
|
|
}
|
|
} else {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|