Documentation ¶
Overview ¶
Copyright 2022 Nethermind
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 Nethermind ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func ContainerNameWithTag(containerName, tag string) string
- type ContainerInfo
- type ContainerLogsMergedOptions
- type DockerServiceManager
- func (d *DockerServiceManager) BuildImageFromURI(remote string, tag string, buildArgs map[string]*string) (err error)
- func (d *DockerServiceManager) ContainerID(containerName string) (string, error)
- func (d *DockerServiceManager) ContainerIP(container string) (string, error)
- func (d *DockerServiceManager) ContainerLogs(containerVar, service string) (string, error)
- func (d *DockerServiceManager) ContainerLogsMerged(ctx context.Context, w io.Writer, services map[string]string, ...) error
- func (d *DockerServiceManager) ContainerNetworks(container string) ([]string, error)
- func (d *DockerServiceManager) ContainerStatus(container string) (common.Status, error)
- func (d *DockerServiceManager) Image(container string) (string, error)
- func (d *DockerServiceManager) ImageExist(image string) (bool, error)
- func (d *DockerServiceManager) ImageRemove(imageVar string) error
- func (d *DockerServiceManager) IsRunning(ct string) (bool, error)
- func (d *DockerServiceManager) LoadImageContext(path string) (io.ReadCloser, error)
- func (d *DockerServiceManager) NetworkConnect(container, network string) error
- func (d *DockerServiceManager) NetworkDisconnect(container, network string) error
- func (d *DockerServiceManager) PS() ([]ContainerInfo, error)
- func (d *DockerServiceManager) Pull(imageVar string) error
- func (d *DockerServiceManager) Run(image string, options RunOptions) (err error)
- func (d *DockerServiceManager) Start(containerVar string) error
- func (d *DockerServiceManager) Stop(container string) error
- func (d *DockerServiceManager) Wait(container string, condition dockerCt.WaitCondition) (<-chan dockerCt.WaitResponse, <-chan error)
- type Mount
- type Port
- type RunOptions
- type VolumeType
- type WaitExitError
- type WaitResponse
Examples ¶
Constants ¶
const ( ServiceCtSlashingData = "sedge-validator-slashing-data-manager" ServiceCtValidatorImport = "sedge-validator-import" DefaultSedgeValidatorClient = "sedge-validator-client" DefaultSedgeExecutionClient = "sedge-execution-client" DefaultSedgeConsensusClient = "sedge-consensus-client" )
const NetworkHost = "host"
Variables ¶
Functions ¶
func ContainerNameWithTag ¶
Types ¶
type ContainerInfo ¶ added in v1.6.0
type ContainerLogsMergedOptions ¶ added in v1.6.0
type DockerServiceManager ¶ added in v1.6.0
type DockerServiceManager struct {
// contains filtered or unexported fields
}
DockerServiceManager is an interface to the Docker Daemon for managing docker containers
func NewDockerServiceManager ¶ added in v1.6.0
func NewDockerServiceManager(dockerClient client.APIClient) *DockerServiceManager
NewDockerServiceManager returns a new instance of DockerServiceManager
func (*DockerServiceManager) BuildImageFromURI ¶ added in v1.6.0
func (d *DockerServiceManager) BuildImageFromURI(remote string, tag string, buildArgs map[string]*string) (err error)
BuildFromURL build an image from a Git repository URI or HTTP/HTTPS context URI.
func (*DockerServiceManager) ContainerID ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerID(containerName string) (string, error)
ContainerID retrieves the ID of a specified Docker container name. The function lists all containers and filters them by name. If a container with the specified name is found, its ID is returned. If no container with the specified name is found, the function returns an error.
func (*DockerServiceManager) ContainerIP ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerIP(container string) (string, error)
ContainerIP returns the IP address of the specified container
The function takes a container ID or name as input and returns its IP address as a string. If an error occurs while inspecting the container or if the container does not have any networks configured, function returns an empty string and an error. Possible errors that may occur are returned as error types defined in this package.
func (*DockerServiceManager) ContainerLogs ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerLogs(containerVar, service string) (string, error)
ContainerLogs returns the logs of a container. <service> is the name of the container for logging purposes. The function accepts a string parameter 'ctID', which represents the name or ID of the Docker container. The function attempts to fetch the logs and returns them as a string. If an error occurs during the process, it returns the error.
func (*DockerServiceManager) ContainerLogsMerged ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerLogsMerged(ctx context.Context, w io.Writer, services map[string]string, opts ContainerLogsMergedOptions) error
ContainerLogsMerged retrieves the merge of all logs of specified Docker containers. Spin up a goroutine for each container and write the logs to the provided io.Writer, and wait for all goroutines to finish. To cancel the process, use the provided context.
func (*DockerServiceManager) ContainerNetworks ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerNetworks(container string) ([]string, error)
ContainerNetworks returns the networks of the specified container
func (*DockerServiceManager) ContainerStatus ¶ added in v1.6.0
func (d *DockerServiceManager) ContainerStatus(container string) (common.Status, error)
ContainerStatus retrieves the status of a specified Docker container.
func (*DockerServiceManager) Image ¶ added in v1.6.0
func (d *DockerServiceManager) Image(container string) (string, error)
Image retrieves the image name associated with a specified Docker container. The function accepts a string parameter 'container', which represents the name or ID of the Docker container. It uses the ContainerInspect method of the Docker client to fetch the container's information. If the container is found and no error occurs, the function returns the image name as a string. If the container is not found or an error occurs during the inspection, the function returns an empty string and the error.
Example ¶
package main import ( "github.com/docker/docker/client" log "github.com/sirupsen/logrus" "github.com/NethermindEth/sedge/internal/pkg/services" ) func main() { // Create a new Docker client dockerClient, err := client.NewClientWithOpts(client.FromEnv) if err != nil { log.Fatal(err) } defer dockerClient.Close() // Create a new dockerServicemanager dm := services.NewDockerServiceManager(dockerClient) // Get the image name of a running container _, err = dm.Image("myContainer") if err != nil { log.Error(err) } }
Output:
func (*DockerServiceManager) ImageExist ¶ added in v1.6.0
func (d *DockerServiceManager) ImageExist(image string) (bool, error)
ImageExist checks if a specified Docker image exists.
func (*DockerServiceManager) ImageRemove ¶ added in v1.6.0
func (d *DockerServiceManager) ImageRemove(imageVar string) error
ImageRemove removes a specified Docker image.
func (*DockerServiceManager) IsRunning ¶ added in v1.6.0
func (d *DockerServiceManager) IsRunning(ct string) (bool, error)
func (*DockerServiceManager) LoadImageContext ¶ added in v1.6.0
func (d *DockerServiceManager) LoadImageContext(path string) (io.ReadCloser, error)
LoadImageContext loads an image context from a local path.
func (*DockerServiceManager) NetworkConnect ¶ added in v1.6.0
func (d *DockerServiceManager) NetworkConnect(container, network string) error
NetworkConnect connects a container to a network
func (*DockerServiceManager) NetworkDisconnect ¶ added in v1.6.0
func (d *DockerServiceManager) NetworkDisconnect(container, network string) error
NetworkDisconnect disconnects a container from a network
func (*DockerServiceManager) PS ¶ added in v1.6.0
func (d *DockerServiceManager) PS() ([]ContainerInfo, error)
PS lists all running containers along with their details
PS returns a slice of ContainerInfo structs, each representing one running container. ContainerInfo struct contains the ID, Name, Image, Command, Created, Ports, and Status of the container. If an error occurs while communicating with the Docker API, function returns nil and the error.
func (*DockerServiceManager) Pull ¶ added in v1.6.0
func (d *DockerServiceManager) Pull(imageVar string) error
Pull pulls a specified Docker image. The function attempts to pull the image and returns any error that occurs during the process.
func (*DockerServiceManager) Run ¶ added in v1.6.0
func (d *DockerServiceManager) Run(image string, options RunOptions) (err error)
Run is a method of DockerServiceManager that handles running a Docker container from an image. It creates the container from the specified image with the provided command arguments, connects the created container to the specified network, then starts the container.
After the container starts, the function waits for the container to exit. During the waiting process, it also listens for errors from the container. If an error is received, it prints the container logs and returns the error.
func (*DockerServiceManager) Start ¶ added in v1.6.0
func (d *DockerServiceManager) Start(containerVar string) error
Start initiates the start process of a specified Docker container. The function accepts a string parameter 'container', which represents the name or ID of the Docker container. It uses the ContainerStart method of the Docker client to start the container. If the container is successfully started, the function returns nil. If an error occurs during the start process, the function wraps the error with a custom message and returns it.
func (*DockerServiceManager) Stop ¶ added in v1.6.0
func (d *DockerServiceManager) Stop(container string) error
Stop attempts to stop a specified Docker dockerCt. The function first inspects the container to check if it's running. If the container is not found, it returns nil. If the container is running, it attempts to stop the container and returns any error that occurs during the process.
func (*DockerServiceManager) Wait ¶ added in v1.6.0
func (d *DockerServiceManager) Wait(container string, condition dockerCt.WaitCondition) (<-chan dockerCt.WaitResponse, <-chan error)
Wait waits for a specified Docker container to reach a certain condition. The function returns two channels: one for the wait response and one for any error that occurs during the wait process.
type Mount ¶ added in v1.6.0
type Mount struct { Type VolumeType Source string Target string }
type RunOptions ¶ added in v1.6.0
type VolumeType ¶ added in v1.6.0
type VolumeType string
const ( VolumeTypeBind VolumeType = "bind" VolumeTypeVolume VolumeType = "volume" )
type WaitExitError ¶ added in v1.6.0
type WaitExitError struct {
Message string `json:"Message,omitempty"`
}
WaitExitError container waiting error, if any
type WaitResponse ¶ added in v1.6.0
type WaitResponse struct { // error Error *WaitExitError `json:"Error,omitempty"` // Exit code of the container // Required: true StatusCode int64 `json:"StatusCode"` }
WaitResponse ContainerWaitResponse OK response to ContainerWait operation