github.com/mweagle/Sparta@v1.15.0/docs_source/content/reference/decorators/_index.md (about)

     1  ---
     2  date: 2018-12-01 06:18:10
     3  title:
     4  pre: "<b>Build-Time Decorators</b>"
     5  chapter: false
     6  weight: 120
     7  ---
     8  
     9  # Build-Time Decorators
    10  
    11  Sparta uses build-time [decorators](https://godoc.org/github.com/mweagle/Sparta/decorator) to annotate the CloudFormation template with
    12  additional functionality.
    13  
    14  While Sparta tries to provide workflows common across service lifecycles, it may be the case that an application requires additional functionality or runtime resources.
    15  
    16  To support this, Sparta allows you to customize the build pipeline via [WorkflowHooks](https://godoc.org/github.com/mweagle/Sparta#WorkflowHooks) structure.  These hooks are called at specific points in the _provision_ lifecycle and support augmenting the standard pipeline:
    17  
    18  {{< spartaflow >}}
    19  
    20  The following sections describe the types of WorkflowHooks available.  All hooks accept a `context map[string]interface{}` as their first parameter.  Sparta treats this as an opaque property bag that enables hooks to communicate state.
    21  
    22  ## WorkflowHook Types
    23  
    24  ### Builder Hooks
    25  
    26  BuilderHooks share the [WorkflowHook](https://godoc.org/github.com/mweagle/Sparta#WorkflowHook) signature:
    27  
    28  ```go
    29  type WorkflowHook func(context map[string]interface{},
    30    serviceName string,
    31    S3Bucket string,
    32    buildID string,
    33    awsSession *session.Session,
    34    noop bool,
    35    logger *logrus.Logger) error
    36  ```
    37  
    38  These functions include:
    39  
    40  - PreBuild
    41  - PostBuild
    42  - PreMarshall
    43  - PostMarshall
    44  
    45  ### Archive Hook
    46  
    47  The `ArchiveHook` allows a service to add custom resources to the ZIP archive and have the signature:
    48  
    49  ```go
    50  type ArchiveHook func(context map[string]interface{},
    51    serviceName string,
    52    zipWriter *zip.Writer,
    53    awsSession *session.Session,
    54    noop bool,
    55    logger *logrus.Logger) error
    56  ```
    57  
    58  This function is called _after_ Sparta has written the standard resources to the `*zip.Writer` stream.
    59  
    60  ### Rollback Hook
    61  
    62  The `RollbackHook` is called *iff* the _provision_ operation fails and has the signature:
    63  
    64  ```go
    65  
    66  type RollbackHook func(context map[string]interface{},
    67    serviceName string,
    68    awsSession *session.Session,
    69    noop bool,
    70    logger *logrus.Logger)
    71  ```
    72  
    73  ## Using WorkflowHooks
    74  
    75  To use the Workflow Hooks feature, initialize a [WorkflowHooks](https://godoc.org/github.com/mweagle/Sparta#WorkflowHooks) structure with 1 or more hook functions and call [sparta.MainEx](https://godoc.org/github.com/mweagle/Sparta#MainEx).
    76  
    77  ## Available Decorators
    78  
    79  {{% children description="true"   %}}
    80  
    81  ### Notes
    82  
    83  - Workflow hooks can be used to support [Dockerizing](https://github.com/mweagle/SpartaDocker) your application
    84  - You may need to add [custom CLI commands](/reference/application/custom_commands) to fully support Docker
    85  - Enable `--level debug` for detailed workflow hook debugging information