internal

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProdImages = []string{
		"ghostwriter_production_django", "ghostwriter_production_nginx",
		"ghostwriter_production_redis", "ghostwriter_production_postgres",
		"ghostwriter_production_graphql", "ghostwriter_production_queue",
		"ghostwriter_production_collab_server",
	}
	SysProdImages = []string{
		"ghostwriter_django", "ghostwriter_nginx",
		"ghostwriter_redis", "ghostwriter_postgres",
		"ghostwriter_hasura", "ghostwriter_collab_server",
	}
	DevImages = []string{
		"ghostwriter_local_django", "ghostwriter_local_redis",
		"ghostwriter_local_postgres", "ghostwriter_local_graphql",
		"ghostwriter_local_queue", "ghostwriter_local_collab_server",
		"ghostwriter_local_frontend",
	}
)

Vars for tracking the list of Ghostwriter images Used for filtering the list of containers returned by the Docker client

Functions

func AskForConfirmation added in v0.2.12

func AskForConfirmation(s string) bool

AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user. Original source: https://gist.github.com/r0l1/3dcbb0c8f6cfe9c66ab8008f55f8f28b

func CheckLatestVersionNag added in v1.0.0

func CheckLatestVersionNag(docker *DockerInterface)

func CheckPath

func CheckPath(cmd string) bool

CheckPath checks the $PATH environment variable for a given "cmd" and return a "bool" indicating if it exists.

func Contains

func Contains(slice []string, target string) bool

Contains checks if a slice of strings ("slice" parameter) contains a given string ("search" parameter).

func DirExists

func DirExists(path string) bool

DirExists determines if a given string is a valid directory. Reference: https://golangcode.com/check-if-a-file-exists/

func FetchLatestRelease added in v1.0.0

func FetchLatestRelease() (string, error)

FetchLatestRelease fetches the latest Ghostwriter release tag from GitHub. This is a convenience wrapper around GetRemoteVersion for the specific case of checking the Ghostwriter repository.

func FileExists

func FileExists(path string) bool

FileExists determines if a given string is a valid filepath. Reference: https://golangcode.com/check-if-a-file-exists/

func GenerateCertificatePackage

func GenerateCertificatePackage(path string) error

GenerateCertificatePackage generate TLS certificates and Diffie-Helman parameters file using Go.

func GenerateRandomPassword

func GenerateRandomPassword(pwLength int, safe bool) string

GenerateRandomPassword generates a random password of the given length The password will be comprised of a-zA-Z0-9 and !@#$%^&*()_-+=/?<>., Special characters exclude the following: '";:`~\/| Exclusions are to help avoid issues with escaping and breaking quotes in env files

func GetCwdFromExe

func GetCwdFromExe() string

GetCwdFromExe gets the current working directory based on "ghostwriter-cli" location.

func GetDockerDirFromMode added in v1.0.0

func GetDockerDirFromMode(mode DockerMode) string

Gets the directory that the docker-compose and other files are in, depending on the run mode

func GetLocalGhostwriterVersion

func GetLocalGhostwriterVersion() (string, error)

GetLocalGhostwriterVersion fetches the local Ghostwriter version from the "VERSION" file.

func GetRemoteVersion added in v0.2.26

func GetRemoteVersion(owner string, repository string) (string, string, error)

GetRemoteVersion fetches the latest version information from GitHub's API for the given repository. It includes proper headers to avoid rate limiting and uses struct-based unmarshaling for type safety.

func MigrateFile added in v1.0.0

func MigrateFile(sourcePath, destPath string, perm os.FileMode, confirm bool) (bool, error)

MigrateFile copies a file from source to destination with atomic write and permission handling. If confirm is true and the destination exists, it asks the user for confirmation to overwrite. Returns true if the file was migrated, false if it was skipped.

func PrepareSettingsDirectory added in v1.0.0

func PrepareSettingsDirectory(path string) error

PrepareSettingsDirectory creates the settings directory for custom Django configuration files and populates it with a helpful README if it doesn't already exist.

Types

type Configuration

type Configuration struct {
	Key string
	Val string
}

Configuration is a custom type for storing configuration values as Key:Val pairs.

type Container

type Container struct {
	ID     string
	Image  string
	Status string
	Ports  []container.PortSummary
	Name   string
}

