Note: Stencil module hooks are documented in the module docs.
stencil-golang exposes a few module hooks to allow for integration with other modules. These docs will go over them at a highlevel, but note this is not and exhaustive list of hooks or how to use them. For more information it's suggested to look at the hooks in context of the file you're trying to modify.
Type: { name string, version string }
File: _helpers.tpl
Add a dependency to this service. This dependency will be ignored by dependency management tools like dependabot
in favor of the dependency specified in go_modules
.
{{- define "deps" -}}
- name: a-module
version: 1.0.0
{{- end -}}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "go_modules" (stencil.ApplyTemplate "deps" | fromYaml) }}
Type: { name string, version string }
File: _helpers.tpl
Equivalent go_modules
but for JavaScript (node).
Type: { name string, version string }
File: _helpers.tpl
Equivalent go_modules
but for JavaScript (node), dev dependencies.
Type: []string
File: deployments/appname/app.jsonnet.tpl
Adds Vault secret paths to be pulled within the deployment manifests and created in Kubernetes.
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "vaultSecrets" (list "path/to/secret") }}
Type: map[string]interface{}
File: .vscode/private.env.tpl
Environment variables to write out to private.env
for VSCode to use while running tests.
{
{
stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" (list (dict "MY_ENV_VAR" "my-value")),
},
}
Type: string
File: api/api.go.tpl
Extra interface methods to add to the Service
interface.
{{ $myInterface := "MyServiceMethod(ctx context.Context) error" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "api.Service" (list $myInterface) }}
Type: string
File: api/api.proto.tpl
Extra message types to add to the api.proto
file.
Note: New lines are supported.
{{ $myMessage := "message MyMessage { string my_field = 1; }" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "api.proto.message" (list $myMessage) }}
Type: string
File: api/api.proto.tpl
Extra service rpcs to add to the api.proto
file.
{{ $myService := "rpc MyMethod (MyMessage) returns (MyMessage) {}" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "api.proto.service" (list $myService) }}
Type: map[string]interface{}
File: main.go.tpl
Additional dependencies to add to the main.go
file.
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "main.dependencies"
(list
(dict "count" "int")
)
}}
Type: string
File: internal/appName/http/handler.go.tpl
Insert to different parts for extension of handler.go
http/extraComments
add extra comment in top of the filehttp/extraStandardImports
add extra standard importshttp/additionalImports
add extra other importshttp/extraRoutes
add extra handlers for routinghttp/extraFuncs
add extra functions for routing's usages
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "http/xxxx"
(stencil.applyTemplate "<template-name>")
}}
Type: string
File: internal/appName/rpc/rpc.go.tpl
Insert to different parts for extension of rpc.go
internal/rpc/extraComments
add extra comment in top of the fileinternal/rpc/extraStandardImports
add extra standard importsinternal/rpc/additionalImports
add extra non-standard importsinternal/rpc/grpcServerOptionInit
add extra init statements by modulesinternal/rpc/grpcServerOptions
add extra options by modulesinternal/rpc/additionalGRPCRPCS
add extra gRPC RPCs injected by modulesinternal/rpc/additionalDefaultHandlers
add extra functions
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "internal/rpc/xxxx"
(stencil.applyTemplate "<template-name>")
}}
Type: string
File: deployments/appname/app.jsonnet.tpl
Extra mixin files in deployments/appname/mixins
to include in the jsonnet deployments.
# deployments/appname/mixins/my-mixin.jsonnet
{{ $myMixin := "my-mixin" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "mixins" (list $myMixin) }}
Type: string
File: deployments/appname/Dockerfile.tpl
Extra commands to run after the build stage in the Dockerfile.
{{ $myCommand := "RUN echo 'hello world'" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "Dockerfile.afterBuild" (list $myCommand) }}
Type: string
File: deployments/appname/app.config.jsonnet.tpl
Extra configuration jsonnet files to merge into the application config.
# deployments/appname/configs/my-config.jsonnet
{{ $myConfig := "my-config" }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "app.config.jsonnet/config" (list $myConfig) }}
Type:
{
name: string,
description: string,
activation:
env: [ key: value ]
vars: [ key: value ]
patches:
[
{
op: string
path: string
value: [ key: value ]
}
]
File: devspace.yaml.tpl
Extra devspace profiles to merge into the devspace.yaml config.
{{- define "ingestTerminalDevspaceProfile" }}
- name: {{ .Config.Name }}-ingest-terminal
description: Allows for running ingest in --with-terminal mode
activation:
- env:
DEVENV_DEV_DEPLOYMENT_PROFILE: deployment__{{ .Config.Name }}-ingest
DEVENV_DEV_TERMINAL: "true"
patches:
- op: replace
path: dev.terminal.labelSelector
value:
app: {{ .Config.Name }}-ingest
{{- end }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "devspace.profiles" (stencil.ApplyTemplate "ingestDevspaceProfile" | fromYaml) }}
Type:
{
name: string,
labelSelector: string,
namespace: string,
localSubPath: string,
containerPath: string,
excludePaths: [ string ]
}
File: devspace.yaml.tpl
Extra devspace sync to merge into a devspace.yaml config.
{{- define "testSync"}}
- name: test
labelSelector: ${DEVENV_DEPLOY_LABELS}
namespace: ${DEVENV_DEPLOY_NAMESPACE}
localSubPath: ./
containerPath: ${DEV_CONTAINER_WORKDIR}
excludePaths:
- bin
- ./vendor
{{- end }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "devspace.profiles" (stencil.ApplyTemplate "testSync" | fromYaml) }}
Type: string
File: devspace.yaml.tpl
Extra ports that should be forwarded while devspace dev
is running
# devspace.ports
{{- stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "devspace.ports" (list "4000") }}
Type: string
File: Makefile
Extra commands to add to the root Makefile
{{- define "run.rover" }}
## run-rover: merges shared and specific schemas and runs rover-cli
.PHONY: run-rover
run-rover:
cat internal/graphql/schema/shared.graphql > internal/graphql/generated/schema.graphql
cat internal/graphql/schema/schema.graphql >> internal/graphql/generated/schema.graphql
rover dev --router-config config/apollo.yaml --name $appName --url http://localhost:4000/graphql --schema internal/graphql/generated/schema.graphql
{{- end }}
{{- stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "Makefile.commands" (list (stencil.ApplyTemplate "run.rover")) }}
Type: string
File: monitoring/slos.tf
Extra SLO teraform definitions.
{{- define "grpc-slo"}}
resource "datadog_service_level_objective" "grpc_p99_latency" {
name = "{{ .Config.Name | title }} GRPC P99 Latency"
type = "monitor"
description = "Keeping track of P99 latency commitments for all {{ .Config.Name | title }} GRPC requests in aggregate, for production bentos only."
tags = local.ddTags
monitor_ids = [module.grpc_latency_high.high_traffic_id]
groups = [
{{- $bentos := extensions.Call "github.com/getoutreach/stencil-discovery.Bentos" (stencil.Arg "deployment.environments") (stencil.Arg "deployment.serviceDomains") }}
{{- range $b := $bentos }}
"kube_namespace:{{ stencil.ApplyTemplate "goPackageSafeName" }}--{{ $b.name }}",
{{- end }}
]
thresholds {
timeframe = "7d"
target = 99.9
warning = 99.95
}
}
{{- end }}
{{- stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "monitoring.slos"
(list (stencil.ApplyTemplate "grpc-slo"))
}}
Type: string
File: .vscode/extensions.json
This hook allows you to add more recommended extensions for the workspace in VSCode. These extensions are suggested when a developer opens the workspace in VSCode.
{{- define "extensions" -}}
"somekittens.hot-dog-stand",
{{- end }}
{{ stencil.AddToModuleHook "github.com/getoutreach/stencil-golang" "vscode/additional-extensions"
(list
(stencil.ApplyTemplate "extensions")
)
}}