-
Notifications
You must be signed in to change notification settings - Fork 4
feat: 🚧 Add stack with docker-compose generation #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gonzariosm
wants to merge
7
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8aee58d
feat: :construction: Add stack with docker-compose generation
97567bc
docs: :memo: updated the doc for image package
f8ba02c
feat: :sparkles: Added AddWithImage stack function
6ef4ed9
feat: :construction: [WIP] moved dockercompose to utils
1a3ee4a
fix: :bug: Fix utils adding new package dockercompose
f007dd5
feat: Added ImageProviderName type
318e2af
feat: Added ImageProvider type
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Package image represents a cloud stack images operations under the `/cloud/stack/image` API endpoint. | ||
| package image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package image | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/sitehostnz/gosh/pkg/models" | ||
| ) | ||
|
|
||
| // GetImageByCode returns a image by code. | ||
| func (s *Client) GetImageByCode(ctx context.Context, request GetRequest) (response models.Image, err error) { | ||
| images, err := s.ListImages(ctx) | ||
| if err != nil { | ||
| return response, err | ||
| } | ||
|
|
||
| for _, image := range images.Return { | ||
| if image.Code == request.Code { | ||
| return image, nil | ||
| } | ||
| } | ||
|
|
||
| return response, errors.New("image not found") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package image | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| // ListImages returns a list of images. | ||
| func (s *Client) ListImages(ctx context.Context) (response GetResponse, err error) { | ||
| uri := "cloud/stack/image/list_all.json" | ||
|
|
||
| req, err := s.client.NewRequest("GET", uri, "") | ||
| if err != nil { | ||
| return response, err | ||
| } | ||
|
|
||
| if err := s.client.Do(ctx, req, &response); err != nil { | ||
| return response, err | ||
| } | ||
|
|
||
| return response, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package image | ||
|
|
||
| import ( | ||
| "github.com/sitehostnz/gosh/pkg/api" | ||
| ) | ||
|
|
||
| type ( | ||
| // Client is a Service to work with API. | ||
| Client struct { | ||
| client *api.Client | ||
| } | ||
| ) | ||
|
|
||
| // New is an initialisation function. | ||
| func New(c *api.Client) *Client { | ||
| return &Client{ | ||
| client: c, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package image | ||
|
|
||
| type ( | ||
| // GetRequest is the request to get a image by code. | ||
| GetRequest struct { | ||
| Code string `json:"code"` | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package image | ||
|
|
||
| import "github.com/sitehostnz/gosh/pkg/models" | ||
|
|
||
| type ( | ||
| // GetResponse is the response that returns a images list. | ||
| GetResponse struct { | ||
| Return []models.Image `json:"return"` | ||
| models.APIResponse | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package models | ||
|
|
||
| type ( | ||
| // DockerCompose represents a docker-compose.yml file. | ||
| // See https://docs.docker.com/compose/compose-file/ | ||
|
|
||
| // Service represents a service in the docker-compose.yml file. | ||
| Service struct { | ||
| ContainerName string `yaml:"container_name"` | ||
| Environment []string `yaml:"environment"` | ||
| Expose []string `yaml:"expose"` | ||
| Image string `yaml:"image"` | ||
| Labels []string `yaml:"labels"` | ||
| Restart string `yaml:"restart"` | ||
| Volumes []string `yaml:"volumes"` | ||
| } | ||
|
|
||
| // Networks represents the networks in the docker-compose.yml file. | ||
| Networks struct { | ||
| Default DefaultNetwork `yaml:"default"` | ||
| } | ||
|
|
||
| // DefaultNetwork represents the default network in the docker-compose.yml file. | ||
| DefaultNetwork struct { | ||
| External ExternalNetwork `yaml:"external"` | ||
| } | ||
|
|
||
| // ExternalNetwork represents the external network in the docker-compose.yml file. | ||
| ExternalNetwork struct { | ||
| Name string `yaml:"name"` | ||
| } | ||
|
|
||
| // DockerCompose represents a docker-compose.yml file. | ||
| DockerCompose struct { | ||
| Version string `yaml:"version"` | ||
| Services map[string]Service `yaml:"services"` | ||
| Networks Networks `yaml:"networks"` | ||
| } | ||
|
|
||
| // GenerateDockerComposeRequest represents the construction / setup of a docker compose. | ||
| GenerateDockerComposeRequest struct { | ||
| Name string `json:"name"` | ||
| Label string `json:"label"` | ||
| RegistryPath string `json:"registry_path"` | ||
| ImageCode string `json:"image_code"` | ||
| } | ||
|
|
||
| // BuildDockerCompose represents the construction / setup of a docker compose. | ||
| BuildDockerCompose struct { | ||
| Name string `json:"name"` | ||
| Label string `json:"label"` | ||
| Image string `json:"image"` | ||
| Type string `json:"type"` | ||
| Ports []string `yaml:"ports"` | ||
| Volumes []string `yaml:"volumes"` | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,82 @@ | ||
| package models | ||
|
|
||
| import "github.com/sitehostnz/gosh/pkg/utils" | ||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| ) | ||
|
|
||
| type ( | ||
| // Image represents an image in the cloud images api. | ||
| Image struct { | ||
| ID string `json:"id"` | ||
| ClientID string `json:"client_id"` | ||
| Label string `json:"label"` | ||
| Code string `json:"code"` | ||
| Version string `json:"version"` | ||
| Labels string `json:"labels"` | ||
| Changelog string `json:"changelog"` | ||
| DateAdded string `json:"date_added"` | ||
| DateUpdated string `json:"date_updated"` | ||
| IsPublic utils.MaybeBool `json:"is_public"` | ||
| IsMissing utils.MaybeBool `json:"is_missing"` | ||
| ProjectID string `json:"project_id"` | ||
| RegistryID string `json:"registry_id"` | ||
| ForkedFrom string `json:"forked_from"` | ||
| Pending string `json:"pending"` | ||
| ClientName string `json:"client_name"` | ||
| ImageType string `json:"image_type"` | ||
| RegistryURL string `json:"registry_url"` | ||
| VersionCount int `json:"version_count"` | ||
| ContainerCount int `json:"container_count"` | ||
| BuildStatus string `json:"build_status"` | ||
| ID string `json:"id"` | ||
| ClientID string `json:"client_id"` | ||
| Label string `json:"label"` | ||
| Code string `json:"code"` | ||
| Labels struct { | ||
| NzSitehostImageVolumes struct { | ||
| Source any `json:"source"` | ||
| Hash string `json:"hash"` | ||
| Volumes map[string]Volume `json:"volumes"` | ||
| } `json:"nz.sitehost.image.volumes"` | ||
| NzSitehostImageProvider string `json:"nz.sitehost.image.provider"` | ||
gonzariosm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NzSitehostImageType string `json:"nz.sitehost.image.type"` | ||
gonzariosm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NzSitehostImageLabel string `json:"nz.sitehost.image.label"` | ||
gonzariosm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NzSitehostImagePorts PortList `json:"nz.sitehost.image.ports"` | ||
gonzariosm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } `json:"labels"` | ||
| Changelog string `json:"changelog"` | ||
| DateAdded string `json:"date_added"` | ||
| DateUpdated string `json:"date_updated"` | ||
| IsPublic string `json:"is_public"` | ||
| IsMissing string `json:"is_missing"` | ||
| ProjectID string `json:"project_id"` | ||
| RegistryID string `json:"registry_id"` | ||
| ForkedFrom any `json:"forked_from"` | ||
| Pending any `json:"pending"` | ||
| Versions []struct { | ||
| ID string `json:"id"` | ||
| ClientID string `json:"client_id"` | ||
| ImageID string `json:"image_id"` | ||
| Version string `json:"version"` | ||
| Labels string `json:"labels"` | ||
| DateAdded string `json:"date_added"` | ||
| DateUpdated string `json:"date_updated"` | ||
| IsMissing string `json:"is_missing"` | ||
| ForceConfig string `json:"force_config"` | ||
| BuildID string `json:"build_id"` | ||
| BuildStatus string `json:"build_status"` | ||
| Pending string `json:"pending"` | ||
| } `json:"versions"` | ||
| RegistryPath string `json:"registry_path,omitempty"` | ||
| } | ||
|
|
||
| // PortList represents a port list in the cloud images api. | ||
| PortList map[string]Port | ||
|
|
||
| // Port represents a port in the cloud images api. | ||
| Port struct { | ||
| Protocol string `json:"protocol"` | ||
| Publish bool `json:"publish"` | ||
| Exposed bool `json:"exposed"` | ||
| } | ||
|
|
||
| // Volume represents a volume in the cloud images api. | ||
| Volume struct { | ||
| Dest string `json:"dest"` | ||
| Mode string `json:"mode"` | ||
| } | ||
| ) | ||
|
|
||
| // UnmarshalJSON implements the json.Unmarshaler interface to fix the port list format. | ||
| func (p *PortList) UnmarshalJSON(data []byte) error { | ||
| if bytes.Equal(data, []byte("[]")) { | ||
| *p = make(map[string]Port) | ||
| return nil | ||
| } | ||
| var m map[string]Port | ||
| err := json.Unmarshal(data, &m) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| *p = m | ||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.