Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): support deployment parameters in templates #665

Merged
merged 11 commits into from
Aug 15, 2022

Conversation

jbrockopp
Copy link
Contributor

@jbrockopp jbrockopp commented Jun 23, 2022

closes go-vela/community#568

Related to go-vela/docs#306

This change updates the golangci-lint configuration to ignore the wsl linter for *_test.go files.

This change also adds support for referencing DEPLOYMENT_PARAMETER_* variables in a template.

In a Go template, you'll be able to reference these parameters using the existing vela platform function:

  • {{ vela "DEPLOYMENT_PARAMETER_<NAME>" }}

In a Starlark template, you'll be able to reference these parameters using the existing vela platform function:

  • ctx["vela"]["deployment"]["<name>"]

This was tested utilizing the following deployment command:

$ vela add deployment --org <org> --repo <repo> --parameter 'foobar=3.14'

And using the following root Vela pipeline:

version: "1"

templates:
  - name: go
    source: git.example.com/<org>/<repo>/template/test.yml
    format: go
    type: github

  - name: starlark
    source: git.example.com/<org>/<repo>/template/test.star
    format: starlark
    type: github

steps:
  - name: go
    template:
      name: go

  - name: starlark
    template:
      name: starlark

The test.yml file had the following content:

metadata:
  template: true

steps:
  - name: hello
    image: alpine:latest
    commands:
      - echo hello

  - name: deployment
    image: alpine:latest
    ruleset:
      event: deployment
    commands:
      - echo $DEPLOYMENT_PARAMETER_FOOBAR
      - echo {{ vela "DEPLOYMENT_PARAMETER_FOOBAR" }}

The test.star file had the following content:

def main(ctx):
  return {
    'version': '1',
    'steps': [
      {
        'name': 'hello',
        'image': 'alpine:latest',
        'commands': [
          'echo hello',
        ]
      },
      {
        'name': 'deployment',
        'image': 'alpine:latest',
        'ruleset': {
          'event': ['deployment'],
        },
        'commands': [
          'echo $DEPLOYMENT_PARAMETER_FOOBAR',
          "echo %s" % ctx["vela"]["deployment"]["foobar"],
        ]
      },
    ],
  }

@jbrockopp jbrockopp self-assigned this Jun 23, 2022
@codecov
Copy link

codecov bot commented Jun 23, 2022

Codecov Report

Merging #665 (a3f4495) into master (a08413f) will increase coverage by 0.05%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #665      +/-   ##
==========================================
+ Coverage   55.14%   55.20%   +0.05%     
==========================================
  Files         201      201              
  Lines       15882    15916      +34     
==========================================
+ Hits         8758     8786      +28     
- Misses       6748     6752       +4     
- Partials      376      378       +2     
Impacted Files Coverage Δ
compiler/template/starlark/convert.go 54.65% <57.14%> (+3.18%) ⬆️
compiler/template/native/convert.go 90.69% <100.00%> (+5.51%) ⬆️

@jbrockopp jbrockopp added the feature Indicates a new feature label Jun 28, 2022
@jbrockopp jbrockopp marked this pull request as ready for review June 28, 2022 13:57
@jbrockopp jbrockopp requested a review from a team as a code owner June 28, 2022 13:57
kneal
kneal previously approved these changes Jun 28, 2022
Copy link
Contributor

@kneal kneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐬

@plyr4 plyr4 merged commit 048364c into master Aug 15, 2022
@plyr4 plyr4 deleted the feature/compiler/templates/deploy_params branch August 15, 2022 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for deployment parameters in templates
5 participants