Container is a custom type for storing container information similar to output from "docker containers ls".

type Containers

type Containers []Container

Containers is a collection of Container structs

func (Containers) Len

func (c Containers) Len() int

Len returns the length of a Containers struct

func (Containers) Less

func (c Containers) Less(i, j int) bool

Less determines if one Container is less than another Container

func (Containers) Swap

func (c Containers) Swap(i, j int)

Swap exchanges the position of two Container values in a Containers struct

type DockerInterface added in v1.0.0

type DockerInterface struct {
	// Directory that docker compose file resides in
	Dir string
	// Docker compose filename to use, without directory
	ComposeFile string
	// Use development image names and environment settings instead of production ones
	UseDevInfra bool
	// Whether GW-CLI should download and write the compose file
	ManageComposeFile bool

	// Docker environmental variables
	Env *GWEnvironment
	// contains filtered or unexported fields
}

func GetDockerInterface added in v1.0.0

func GetDockerInterface(mode DockerMode) *DockerInterface

Gets the docker interface, checking how to run docker/podman, etc

func (*DockerInterface) BackupMediaFiles added in v1.0.0

func (this *DockerInterface) BackupMediaFiles() error

BackupMediaFiles executes the "docker compose" command to back up the media files to a tar.gz archive in the postgres_data_backups volume

func (*DockerInterface) CopyVolume added in v1.0.0

func (this *DockerInterface) CopyVolume(sourceVol, destVol string) error

CopyVolume copies data from sourceVol to destVol using a temporary Alpine container. This is useful for migrating data between volumes with different names.

func (*DockerInterface) Down added in v1.0.0

func (this *DockerInterface) Down(opts *DownOptions) error

Take down all containers. `opts` are optional

func (*DockerInterface) FetchLogs added in v1.0.0

func (this *DockerInterface) FetchLogs(containerName string, lines string) []string

Gets logs from a container

func (*DockerInterface) GetComposeProjectName added in v1.0.0

func (this *DockerInterface) GetComposeProjectName() string

Gets the docker compose project name

func (*DockerInterface) GetDaemonClient added in v1.0.0

func (this *DockerInterface) GetDaemonClient() (*client.Client, error)

Connects to the docker daemon

func (*DockerInterface) GetRunning added in v1.0.0

func (this *DockerInterface) GetRunning() Containers

Gets a list of all running docker containers (including outside of this project)

func (*DockerInterface) GetVersion added in v1.0.0

func (this *DockerInterface) GetVersion() (string, error)

Gets the currently installed version of Ghostwriter

func (*DockerInterface) GetVolumeNameFromConfig added in v1.0.0

func (this *DockerInterface) GetVolumeNameFromConfig(volumeKey string) (string, error)

GetVolumeNameFromConfig extracts the actual volume name from the Docker Compose configuration. The volumeKey is the logical name (e.g., "production_postgres_data"). Returns the actual Docker volume name (e.g., "ghostwriter_production_postgres_data").

func (*DockerInterface) IsDjangoStarted added in v1.0.0

func (this *DockerInterface) IsDjangoStarted() bool

Determine if the Django application has completed startup based on the "Application startup complete" log message.

func (*DockerInterface) IsPostgresStarted added in v1.0.0

func (this *DockerInterface) IsPostgresStarted() bool

Check if PostgreSQL is having trouble starting due to a password mismatch.

func (*DockerInterface) IsServiceRunning added in v1.0.0

func (this *DockerInterface) IsServiceRunning(containerName string) bool

Determine if the container with the specified name is running

func (*DockerInterface) ListVolumes added in v1.0.0

func (this *DockerInterface) ListVolumes(nameFilter string) ([]string, error)

ListVolumes returns a list of Docker volumes matching the given name filter. The filter can be a simple string that will be matched as a prefix.

func (*DockerInterface) RunCmd added in v1.0.0

func (this *DockerInterface) RunCmd(args ...string) error

Runs docker/podman with the specified additional arguments, in the proper CWD with the env and compose files. Basis for most of the other Run commands.

func (*DockerInterface) RunCmdWithOutput added in v1.0.0

func (this *DockerInterface) RunCmdWithOutput(args ...string) (string, error)

Similar to `RunCmd` but returns stdout

func (*DockerInterface) RunComposeCmd added in v1.0.0

func (this *DockerInterface) RunComposeCmd(args ...string) error

