diff --git a/Taskfile.yaml b/Taskfile.yaml index 6717fa0..ef48b74 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -4,6 +4,7 @@ vars: PLATFORM: sulfone SERVICE: boron USER: kirinnee/ + REGISTRY_HOST: http://host.docker.internal:9001 includes: docker: tasks/Taskfile.docker.yaml diff --git a/docker_executor/docker.go b/docker_executor/docker.go index 1edc6f9..e034ea0 100644 --- a/docker_executor/docker.go +++ b/docker_executor/docker.go @@ -36,8 +36,8 @@ func (d *DockerClient) ListImages() ([]DockerImageReference, error) { var imageNames []DockerImageReference for _, image := range images { - for _, digest := range image.RepoDigests { - s, err := DockerImageToStruct(digest) + for _, tags := range image.RepoTags { + s, err := DockerImageToStruct(tags) if err != nil { return nil, err } @@ -116,8 +116,8 @@ func (d *DockerClient) GetCoordinatorImage() (DockerImageReference, error) { } - for _, digest := range latest.RepoDigests { - s, e := DockerImageToStruct(digest) + for _, tag := range latest.RepoTags { + s, e := DockerImageToStruct(tag) if e != nil { return DockerImageReference{}, e } diff --git a/docker_executor/domain_model.go b/docker_executor/domain_model.go index 579fcd2..4ce7c47 100644 --- a/docker_executor/domain_model.go +++ b/docker_executor/domain_model.go @@ -20,27 +20,22 @@ func InsertDash(uuid string) string { type DockerImageReference struct { Reference string - Sha string + Tag string } func DockerImageToString(image DockerImageReference) string { - return fmt.Sprintf("%s@sha256:%s", image.Reference, image.Sha) + return fmt.Sprintf("%s:%s", image.Reference, image.Tag) } func DockerImageToStruct(imageString string) (DockerImageReference, error) { - parts := strings.Split(imageString, "@") + parts := strings.Split(imageString, ":") if len(parts) != 2 { fmt.Println("Invalid image string format") return DockerImageReference{}, errors.New("invalid image string format") } - reference := parts[0] - shaWithPrefix := parts[1] - - sha := strings.TrimPrefix(shaWithPrefix, "sha256:") - return DockerImageReference{ - Reference: reference, - Sha: sha, + Reference: parts[0], + Tag: parts[1], }, nil } @@ -73,7 +68,7 @@ func DockerContainerNameToStruct(name string) (DockerContainerReference, error) SessionId: sessionId, }, nil } - return DockerContainerReference{}, errors.New("invalid container name") + return DockerContainerReference{}, errors.New("invalid container name: " + name) } type DockerVolumeReference struct { diff --git a/docker_executor/executor.go b/docker_executor/executor.go index f7390b3..cee9c7c 100644 --- a/docker_executor/executor.go +++ b/docker_executor/executor.go @@ -20,11 +20,11 @@ func (e Executor) missingPluginsImages(images []DockerImageReference) []DockerIm for _, plugin := range e.Template.Plugins { c := DockerImageReference{ Reference: plugin.DockerReference, - Sha: plugin.DockerSHA, + Tag: plugin.DockerTag, } found := false for _, i := range images { - if i.Reference == plugin.DockerReference && i.Sha == plugin.DockerSHA { + if i.Reference == plugin.DockerReference && i.Tag == plugin.DockerTag { found = true break } @@ -41,11 +41,11 @@ func (e Executor) missingProcessorImages(images []DockerImageReference) []Docker for _, processor := range e.Template.Processors { c := DockerImageReference{ Reference: processor.DockerReference, - Sha: processor.DockerSHA, + Tag: processor.DockerTag, } found := false for _, i := range images { - if i.Reference == processor.DockerReference && i.Sha == processor.DockerSHA { + if i.Reference == processor.DockerReference && i.Tag == processor.DockerTag { found = true break } @@ -100,7 +100,7 @@ func (e Executor) startProcessors(session string, temVolRef, workVolRef DockerVo semaphore <- 0 i := DockerImageReference{ Reference: processor.DockerReference, - Sha: processor.DockerSHA, + Tag: processor.DockerTag, } c := DockerContainerReference{ CyanId: processor.ID, @@ -159,7 +159,7 @@ func (e Executor) startPlugins(session string, temVolRef, workVolRef DockerVolum semaphore <- 0 i := DockerImageReference{ Reference: plugin.DockerReference, - Sha: plugin.DockerSHA, + Tag: plugin.DockerTag, } c := DockerContainerReference{ CyanId: plugin.ID, diff --git a/docker_executor/model.go b/docker_executor/model.go index 7ee4510..2731422 100644 --- a/docker_executor/model.go +++ b/docker_executor/model.go @@ -105,7 +105,7 @@ type RegistryPluginVersionPrincipalRes struct { CreatedAt string `json:"created_at"` Description string `json:"description"` DockerReference string `json:"dockerReference"` - DockerSha string `json:"dockerSha"` + DockerTag string `json:"dockerTag"` } type RegistryPluginRes struct { @@ -131,7 +131,7 @@ type RegistryProcessorVersionPrincipalRes struct { CreatedAt string `json:"created_at"` Description string `json:"description"` DockerReference string `json:"dockerReference"` - DockerSha string `json:"dockerSha"` + DockerTag string `json:"dockerTag"` } type RegistryProcessorRes struct { diff --git a/docker_executor/models.go b/docker_executor/models.go index 4dc9e26..39e9f6f 100644 --- a/docker_executor/models.go +++ b/docker_executor/models.go @@ -13,7 +13,7 @@ type PluginRes struct { CreatedAt string `json:"createdAt"` Description string `json:"description"` DockerReference string `json:"dockerReference"` - DockerSHA string `json:"dockerSha"` + DockerTag string `json:"dockerTag"` } type ProcessorRes struct { @@ -22,7 +22,7 @@ type ProcessorRes struct { CreatedAt string `json:"createdAt"` Description string `json:"description"` DockerReference string `json:"dockerReference"` - DockerSHA string `json:"dockerSha"` + DockerTag string `json:"dockerTag"` } type TemplateVersionPrincipalRes struct { @@ -31,9 +31,9 @@ type TemplateVersionPrincipalRes struct { CreatedAt string `json:"createdAt"` Description string `json:"description"` BlobDockerReference string `json:"blobDockerReference"` - BlobDockerSHA string `json:"blobDockerSha"` + BlobDockerTag string `json:"blobDockerTag"` TemplateDockerReference string `json:"templateDockerReference"` - TemplateDockerSHA string `json:"templateDockerSha"` + TemplateDockerTag string `json:"templateDockerTag"` } type TemplatePrincipalRes struct { diff --git a/docker_executor/registry.go b/docker_executor/registry.go index 76c75a0..5785d4c 100644 --- a/docker_executor/registry.go +++ b/docker_executor/registry.go @@ -14,6 +14,7 @@ type RegistryClient struct { func (rc RegistryClient) getProcessorVersion(username string, name string, version string) (RegistryProcessorVersionRes, error) { url := rc.Endpoint + "/api/v1/Processor/slug/" + username + "/" + name + "/versions/" + version + fmt.Println("🔍 Getting version of processor:", url) resp, err := http.Get(url) if err != nil { fmt.Printf("🚨 Error occurred making a request to %s: %v\n", url, err) @@ -31,7 +32,7 @@ func (rc RegistryClient) getProcessorVersion(username string, name string, versi if resp.StatusCode != http.StatusOK { fmt.Printf("🚨 Unexpected status code: %d. Body: %s\n", resp.StatusCode, body) - return RegistryProcessorVersionRes{}, err + return RegistryProcessorVersionRes{}, fmt.Errorf("unexpected status code: %d. Body: %s\n", resp.StatusCode, body) } var res RegistryProcessorVersionRes @@ -46,6 +47,7 @@ func (rc RegistryClient) getProcessorVersion(username string, name string, versi func (rc RegistryClient) getProcessorVersionLatest(username string, name string) (RegistryProcessorVersionRes, error) { url := rc.Endpoint + "/api/v1/Processor/slug/" + username + "/" + name + "/versions/latest" + fmt.Println("🔍 Getting latest version of processor:", url) resp, err := http.Get(url) if err != nil { fmt.Printf("🚨 Error occurred making a request to %s: %v\n", url, err) @@ -63,7 +65,7 @@ func (rc RegistryClient) getProcessorVersionLatest(username string, name string) if resp.StatusCode != http.StatusOK { fmt.Printf("🚨 Unexpected status code: %d. Body: %s\n", resp.StatusCode, body) - return RegistryProcessorVersionRes{}, err + return RegistryProcessorVersionRes{}, fmt.Errorf("unexpected status code: %d. Body: %s\n", resp.StatusCode, body) } var res RegistryProcessorVersionRes @@ -78,6 +80,7 @@ func (rc RegistryClient) getProcessorVersionLatest(username string, name string) func (rc RegistryClient) getPluginVersion(username string, name string, version string) (RegistryPluginVersionRes, error) { url := rc.Endpoint + "/api/v1/Plugin/slug/" + username + "/" + name + "/versions/" + version + fmt.Println("🔍 Getting version of plugin:", url) resp, err := http.Get(url) if err != nil { fmt.Printf("🚨 Error occurred making a request to %s: %v\n", url, err) @@ -95,7 +98,7 @@ func (rc RegistryClient) getPluginVersion(username string, name string, version if resp.StatusCode != http.StatusOK { fmt.Printf("🚨 Unexpected status code: %d. Body: %s\n", resp.StatusCode, body) - return RegistryPluginVersionRes{}, err + return RegistryPluginVersionRes{}, fmt.Errorf("unexpected status code: %d. Body: %s\n", resp.StatusCode, body) } var res RegistryPluginVersionRes @@ -110,6 +113,7 @@ func (rc RegistryClient) getPluginVersion(username string, name string, version func (rc RegistryClient) getPluginVersionLatest(username string, name string) (RegistryPluginVersionRes, error) { url := rc.Endpoint + "/api/v1/Plugin/slug/" + username + "/" + name + "/versions/latest" + fmt.Println("🔍 Getting latest version of plugin:", url) resp, err := http.Get(url) if err != nil { fmt.Printf("🚨 Error occurred making a request to %s: %v\n", url, err) @@ -127,7 +131,7 @@ func (rc RegistryClient) getPluginVersionLatest(username string, name string) (R if resp.StatusCode != http.StatusOK { fmt.Printf("🚨 Unexpected status code: %d. Body: %s\n", resp.StatusCode, body) - return RegistryPluginVersionRes{}, err + return RegistryPluginVersionRes{}, fmt.Errorf("unexpected status code: %d. Body: %s\n", resp.StatusCode, body) } var res RegistryPluginVersionRes diff --git a/docker_executor/template_executor.go b/docker_executor/template_executor.go index cd3f72b..6a9859c 100644 --- a/docker_executor/template_executor.go +++ b/docker_executor/template_executor.go @@ -46,10 +46,10 @@ func (de TemplateExecutor) missingTemplateVolumeImage(images []DockerImageRefere template := de.Template i := DockerImageReference{ Reference: template.BlobDockerReference, - Sha: template.BlobDockerSHA, + Tag: template.BlobDockerTag, } for _, image := range images { - if image.Reference == i.Reference && image.Sha == i.Sha { + if image.Reference == i.Reference && image.Tag == i.Tag { return false, i } } @@ -60,10 +60,10 @@ func (de TemplateExecutor) missingTemplateImages(images []DockerImageReference) template := de.Template i := DockerImageReference{ Reference: template.TemplateDockerReference, - Sha: template.TemplateDockerSHA, + Tag: template.TemplateDockerTag, } for _, image := range images { - if image.Reference == i.Reference && image.Sha == i.Sha { + if image.Reference == i.Reference && image.Tag == i.Tag { return false, i } } @@ -145,7 +145,7 @@ func (de TemplateExecutor) listContainersVolumesImages() ( func (de TemplateExecutor) startContainer(conRef DockerContainerReference) error { imageRef := DockerImageReference{ Reference: de.Template.TemplateDockerReference, - Sha: de.Template.TemplateDockerSHA, + Tag: de.Template.TemplateDockerTag, } err := de.Docker.CreateContainer(conRef, imageRef) if err != nil { @@ -168,7 +168,7 @@ func (de TemplateExecutor) startVolume(volRef DockerVolumeReference) error { } unzipImage := DockerImageReference{ Reference: de.Template.BlobDockerReference, - Sha: de.Template.BlobDockerSHA, + Tag: de.Template.BlobDockerTag, } unzipContainer := DockerContainerReference{ CyanId: de.Template.ID, diff --git a/main.go b/main.go index 393095a..adf2351 100644 --- a/main.go +++ b/main.go @@ -18,8 +18,16 @@ func main() { Commands: []*cli.Command{ { Name: "start", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "registry", + Aliases: []string{"r"}, + Value: "https://api.zinc.sulfone.raichu.cluster.atomi.cloud", + }, + }, Action: func(context *cli.Context) error { - server() + registry := context.String("registry") + server(registry) return nil }, }, diff --git a/server.go b/server.go index 503d5ee..b38f8a1 100644 --- a/server.go +++ b/server.go @@ -24,7 +24,7 @@ func stringifyErrors(e []error) []string { return errs } -func server() { +func server(registryEndpoint string) { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(200, docker_executor.StandardResponse{Status: "OK"}) @@ -85,7 +85,7 @@ func server() { merger := docker_executor.Merger{ ParallelismLimit: cpu, RegistryClient: docker_executor.RegistryClient{ - Endpoint: "https://api.zinc.sulfone.raichu.cluster.atomi.cloud", + Endpoint: registryEndpoint, }, Template: req.Template, SessionId: sessionId, @@ -642,7 +642,7 @@ func server() { m := docker_executor.Merger{ ParallelismLimit: cpu, RegistryClient: docker_executor.RegistryClient{ - Endpoint: "https://api.zinc.sulfone.raichu.cluster.atomi.cloud", + Endpoint: registryEndpoint, }, Template: req.Template, SessionId: sessionId, diff --git a/tasks/Taskfile.docker.yaml b/tasks/Taskfile.docker.yaml index 6d668e2..a760af3 100644 --- a/tasks/Taskfile.docker.yaml +++ b/tasks/Taskfile.docker.yaml @@ -9,7 +9,7 @@ tasks: desc: "Run docker images" cmds: - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock {{.USER}}{{.PLATFORM}}-{{.SERVICE}}:{{.CLI_ARGS |default "latest"}} setup - - docker run --rm -it -p 9000:9000 --network cyanprint -v /var/run/docker.sock:/var/run/docker.sock {{.USER}}{{.PLATFORM}}-{{.SERVICE}}:{{.CLI_ARGS |default "latest"}} + - docker run --rm -it -p 9000:9000 --network cyanprint -v /var/run/docker.sock:/var/run/docker.sock {{.USER}}{{.PLATFORM}}-{{.SERVICE}}:{{.CLI_ARGS |default "latest"}} start -r {{.REGISTRY_HOST}} push: desc: "Push docker images" cmds: