Skip to content

Commit

Permalink
Better Shipit TASK_ID integration (deployment_id)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Feb 27, 2019
1 parent d28b284 commit 7815b2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## next

*Enhancements*
- Uses `TASK_ID` environment variable as the `deployment_id` when rendering resource templates for better Shipit integration.

*Bug fixes*
- Attempting to deploy from a directory that only contains `secrets.ejson` will no longer fail deploy ([#416](https://github.com/Shopify/kubernetes-deploy/pull/416))

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ offical compatibility chart below.

- `$REVISION` **(required)**: the SHA of the commit you are deploying. Will be exposed to your ERB templates as `current_sha`.
- `$KUBECONFIG` **(required)**: points to one or multiple valid kubeconfig files that include the context you want to deploy to. File names are separated by colon for Linux and Mac, and semi-colon for Windows.
- `$TASK_ID`: used as the ID of the deployment for resource naming.
- `$ENVIRONMENT`: used to set the deploy directory to `config/deploy/$ENVIRONMENT`. You can use the `--template-dir=DIR` option instead if you prefer (**one or the other is required**).
- `$GOOGLE_APPLICATION_CREDENTIALS`: points to the credentials for an authenticated service account (required if your kubeconfig `user`'s auth provider is GCP)

Expand All @@ -130,7 +131,7 @@ Each app's templates are expected to be stored in a single directory. If this is
All templates must be YAML formatted. You can also use ERB. The following local variables will be available to your ERB templates by default:

* `current_sha`: The value of `$REVISION`
* `deployment_id`: A randomly generated identifier for the deploy. Useful for creating unique names for task-runner pods (e.g. a pod that runs rails migrations at the beginning of deploys).
* `deployment_id`: The value of `$TASK_ID`, or in its absence, a randomly generated identifier for the deploy. Useful for creating unique names for task-runner pods (e.g. a pod that runs rails migrations at the beginning of deploys).

You can add additional variables using the `--bindings=BINDINGS` option which can be formated as comma separated string, JSON string or path to a JSON or YAML file. Complex JSON or YAML data will be converted to a Hash for use in templates. To load a file the argument should include the relative file path prefixed with an `@` sign. An argument error will be raised if the string argument cannot be parsed, the referenced file does not include a valid extension (`.json`, `.yaml` or `.yml`) or the referenced file does not exist.

Expand Down
6 changes: 5 additions & 1 deletion lib/kubernetes-deploy/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def initialize(current_sha:, template_dir:, logger:, bindings: {})
@logger = logger
@bindings = bindings
# Max length of podname is only 63chars so try to save some room by truncating sha to 8 chars
@id = current_sha[0...8] + "-#{SecureRandom.hex(4)}" if current_sha
@id = if ENV["TASK_ID"]
ENV["TASK_ID"]
elsif current_sha
current_sha[0...8] + "-#{SecureRandom.hex(4)}"
end
end

def render_template(filename, raw_template)
Expand Down

0 comments on commit 7815b2e

Please sign in to comment.