Runs a `docker compose` subcommand, pointing to the configured compose file, with additional arguments.

func (*DockerInterface) RunDjangoManageCommand added in v1.0.0

func (this *DockerInterface) RunDjangoManageCommand(args ...string) error

Runs the django manage.py script, with the specified arguments

func (*DockerInterface) Up added in v1.0.0

func (this *DockerInterface) Up() error

Bring all containers up

func (*DockerInterface) ValidateContainersRunning added in v1.0.0

func (this *DockerInterface) ValidateContainersRunning() error

ValidateContainersRunning checks that Ghostwriter containers are running and match the current mode. Returns an error with a user-friendly message if validation fails.

func (*DockerInterface) VerifyVolumeCopy added in v1.0.0

func (this *DockerInterface) VerifyVolumeCopy(sourceVol, destVol string) (int, int, error)

VerifyVolumeCopy compares file counts between source and destination volumes. Returns the file count in each volume and any error encountered.

func (*DockerInterface) VerifyVolumeExists added in v1.0.0

func (this *DockerInterface) VerifyVolumeExists(volumeName string) bool

VerifyVolumeExists checks if a Docker volume with the given name exists.

func (*DockerInterface) WaitForDjango added in v1.0.0

func (this *DockerInterface) WaitForDjango() bool

Determine if the Ghostwriter application has completed startup

type DockerMode added in v1.0.0

type DockerMode string

Run mode - specifies where to get dockerfiles and whether to run dev or prod

const (
	// Use source in exe's directory in dev mode
	ModeLocalDev DockerMode = "local-dev"
	// Use source in exe's directory in prod mode
	ModeLocalProd DockerMode = "local-prod"
	// Download and manage dockerfiles and run in prod mode
	ModeProd DockerMode = "prod"
)

func (*DockerMode) Set added in v1.0.0

func (e *DockerMode) Set(v string) error

func (*DockerMode) String added in v1.0.0

func (e *DockerMode) String() string

cobra pvalue.Value implementation for argument parsing

func (*DockerMode) Type added in v1.0.0

func (e *DockerMode) Type() string

type DownOptions added in v1.0.0

type DownOptions struct {
	// Pass `--volumes` to delete the project's volumes as well (will lose data!)
	Volumes bool
	// Pass `--remove-orphans` to delete orphaned service containers
	RemoveOrphans bool
}

Options for `Down`

type GWEnvironment added in v1.0.0

type GWEnvironment struct {
	// contains filtered or unexported fields
}

func ReadEnv added in v1.0.0

func ReadEnv(dir string) (*GWEnvironment, error)

func (*GWEnvironment) AppendHost added in v1.0.0

func (this *GWEnvironment) AppendHost(key string, host string)

func (*GWEnvironment) Get added in v1.0.0

func (this *GWEnvironment) Get(key string) string

func (*GWEnvironment) GetAll added in v1.0.0

func (this *GWEnvironment) GetAll() []Configuration

func (*GWEnvironment) GetBool added in v1.0.0

func (this *GWEnvironment) GetBool(key string) bool

func (*GWEnvironment) RemoveHost added in v1.0.0

func (this *GWEnvironment) RemoveHost(key string, host string)

func (*GWEnvironment) Save added in v1.0.0

func (this *GWEnvironment) Save()

func (*GWEnvironment) Set added in v1.0.0

func (this *GWEnvironment) Set(key string, val string)

func (*GWEnvironment) SetDev added in v1.0.0

func (this *GWEnvironment) SetDev()

func (*GWEnvironment) SetProd added in v1.0.0

func (this *GWEnvironment) SetProd()

type MigrationResult added in v1.0.0

type MigrationResult struct {
	Migrated int
	Skipped  int
	Failed   int
	Errors   []error
}

MigrationResult tracks the outcome of a migration operation.

func MigrateDirectory added in v1.0.0

func MigrateDirectory(sourceDir, destDir string, confirm bool) (*MigrationResult, error)

MigrateDirectory recursively copies all files from sourceDir to destDir. If confirm is true, it asks for confirmation before overwriting existing files. Returns a MigrationResult with statistics about the operation.

func (*MigrationResult) AddError added in v1.0.0

func (r *MigrationResult) AddError(err error)

AddError adds an error to the migration result and increments the failure counter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL