Main Go Files in the Dewy Repository: A Complete Source Code Guide

The Dewy repository contains approximately 20 core Go files organized into packages for CLI entry points, configuration, container runtime abstraction, artifact fetching, registry communication, and caching, with cmd/dewy/main.go, dewy.go, and config.go serving as the primary orchestration layer.

The linyows/dewy repository implements a self-updating Go service capable of deploying binaries or containers while maintaining artifact caches and exposing administrative APIs. Understanding the main Go files in the Dewy repository is essential for contributors and operators who need to extend functionality or debug deployment workflows.

Core Entry Points and CLI Structure

The application exposes both a standalone binary interface and a library-style API for embedding.

cmd/dewy/main.go: The Application Entry Point

The cmd/dewy/main.go file contains the main function that bootstraps the entire application. It constructs a dewy.Env object containing stdout, stderr, command-line arguments, and version information, then delegates to dewy.RunCLI to initiate execution.


# Compile & run (the binary built by `go build ./cmd/dewy`)

dewy \
  --registry https://example.com/dewy \
  --command server \
  --port 8080:80 \
  --notify-slack https://hooks.slack.com/services/XXX/YYY/ZZZ

cli.go: Library-Style CLI Wrapper

The cli.go file provides the RunCLI function, which serves as the entry point for the library version of the CLI. It wires stdout/stderr, parses arguments, creates the structured logger, and initializes the core Dewy object before starting the run loop.

Central Orchestration and Configuration

These files implement the central Dewy struct and its configuration, handling the coordination between artifact fetching, deployment, and health checking.

dewy.go: The Core Engine

The dewy.go file defines the Dewy struct and implements the Start, Run, and RunContainer methods. This file orchestrates registry queries, artifact downloads, caching, deployment (binary or container), health checks, proxy routing, admin API exposure, and graceful shutdown. It is the primary integration point that wires together the container, artifact, registry, and notifier packages.

package main

import (
	"os"

	"github.com/linyows/dewy"
	"github.com/linyows/dewy/logging"
)

func main() {
	// Build a logger (wrapping slog)
	logger := logging.NewLogger(os.Stdout, logging.LevelInfo)

	// Minimal config – you could load from a file or flags
	cfg := dewy.Config{
		Registry: "https://example.com/dewy",
		Command:  dewy.SERVER,
		PortMappings: []dewy.PortMapping{
			{ProxyPort: 8080, ContainerPort: ptr(80)},
		},
	}

	// Create the core object
	app, err := dewy.New(cfg, logger)
	if err != nil {
		panic(err)
	}

	// Run once (no scheduler) – useful for tests or one‑shot deployments
	if err := app.Run(); err != nil {
		panic(err)
	}
}

// helper to obtain *int
func ptr(v int) *int { return &v }

config.go: Configuration Management

The config.go file contains the Config struct definition, which holds all flags and options including registry URL, command mode (server or task), container settings, notifier configuration, and port mappings. This configuration is used by both the CLI entry point and the core Dewy engine.

Container Runtime Abstraction

Dewy supports both Docker and Podman runtimes through a unified interface.

container/docker.go and container/podman.go

The container/docker.go and container/podman.go files implement the container runtime interface for Docker and Podman respectively. They handle operations such as running containers, stopping them, listing active containers, inspecting images, and executing health checks.

container/container.go: Shared Interfaces

The container/container.go file defines shared abstractions, types, and options used by both Docker and Podman implementations, ensuring a consistent API across different container runtimes.

container/healthcheck.go: Health Monitoring

The container/healthcheck.go file implements HTTP health probes against running containers, verifying that deployed services are ready to accept traffic before marking deployments as successful.

Artifact and Registry Management

These components handle fetching deployment artifacts and communicating with the Dewy registry service.

artifact/artifact.go and Implementations

The artifact/artifact.go file defines the generic artifact downloader interface. Concrete implementations reside in separate files:

registry/registry.go: Service Communication

The registry/registry.go file implements the gRPC and HTTP client for communicating with the Dewy registry service. It obtains latest release metadata and reports successful deployments. Generated protobuf stubs reside in registry/gen/dewy/.

Supporting Infrastructure

Additional packages provide notifications, caching, logging, and server integration.

notifier/notifier.go: Deployment Notifications

The notifier/notifier.go file defines the Notifier interface and factory for sending deployment notifications. Built-in implementations include:

Any struct implementing the Notifier interface can be injected into the configuration for custom notification channels.

type myNotifier struct{ logging.Logger }

func (n *myNotifier) Send(ctx context.Context, msg string) error {
	n.Logger.Info("custom notify", slog.String("msg", msg))
	return nil
}

// Register it in the config
cfg := dewy.Config{
    Notifier: &myNotifier{*logging.NewLogger(os.Stdout, logging.LevelInfo)},
}

kvs/kvs.go: Artifact Caching

The kvs/kvs.go file defines the abstract key-value store interface for caching downloaded artifacts. Concrete implementations include:

logging/logger.go: Structured Logging

The logging/logger.go file provides a thin wrapper around Go's slog package, adding structured fields and helper methods for consistent logging across the application.

starter.go: Server-Starter Integration

The starter.go file contains integration helpers for server-starter, enabling graceful restarts and socket passing in production deployments.

Summary

  • cmd/dewy/main.go serves as the application entry point, delegating to dewy.RunCLI after constructing the environment.
  • dewy.go contains the central Dewy struct that orchestrates registry queries, artifact downloads, deployments, and health checks.
  • config.go defines the configuration structure used by both CLI and core engine.
  • Container abstraction is implemented in container/docker.go, container/podman.go, and supporting files for runtime-agnostic operations.
  • Artifact management uses artifact/artifact.go with concrete implementations for S3, GCS, GitHub Releases, and OCI registries.
  • Registry communication is handled by registry/registry.go using gRPC/HTTP protocols.
  • Supporting packages include notifier/ for deployment notifications, kvs/ for artifact caching, logging/ for structured logs, and starter.go for server-starter integration.

Frequently Asked Questions

What is the purpose of the dewy.go file in the Dewy repository?

The dewy.go file defines the central Dewy struct and implements the primary orchestration logic including the Start, Run, and RunContainer methods. It coordinates interactions between the registry client, artifact fetchers, container runtime, and notification systems, effectively serving as the main control loop for the self-updating deployment engine.

How does Dewy support both Docker and Podman container runtimes?

Dewy abstracts container operations through the container/container.go interface, with concrete implementations provided in container/docker.go for Docker and container/podman.go for Podman. Both implementations expose identical methods for running, stopping, and inspecting containers, allowing the core engine in dewy.go to switch between runtimes based on configuration without requiring code changes.

What storage backends does Dewy support for caching artifacts?

The artifact caching system is defined in kvs/kvs.go, which provides a key-value store interface. Concrete implementations include kvs/file.go for local disk storage, kvs/redis.go for Redis backends, and kvs/consul.go for Consul integration. This modular design allows operators to choose appropriate storage based on infrastructure requirements, from single-node deployments to distributed clusters.

How can I extend Dewy to send notifications to a custom service?

You can implement the Notifier interface defined in notifier/notifier.go, which requires a Send(context.Context, string) error method. After implementing your custom notifier struct, inject it into the Config struct's Notifier field before calling dewy.New. The core engine automatically invokes your implementation during deployment events, enabling integration with arbitrary webhook services, message queues, or monitoring systems.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →