bundler

package
v0.0.0-...-96c172f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package bundler takes care of collecting file assets stored in different packages and putting them in a single place that might be accessible to the app or a third party static file server.

These are the kind of assets that can take care of collecting:

  • migration files
  • html templates
  • notification templates

Index

Constants

View Source
const (
	// StaticDir has the directory name where the static assets
	// should be placed.
	StaticDir string = "static"
	// AppDir contains the root app directory, where the output
	// binary should be placed.
	AppDir string = "app"
	// ConfDir is the directory where the configuration for the
	// app will be stored.
	ConfDir string = "app/config"
	// DBMigrationsDir is the directory where database migrations
	// should be placed.
	DBMigrationsDir string = "app/dbmigrations"
	// AppDataDir is the directory where additional files for the
	// app must be placed (the ones that won't be directly served
	// by any other app).
	AppDataDir string = "app/data"

	// AppDataHTMLTemplates is the directory where the html templates
	// should be placed.
	AppDataHTMLTemplates string = "app/data/html_templates"
	// AppDataNotificationTemplates is the directory for the email
	// notification templates.
	AppDataNotificationTemplates string = "app/data/notifications/templates"
)
View Source
const (
	// KeyBundlerCollectMigrations is the config key for a boolean value that enables
	// collecting the database migration files.
	KeyBundlerCollectMigrations = "bundler.migrations.collect"

	// KeyBundlerCollectMigrationsDstDir is the config key for a string value that
	// tells the bundler where to place the collected migrations.
	KeyBundlerCollectMigrationsDstDir = "bundler.migrations.dst"

	// KeyBundlerCollectMigrationsScanDirs  is the config key for migrations source dir.
	KeyBundlerCollectMigrationsScanDirs = "bundler.migrations.scan"

	// KeyBundlerMigrate is the config key for knowing if migrations should be applied.
	KeyBundlerMigrate = "bundler.migrations.migrate"
	// KeyBundlerPackDstDir is the config key for knowing where to place the files
	// to be packed with the bundler.
	KeyBundlerPackDstDir = "bundler.pack.dst"
	// KeyBundlerPackExtraDirs is the config key for knowing from where the files are
	// picked to be packed with the bundler.
	KeyBundlerPackExtraDirs = "bundler.pack.srcs"
	// KeyBundlerPackVariant defines the variant of the config to be put inside the bundle
	KeyBundlerPackVariant = "bundler.pack.variant"
)

Variables

This section is empty.

Functions

func ApplyMigrationsFromConfig

func ApplyMigrationsFromConfig(migrateVer string, v *viper.Viper,
	l logs.Logger, confPrefix string) error

ApplyMigrationsFromConfig reads the migrations firectory from config and applies them.

func CollectFiles

func CollectFiles(dstDir string, scanDirs []string) error

CollectFiles searches for files that must be collected in diferent directories and copies them in the bundle

func CollectMigrationsFromDir

func CollectMigrationsFromDir(path string, migrations MigrationFiles, issues []error,
	l logs.Logger) []error

CollectMigrationsFromDir scans a single direcotry

func CompressBundle

func CompressBundle(dstDir string) error

CompressBundle uses a call to exec.Command to run the `tar` utility to compress the bundle.

func ComputeFileHash

func ComputeFileHash(fname string) (string, error)

ComputeFileHash computes a hash for the content of a file

func CopyDir

func CopyDir(src, dst string) error

CopyDir copies one dir from source to dest ignoring symlinks, and setting a default mode

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func CopyMigrationFiles

func CopyMigrationFiles(src *MigrationPair, dst *MigrationPair) error

CopyMigrationFiles copies ap pair of migration files from one dir to another

func DataDirs

func DataDirs() map[string]string

DataDirs creates a map that returns pairs of "data target dir" to the "source data dir".

func ExecuteBundlerOperations

func ExecuteBundlerOperations(v *viper.Viper, l logs.Logger, confPrefix string)

ExecuteBundlerOperations parses the command line and environment to find operations that the bundler should execute: collect migrations, collect static files, run migrations, etc.. This function is a helper to be able to run those operations from the same server executable file.

func PrepareBundle

func PrepareBundle(projDir string, dstDir string, extraPkgsDirs []string,
	envName string) error

PrepareBundle collects all static files, data files to be used by the executable, and config file.

func PrepareBundleDirs

func PrepareBundleDirs(dstDir string) (string, error)

PrepareBundleDirs completely deletes the dstDir, and creates the dir structure to populate an app bundle.

func PrepareExecutables

func PrepareExecutables(projDir string, dstDir string) error

PrepareExecutables finds directories under the `cmd` dir and tries to compile each of those packages, placing the output binary under the app directory.

func UpdateMigrations

func UpdateMigrations(dstDir string, scanDirs []string, l logs.Logger) error

UpdateMigrations finds the existing migrations in dstDir, and checks their hashes for changes, adding the new migrations as required. UpdateMigrations changes the existing IDs for their timestamps, so migration can be executed in order.

func UpdateMigrationsFromConfig

func UpdateMigrationsFromConfig(v *viper.Viper, l logs.Logger, confPrefix string) error

UpdateMigrationsFromConfig reads the configuration values that are set to know the directory from where to collect migrations, and the directory to put the newly found migrations, to call the UpdateMigrations function that performs the actual collection.

Types

type MigrationFile

type MigrationFile struct {
	Idx          int64  // the index inside the directory
	Base         string // the base name of the migration
	Suffix       string // .up.sql or .down.sql
	FullPathFile string // the path + filename file
	Hash         string // hash of the content

}

MigrationFile contains info to match existing migration files with those coming from the sources

func ParseMigrationFile

func ParseMigrationFile(path string, name string) (*MigrationFile, error)

ParseMigrationFile extracts the components of a migrations file pair

type MigrationFiles

type MigrationFiles map[string]MigrationPair

MigrationFiles is a map of the base name (without the prefix Id, nor the 'up.sql' / 'down.sql' extentions) to the pair of files that compose a migration

func CollectMigrations

func CollectMigrations(scanDir string, l logs.Logger) (MigrationFiles, []error)

CollectMigrations scans a directory and all its descendants looking for directories called `migrations`.

func ListExistingMigrations

func ListExistingMigrations(dstDir string, l logs.Logger) (MigrationFiles, []error)

ListExistingMigrations computes the hash for the 'up' and 'down' migration files.

type MigrationPair

type MigrationPair struct {
	Up   MigrationFile
	Down MigrationFile
}

MigrationPair contains information for a pair of 'up' and 'down' migrations.

Jump to

Keyboard shortcuts

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