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

Add default env for script run #5002

Merged
merged 8 commits into from
Jul 1, 2024
Merged

Add default env for script run #5002

merged 8 commits into from
Jul 1, 2024

Conversation

ffjlabo
Copy link
Member

@ffjlabo ffjlabo commented Jun 28, 2024

What this PR does / why we need it:

Added default env value for the deployment information (such as deployment id, application id...)

Current values are below.

Name Description Example
SR_DEPLOYMENT_ID The deployment id 877625fc-196a-40f9-b6a9-99decd5494a0
SR_APPLICATION_ID The application id 8d7609e0-9ff6-4dc7-a5ac-39660768606a
SR_APPLICATION_NAME The application name example
SR_TRIGGERED_AT The timestamp when the deployment is triggered 1719571113
SR_TRIGGERED_COMMIT_HASH The commit hash that triggered the deployment 2bf969a3dad043aaf8ae6419943255e49377da0d
SR_REPOSITORY_URL The repository url configured in the piped config git@github.com:org/repo.git, https://github.com/org/repo
SR_SUMMARY The summary of the deployment Sync with the specified pipeline because piped received a command from user via web console or pipectl
SR_CONTEXT_RAW The json encoded string of above values {"deploymentID":"877625fc-196a-40f9-b6a9-99decd5494a0","applicationID":"8d7609e0-9ff6-4dc7-a5ac-39660768606a","applicationName":"example","triggeredAt":1719571113,"triggeredCommitHash":"2bf969a3dad043aaf8ae6419943255e49377da0d","repositoryURL":"git@github.com:org/repo.git","labels":{"env":"example","team":"product"}}
SR_LABEL_XXX The label attached to the deployment. The env name depends on the label name. For example, if a deployment has the labels env:prd and team:server, SR_LABEL_ENV and SR_LABEL_TEAM are registered. prd, server
PipeCD

example of app.pipecd.yaml

apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
  name: script-run-like-jenkins
  labels:
    env: example
    team: product
  pipeline:
    stages:
      - name: K8S_CANARY_ROLLOUT
        with:
          replicas: 10%
      - name: SCRIPT_RUN
        with:
          run: |
            echo $SR_DEPLOYMENT_ID
            echo $SR_APPLICATION_ID
            echo $SR_APPLICATION_NAME
            echo $SR_TRIGGERED_AT
            echo $SR_TRIGGERED_COMMIT_HASH
            echo $SR_REPOSITORY_URL
            echo $SR_RAW
            echo $
          env:
            REPOSITORY_URL: "https://github.com/pipecd/pipecd"
          onRollback: |
            echo $SR_DEPLOYMENT_ID
            echo $SR_APPLICATION_ID
            echo $SR_APPLICATION_NAME
            echo $SR_TRIGGERED_AT
            echo $SR_TRIGGERED_COMMIT_HASH
            echo $SR_REPOSITORY_URL
            echo $SR_RAW
...

Which issue(s) this PR fixes:

Fixes #4814

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

ffjlabo added 2 commits June 28, 2024 14:07
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 34.61538% with 34 lines in your changes missing coverage. Please review.

Project coverage is 22.28%. Comparing base (ce9bc16) to head (980378d).
Report is 1 commits behind head on master.

Files Patch % Lines
pkg/app/piped/executor/scriptrun/scriptrun.go 42.85% 23 Missing and 1 partial ⚠️
pkg/app/piped/executor/kubernetes/rollback.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5002      +/-   ##
==========================================
+ Coverage   22.25%   22.28%   +0.02%     
==========================================
  Files         519      519              
  Lines       57234    57284      +50     
==========================================
+ Hits        12739    12766      +27     
- Misses      43468    43492      +24     
+ Partials     1027     1026       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ffjlabo added 2 commits June 28, 2024 20:19
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
@ffjlabo ffjlabo marked this pull request as ready for review June 28, 2024 11:57
"SR_TRIGGERED_AT": strconv.FormatInt(src.TriggeredAt, 10),
"SR_TRIGGERED_COMMIT_HASH": src.TriggeredCommitHash,
"SR_REPOSITORY_URL": src.RepositoryURL,
"SR_RAW": string(b), // Add the raw json string as an environment variable.
Copy link
Member

Choose a reason for hiding this comment

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

how about renaming it to SR_CONTEXT_RAW

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, cheged at a9aac93

ffjlabo added 2 commits July 1, 2024 10:25
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
@ffjlabo ffjlabo requested a review from khanhtc1202 July 1, 2024 01:26
Warashi
Warashi previously approved these changes Jul 1, 2024
Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

LGTM

@ffjlabo
Copy link
Member Author

ffjlabo commented Jul 1, 2024

oops, I forgot to add the Summary value. will try to add it 🙏
#4814 (comment)

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
@ffjlabo
Copy link
Member Author

ffjlabo commented Jul 1, 2024

Added Summary value on 701bffa
PipeCD

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

I checked with this PR and the Deployment model.

LGTM

@ffjlabo ffjlabo enabled auto-merge (squash) July 1, 2024 02:16
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Here you go 🚀

@ffjlabo ffjlabo merged commit f20a270 into master Jul 1, 2024
16 of 18 checks passed
@ffjlabo ffjlabo deleted the script-run-context branch July 1, 2024 02:39
@github-actions github-actions bot mentioned this pull request Jul 4, 2024
khanhtc1202 pushed a commit that referenced this pull request Jul 12, 2024
* Add default env for script run

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add default env for script run rollback

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Make ContextInfo to use deployment info for script run stage

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add docs

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Change env name

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add test

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Add Summary value

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

* Set omitempty

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>

---------

Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use current deployment context in SCRIPT_RUN stage
3 participants