refactor: remove internal/domain package, move types to correct packages
- ImageID + ContainerID → internal/docker/types.go - UnparsedURL → internal/service/webhook/types.go - Delete internal/domain/ entirely - Update all imports throughout the codebase
This commit is contained in:
@@ -26,7 +26,7 @@ import (
|
||||
"go.uber.org/fx"
|
||||
|
||||
"git.eeqj.de/sneak/upaas/internal/config"
|
||||
"git.eeqj.de/sneak/upaas/internal/domain"
|
||||
|
||||
"git.eeqj.de/sneak/upaas/internal/logger"
|
||||
)
|
||||
|
||||
@@ -117,7 +117,7 @@ type BuildImageOptions struct {
|
||||
func (c *Client) BuildImage(
|
||||
ctx context.Context,
|
||||
opts BuildImageOptions,
|
||||
) (domain.ImageID, error) {
|
||||
) (ImageID, error) {
|
||||
if c.docker == nil {
|
||||
return "", ErrNotConnected
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func buildPortConfig(ports []PortMapping) (nat.PortSet, nat.PortMap) {
|
||||
func (c *Client) CreateContainer(
|
||||
ctx context.Context,
|
||||
opts CreateContainerOptions,
|
||||
) (domain.ContainerID, error) {
|
||||
) (ContainerID, error) {
|
||||
if c.docker == nil {
|
||||
return "", ErrNotConnected
|
||||
}
|
||||
@@ -242,11 +242,11 @@ func (c *Client) CreateContainer(
|
||||
return "", fmt.Errorf("failed to create container: %w", err)
|
||||
}
|
||||
|
||||
return domain.ContainerID(resp.ID), nil
|
||||
return ContainerID(resp.ID), nil
|
||||
}
|
||||
|
||||
// StartContainer starts a container.
|
||||
func (c *Client) StartContainer(ctx context.Context, containerID domain.ContainerID) error {
|
||||
func (c *Client) StartContainer(ctx context.Context, containerID ContainerID) error {
|
||||
if c.docker == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (c *Client) StartContainer(ctx context.Context, containerID domain.Containe
|
||||
}
|
||||
|
||||
// StopContainer stops a container.
|
||||
func (c *Client) StopContainer(ctx context.Context, containerID domain.ContainerID) error {
|
||||
func (c *Client) StopContainer(ctx context.Context, containerID ContainerID) error {
|
||||
if c.docker == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
@@ -282,7 +282,7 @@ func (c *Client) StopContainer(ctx context.Context, containerID domain.Container
|
||||
// RemoveContainer removes a container.
|
||||
func (c *Client) RemoveContainer(
|
||||
ctx context.Context,
|
||||
containerID domain.ContainerID,
|
||||
containerID ContainerID,
|
||||
force bool,
|
||||
) error {
|
||||
if c.docker == nil {
|
||||
@@ -302,7 +302,7 @@ func (c *Client) RemoveContainer(
|
||||
// ContainerLogs returns the logs for a container.
|
||||
func (c *Client) ContainerLogs(
|
||||
ctx context.Context,
|
||||
containerID domain.ContainerID,
|
||||
containerID ContainerID,
|
||||
tail string,
|
||||
) (string, error) {
|
||||
if c.docker == nil {
|
||||
@@ -338,7 +338,7 @@ func (c *Client) ContainerLogs(
|
||||
// IsContainerRunning checks if a container is running.
|
||||
func (c *Client) IsContainerRunning(
|
||||
ctx context.Context,
|
||||
containerID domain.ContainerID,
|
||||
containerID ContainerID,
|
||||
) (bool, error) {
|
||||
if c.docker == nil {
|
||||
return false, ErrNotConnected
|
||||
@@ -355,7 +355,7 @@ func (c *Client) IsContainerRunning(
|
||||
// IsContainerHealthy checks if a container is healthy.
|
||||
func (c *Client) IsContainerHealthy(
|
||||
ctx context.Context,
|
||||
containerID domain.ContainerID,
|
||||
containerID ContainerID,
|
||||
) (bool, error) {
|
||||
if c.docker == nil {
|
||||
return false, ErrNotConnected
|
||||
@@ -379,7 +379,7 @@ const LabelUpaasID = "upaas.id"
|
||||
|
||||
// ContainerInfo contains basic information about a container.
|
||||
type ContainerInfo struct {
|
||||
ID domain.ContainerID
|
||||
ID ContainerID
|
||||
Running bool
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ func (c *Client) FindContainerByAppID(
|
||||
ctr := containers[0]
|
||||
|
||||
return &ContainerInfo{
|
||||
ID: domain.ContainerID(ctr.ID),
|
||||
ID: ContainerID(ctr.ID),
|
||||
Running: ctr.State == "running",
|
||||
}, nil
|
||||
}
|
||||
@@ -483,7 +483,7 @@ func (c *Client) CloneRepo(
|
||||
|
||||
// RemoveImage removes a Docker image by ID or tag.
|
||||
// It returns nil if the image was successfully removed or does not exist.
|
||||
func (c *Client) RemoveImage(ctx context.Context, imageID domain.ImageID) error {
|
||||
func (c *Client) RemoveImage(ctx context.Context, imageID ImageID) error {
|
||||
_, err := c.docker.ImageRemove(ctx, imageID.String(), image.RemoveOptions{
|
||||
Force: true,
|
||||
PruneChildren: true,
|
||||
@@ -498,7 +498,7 @@ func (c *Client) RemoveImage(ctx context.Context, imageID domain.ImageID) error
|
||||
func (c *Client) performBuild(
|
||||
ctx context.Context,
|
||||
opts BuildImageOptions,
|
||||
) (domain.ImageID, error) {
|
||||
) (ImageID, error) {
|
||||
// Create tar archive of build context
|
||||
tarArchive, err := archive.TarWithOptions(opts.ContextDir, &archive.TarOptions{})
|
||||
if err != nil {
|
||||
@@ -543,7 +543,7 @@ func (c *Client) performBuild(
|
||||
return "", fmt.Errorf("failed to inspect image: %w", inspectErr)
|
||||
}
|
||||
|
||||
return domain.ImageID(inspect.ID), nil
|
||||
return ImageID(inspect.ID), nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
@@ -619,7 +619,7 @@ func (c *Client) performClone(ctx context.Context, cfg *cloneConfig) (*CloneResu
|
||||
func (c *Client) createGitContainer(
|
||||
ctx context.Context,
|
||||
cfg *cloneConfig,
|
||||
) (domain.ContainerID, error) {
|
||||
) (ContainerID, error) {
|
||||
gitSSHCmd := "ssh -i /keys/deploy_key -o StrictHostKeyChecking=no"
|
||||
|
||||
// Build the git command using environment variables to avoid shell injection.
|
||||
@@ -676,10 +676,10 @@ func (c *Client) createGitContainer(
|
||||
return "", fmt.Errorf("failed to create git container: %w", err)
|
||||
}
|
||||
|
||||
return domain.ContainerID(resp.ID), nil
|
||||
return ContainerID(resp.ID), nil
|
||||
}
|
||||
|
||||
func (c *Client) runGitClone(ctx context.Context, containerID domain.ContainerID) (*CloneResult, error) {
|
||||
func (c *Client) runGitClone(ctx context.Context, containerID ContainerID) (*CloneResult, error) {
|
||||
err := c.docker.ContainerStart(ctx, containerID.String(), container.StartOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to start git container: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user