Skip to content

Commit 44b4264

Browse files
Allow to use regular expressions or multiple project prefixes in JIRA_PROJECT_PREFIX (#511)
* Allow to use regular expressions or multiple project prefixes separated by comma in JIRA_PROJECT_PREFIX * update changelog
1 parent 2368ded commit 44b4264

File tree

30 files changed

+9720
-0
lines changed

30 files changed

+9720
-0
lines changed

workflows/codefresh-csdp/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.1.9 (22.03.2023)
4+
* Allow to use regular expressions or multiple project prefixes separated by comma in JIRA_PROJECT_PREFIX.
5+
36
## v1.1.8 (22.03.2023)
47
* Add GOOGLE_REGISTRY_HOST and GOOGLE_JSON_KEY to report-image-info
58

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CSDP-metadata
2+
3+
## Summary
4+
5+
A set of templates to operate against Codefresh Software Delivery Platform such as reporting image information to the Argo platform, and enriching images with metadata and annotation for GitHub (PRs, commits, etc) and Jira (title, assignee, etc).
6+
7+
## Templates
8+
9+
1. [image-enricher-git-info](https://github.com/codefresh-io/argo-hub/blob/main/workflows/codefresh-csdp/versions/1.1.9/docs/image-enricher-git-info.md)
10+
2. [image-enricher-jira-info](https://github.com/codefresh-io/argo-hub/blob/main/workflows/codefresh-csdp/versions/1.1.9/docs/image-enricher-jira-info.md)
11+
3. [report-image-info](https://github.com/codefresh-io/argo-hub/blob/main/workflows/codefresh-csdp/versions/1.1.9/docs/report-image-info.md)
12+
13+
## Security
14+
15+
Minimal required permissions
16+
17+
[Full rbac permissions list](https://github.com/codefresh-io/argo-hub/blob/main/workflows/codefresh-csp/versions/1.1.9/rbac.yaml)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# image-enricher-git-info
2+
3+
## Summary
4+
Enrich images with metadata and annotation such as PR, commits, committers.
5+
6+
## Inputs/Outputs
7+
8+
### Inputs
9+
* IMAGE_NAME (required) - The image name that was imported into Codefresh to enrich
10+
* GIT_PROVIDER (required) - One of the supported git providers: github, gitlab, bitbucket, bitbucket-server
11+
* BRANCH (required) - The git branch to use to enrich
12+
* REPO (required) - The repo to use to enrich
13+
* REVISION - The commit sha to use to enrich
14+
* CF_API_KEY (required) - The Kubernetes secret containing the Codefresh API key created by **runtime**
15+
* CF_API_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret that has the Codefresh API key created by **runtime**. Default is 'token'
16+
* CF_HOST_URL (optional) - The URL to reach Codefresh (support on-premises Codefresh). Default is 'https://g.codefresh.io'
17+
* GITHUB_API_HOST_URL (optional) - The URL to reach the GitHub API (support on-premises GitHub api). Default is 'https://api.github.com'
18+
* GITHUB_API_PATH_PREFIX (optional) - The API prefix path for GitHub (support on-premises GitHub path prefix).
19+
* GITHUB_TOKEN_SECRET_NAME (optional) - The Kubernetes secret containing the GitHub token
20+
* GITHUB_TOKEN_SECRET_KEY (optional) - The key in the Kubernetes secret containing the GitHub token. Default is 'token'
21+
* GITHUB_CONTEXT (optional) - The name of the github context from classic codefresh platform
22+
* GITLAB_HOST_URL (optional) - The URL to reach the GitLab API (support on-premises GitLab api). Default is 'https://gitlab.com'
23+
* GITLAB_TOKEN_SECRET_NAME (optional) - The Kubernetes secret containing the GitLab token
24+
* GITLAB_TOKEN_SECRET_KEY (optional) - The key in the Kubernetes secret containing the GitLab token. Default is 'token'
25+
* BITBUCKET_HOST_URL (optional) - The URL to reach the BitBucket API (support on-premises BitBucket api). Default is 'https://api.bitbucket.org/2.0'
26+
* BITBUCKET_SECRET_NAME (optional) - The Kubernetes secret containing the BitBucket credentials
27+
* BITBUCKET_USERNAME_SECRET_KEY (optional) - The key in the Kubernetes secret containing the BitBucket username. Default is 'username'
28+
* BITBUCKET_PASSWORD_SECRET_KEY (optional) - The key in the Kubernetes secret containing the BitBucket password. Default is 'password'
29+
30+
### Outputs
31+
* `exit-error` – message of the error that caused template failure
32+
33+
## Examples
34+
35+
### task Example
36+
```
37+
apiVersion: argoproj.io/v1alpha1
38+
kind: Workflow
39+
metadata:
40+
generateName: image-enricher-git-info-
41+
spec:
42+
entrypoint: main
43+
templates:
44+
- name: main
45+
dag:
46+
tasks:
47+
- name: image-enricher-git-info
48+
templateRef:
49+
name: argo-hub.codefresh-csdp.1.1.9
50+
template: image-enricher-git-info
51+
arguments:
52+
parameters:
53+
- name: CF_API_KEY
54+
value: 'codefresh-token'
55+
- name: CF_API_KEY_SECRET_KEY
56+
value: 'token'
57+
- name: IMAGE_NAME
58+
value: 'gcr.io/codefresh/cfstep-helm:lastest'
59+
- name: GIT_PROVIDER
60+
value: 'github'
61+
- name: REPO
62+
value: 'codefresh/cfstep-helm'
63+
- name: BRANCH
64+
value: 'main'
65+
- name: REVISION
66+
value: 'ec8cdced58869a9cbd315a1297a702bbd744a9ed'
67+
- name: GITHUB_TOKEN_SECRET_NAME
68+
value: 'github-creds'
69+
- name: GITHUB_TOKEN_SECRET_KEY
70+
value: 'token'
71+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# image-enricher-jira-info
2+
3+
## Summary
4+
Enrich images with metadata and annotation such as ticket number, title, assignee, status.
5+
6+
## Inputs/Outputs
7+
8+
### Inputs
9+
* IMAGE_NAME (required) - The image URI that was imported into Codefresh to enrich
10+
* JIRA_HOST_URL (required) - jira host url
11+
* JIRA_API_TOKEN_SECRET (required) - Name of Kubernetes secret that contains a jira email and token that you generate in jira
12+
* JIRA_API_TOKEN_SECRET_KEY (required) - The key in the Kubernetes secret with the Jira API token. Default is 'token'
13+
* JIRA_EMAIL_SECRET_KEY (required) - The key in the Kubernetes secret with the Jira Email associated with the API token. Default is 'email'
14+
* JIRA_MESSAGE (required) - message from which you want retrieve issue name, can be a branch, commit message, whatever
15+
* JIRA_PROJECT_PREFIX (required) - jira project prefix like: /[A-Z]{2,}-\d+/g, SAAS, CF, etc.
16+
* CF_API_KEY (required) - The Kubernetes secret containing the Codefresh API key created by **runtime**
17+
* CF_API_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret that has the Codefresh API key created by **runtime**. Default is 'token'
18+
* CF_HOST_URL (optional) - The URL to reach Codefresh (support on-premises Codefresh). Default is 'https://g.codefresh.io'
19+
* JIRA_CONTEXT (optional) - The Jira context to use
20+
* FAIL_ON_NOT_FOUND (optional) - fail in case of ticket not found. Default is 'false'
21+
22+
### Outputs
23+
* `exit-error` – message of the error that caused template failure
24+
25+
## Examples
26+
27+
### task Example
28+
```
29+
apiVersion: argoproj.io/v1alpha1
30+
kind: Workflow
31+
metadata:
32+
generateName: image-enricher-jira-info-
33+
spec:
34+
entrypoint: main
35+
templates:
36+
- name: main
37+
dag:
38+
tasks:
39+
- name: image-enricher-jira-info
40+
templateRef:
41+
name: argo-hub.codefresh-csdp.1.1.9
42+
template: image-enricher-jira-info
43+
arguments:
44+
parameters:
45+
- name: CF_API_KEY
46+
value: 'codefresh-token'
47+
- name: CF_API_KEY_SECRET_KEY
48+
value: 'token'
49+
- name: IMAGE_NAME
50+
value: 'gcr.io/codefresh/cfstep-helm:lastest'
51+
- name: JIRA_PROJECT_PREFIX
52+
value: 'CR'
53+
- name: JIRA_MESSAGE
54+
value: 'working on CR-11027'
55+
- name: JIRA_HOST_URL
56+
value: 'https://jira.atlassian.net'
57+
- name: JIRA_API_TOKEN_SECRET
58+
value: 'jira-creds'
59+
- name: JIRA_API_TOKEN_SECRET_KEY
60+
value: 'token'
61+
- name: JIRA_EMAIL_SECRET_KEY
62+
value: 'email'
63+
```
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# report-image-info
2+
3+
## Summary
4+
Report image info to argo platform.
5+
6+
## Inputs/Outputs
7+
8+
### Inputs
9+
* IMAGE_NAME (required) - your image to which you want to report
10+
* CF_API_KEY (required) - Codefresh API key created by **runtime**
11+
* CF_HOST_URL (optional) - support on-premises Codefresh URL
12+
* WORKFLOW_NAME (optional) - name of the workflow
13+
* WORKFLOW_URL (optional) - external url of the workflow
14+
* LOGS_URL (optional) - external url of the workflow logs
15+
* REGISTRY_INSECURE (optional) - security flag for standard registry protocol, when set to true it enables http protocol.
16+
* RETRIEVE_CREDENTIALS_BY_DOMAIN (optional) - decide about the authentication method based on the image domain
17+
* DOCKERFILE_CONTENT (optional) - base64 encoded content of the Dockerfile used for building image
18+
* DOCKERFILE_PATH (optional) - path to the Dockerfile used for building image (used if DOCKERFILE_CONTENT is empty)
19+
#### Specify one from following required registry parameters:
20+
* GCR_KEY_FILE_PATH (required) - JSON key for authenticating to a Google GCR
21+
* GCR_KEY_SECRET (required) - The Kubernetes secret containing the GCR key information. Default is 'gcr-key-file'
22+
* GCR_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret containing the GCR key information. Default is '.keyjson'
23+
* GOOGLE_REGISTRY_HOST (optional) - The host to Google GCR or Google ACR. Default is 'gcr.io'
24+
* GOOGLE_JSON_KEY (required) - The Kubernetes secret with the JSON key for authenticating to a Google GCR or Google ACR
25+
* GOOGLE_KEY_SECRET_KEY (optional) The key in the Kubernetes secret with Google JSON key. Default is 'keyjson'
26+
* AWS_ACCESS_KEY (required) - The Kubernetes secret with the Amazon access key
27+
* AWS_ACCESS_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon access key. Default is 'aws-access-key'
28+
* AWS_SECRET_KEY (required) - The Kubernetes secret with the Amazon secret key
29+
* AWS_SECRET_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon secret key. Default is 'aws-secret-key'
30+
* AWS_REGION (required) - The Kubernetes secret with the Amazon region
31+
* AWS_REGION_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon region. Default is 'aws-region'
32+
* DOCKER_CONFIG_FILE_PATH (required) - docker config json for authenticating to a registry (GCR, ECR, ACR not supported)
33+
* DOCKER_CONFIG_SECRET (required) - The Kubernetes secret containing the docker config json information. Default is 'docker-registry'
34+
* DOCKER_CONFIG_SECRET_KEY (optional) - The key in the Kubernetes secret containing the docker config json information. Default is '.dockerconfigjson'
35+
* DOCKERHUB_USERNAME (required) - The Kubernetes secret with the docker username
36+
* DOCKERHUB_USERNAME_SECRET_KEY (optional) The key in the Kubernetes secret with the docker username. Default is 'username'
37+
* DOCKERHUB_PASSWORD (required) - The Kubernetes secret with the docker password
38+
* DOCKERHUB_PASSWORD_SECRET_KEY (optional) The key in the Kubernetes secret with the docker password. Default is 'password'
39+
* REGISTRY_USERNAME (required) - The Kubernetes secret with the standard registry username
40+
* USERNAME_SECRET_KEY (optional) The key in the Kubernetes secret with the standard registry username. Default is 'username'
41+
* REGISTRY_PASSWORD (required) - The Kubernetes secret with the standard registry password
42+
* PASSWORD_SECRET_KEY (optional) The key in the Kubernetes secret with the standard registry password. Default is 'password'
43+
* REGISTRY_DOMAIN (required) - The Kubernetes secret with the standard registry domain
44+
* REGISTRY_DOMAIN_SECRET_KEY (optional) - The key in the Kubernetes secret with the standard registry domain. Default is 'domain'
45+
* AWS_ROLE_SECRET (required) - The Kubernetes secret with the Amazon role
46+
* AWS_ROLE_SECRET_KEY (optional) -The key in the Kubernetes secret with the standard Amazon role. Default is 'role'
47+
48+
### Outputs
49+
* `image-name` – name of the reported image
50+
* `image-sha` – SHA of the reported image
51+
* `image-link` – link to the image in codefresh
52+
* `exit-error` – message of the error that caused template failure
53+
54+
## Examples
55+
56+
### task Example
57+
```
58+
apiVersion: argoproj.io/v1alpha1
59+
kind: Workflow
60+
metadata:
61+
generateName: report-image-info-
62+
spec:
63+
entrypoint: main
64+
templates:
65+
- name: main
66+
dag:
67+
tasks:
68+
- name: report-image-info
69+
templateRef:
70+
name: argo-hub.codefresh-csdp.1.1.9
71+
template: report-image-info
72+
arguments:
73+
parameters:
74+
- name: CF_API_KEY
75+
value: 'codefresh-token'
76+
- name: CF_API_KEY_SECRET_KEY
77+
value: 'token'
78+
- name: IMAGE_NAME
79+
value: 'deniscodefresh/ppid-inspector:latest'
80+
- name: DOCKERHUB_USERNAME
81+
value: 'dockerhub-creds'
82+
- name: USERNAME_SECRET_KEY
83+
value: 'username'
84+
- name: DOCKERHUB_PASSWORD
85+
value: 'dockerhub-creds'
86+
- name: PASSWORD_SECRET_KEY
87+
value: 'password'
88+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.12.1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:18.12.1-alpine
2+
3+
WORKDIR /app/
4+
5+
COPY package.json .
6+
COPY yarn.lock .
7+
8+
RUN yarn
9+
10+
COPY . .
11+
12+
CMD [ "node", "/app/src/index.js" ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# image-enricher-git-info
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "image-enricher-git-info",
3+
"version": "0.0.2",
4+
"private": true,
5+
"scripts": {
6+
"start": "node src/index.js"
7+
},
8+
"engines": {
9+
"node": "18.12.1"
10+
},
11+
"dependencies": {
12+
"@codefresh-io/cf-report-image-toolbox": "^1.0.5",
13+
"joi": "^17.6.0",
14+
"lodash": "^4.17.21"
15+
}
16+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const Joi = require('joi')
2+
const _ = require('lodash')
3+
4+
const platform = {
5+
GITOPS: 'GITOPS',
6+
}
7+
8+
const providers = {
9+
GITHUB: 'github',
10+
BITBUCKET: 'bitbucket',
11+
BITBUCKET_SERVER: 'bitbucket-server',
12+
GITLAB: 'gitlab'
13+
}
14+
15+
const inputs = {
16+
platform: platform.GITOPS,
17+
provider: process.env.GIT_PROVIDER?.trim(),
18+
cfHost: process.env.CF_HOST_URL?.trim() || 'https://g.codefresh.io',
19+
cfApiKey: process.env.CF_API_KEY?.trim(),
20+
imageName: process.env.IMAGE_NAME?.trim(),
21+
repo: process.env.REPO?.trim(),
22+
branch: process.env.BRANCH?.trim(),
23+
revision: process.env.REVISION?.trim(),
24+
25+
// github
26+
githubApiHost: process.env.GITHUB_API_HOST_URL?.trim() || 'https://api.github.com',
27+
githubToken: process.env.GITHUB_TOKEN?.trim(),
28+
githubApiPathPrefix: process.env.GITHUB_API_PATH_PREFIX?.trim() || '/',
29+
githubContextName: process.env.GITHUB_CONTEXT?.trim(),
30+
31+
// gitlab
32+
gitlabHost: process.env.GITLAB_HOST_URL?.trim() || 'https://gitlab.com',
33+
gitlabToken: process.env.GITLAB_TOKEN?.trim(),
34+
35+
// bitbucket
36+
bitbucketHost: process.env.BITBUCKET_HOST_URL?.trim() || 'https://api.bitbucket.org/2.0',
37+
bitbucketUsername: process.env.BITBUCKET_USERNAME?.trim(),
38+
bitbucketPassword: process.env.BITBUCKET_PASSWORD?.trim(),
39+
40+
commitsByUserLimit: Number(process.env.CF_COMMITS_BY_USER_LIMIT?.trim()) || 5,
41+
};
42+
43+
const schema = Joi.object({
44+
GIT_PROVIDER: Joi.string().valid(...Object.values(providers)).required(),
45+
CF_HOST_URL: Joi.string().uri().empty(''),
46+
CF_API_KEY: Joi.string().required(),
47+
IMAGE_NAME: Joi.string().required(),
48+
REPO: Joi.string().required(),
49+
BRANCH: Joi.string().required(),
50+
REVISION: Joi.string(),
51+
52+
// others
53+
CF_COMMITS_BY_USER_LIMIT: Joi.number(),
54+
})
55+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.GITHUB) }).unknown(), {
56+
then: Joi.object({
57+
GITHUB_API_HOST_URL: Joi.string().uri().empty(''),
58+
GITHUB_TOKEN: Joi.string().empty(''),
59+
GITHUB_API_PATH_PREFIX: Joi.string().uri({ relativeOnly: true }).empty(''),
60+
GITHUB_CONTEXT: Joi.string().empty(''),
61+
}).xor('GITHUB_CONTEXT', 'GITHUB_TOKEN')
62+
})
63+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.GITLAB) }).unknown(), {
64+
then: Joi.object({
65+
GITLAB_HOST_URL: Joi.string().uri().empty(''),
66+
GITLAB_TOKEN: Joi.string().required()
67+
})
68+
})
69+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.BITBUCKET_SERVER, providers.BITBUCKET) }).unknown(), {
70+
then: Joi.object({
71+
BITBUCKET_HOST_URL: Joi.string().uri().empty(''),
72+
BITBUCKET_USERNAME: Joi.string().required(),
73+
BITBUCKET_PASSWORD: Joi.string().required()
74+
})
75+
});
76+
77+
module.exports = {
78+
inputs,
79+
80+
providers,
81+
82+
validateInputs() {
83+
const { error } = schema.validate(process.env, { allowUnknown: true });
84+
return [ error, this.inputs ];
85+
}
86+
}

0 commit comments

Comments
 (0)