Skip to content

Commit 3d0ef0f

Browse files
Cr 16568 lib r (#504)
1 parent 6d43237 commit 3d0ef0f

File tree

30 files changed

+9696
-0
lines changed

30 files changed

+9696
-0
lines changed

workflows/codefresh-csdp/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
3+
## v1.1.8 (28.02.2023)
4+
* Using @codefresh-io/cf-report-image-toolbox library
25

36
## v1.1.7 (16.01.2023)
47
### report-image-info
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.8/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.8/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.8/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.8/rbac.yaml)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
* CF_API_KEY (required) - The Kubernetes secret containing the Codefresh API key created by **runtime**
14+
* CF_API_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret that has the Codefresh API key created by **runtime**. Default is 'token'
15+
* CF_HOST_URL (optional) - The URL to reach Codefresh (support on-premises Codefresh). Default is 'https://g.codefresh.io'
16+
* GITHUB_API_HOST_URL (optional) - The URL to reach the GitHub API (support on-premises GitHub api). Default is 'https://api.github.com'
17+
* GITHUB_API_PATH_PREFIX (optional) - The API prefix path for GitHub (support on-premises GitHub path prefix).
18+
* GITHUB_TOKEN_SECRET_NAME (optional) - The Kubernetes secret containing the GitHub token
19+
* GITHUB_TOKEN_SECRET_KEY (optional) - The key in the Kubernetes secret containing the GitHub token. Default is 'token'
20+
* GITHUB_CONTEXT (optional) - The name of the github context from classic codefresh platform
21+
* GITLAB_HOST_URL (optional) - The URL to reach the GitLab API (support on-premises GitLab api). Default is 'https://gitlab.com'
22+
* GITLAB_TOKEN_SECRET_NAME (optional) - The Kubernetes secret containing the GitLab token
23+
* GITLAB_TOKEN_SECRET_KEY (optional) - The key in the Kubernetes secret containing the GitLab token. Default is 'token'
24+
* BITBUCKET_HOST_URL (optional) - The URL to reach the BitBucket API (support on-premises BitBucket api). Default is 'https://api.bitbucket.org/2.0'
25+
* BITBUCKET_SECRET_NAME (optional) - The Kubernetes secret containing the BitBucket credentials
26+
* BITBUCKET_USERNAME_SECRET_KEY (optional) - The key in the Kubernetes secret containing the BitBucket username. Default is 'username'
27+
* BITBUCKET_PASSWORD_SECRET_KEY (optional) - The key in the Kubernetes secret containing the BitBucket password. Default is 'password'
28+
29+
### Outputs
30+
* `exit-error` – message of the error that caused template failure
31+
32+
## Examples
33+
34+
### task Example
35+
```
36+
apiVersion: argoproj.io/v1alpha1
37+
kind: Workflow
38+
metadata:
39+
generateName: image-enricher-git-info-
40+
spec:
41+
entrypoint: main
42+
templates:
43+
- name: main
44+
dag:
45+
tasks:
46+
- name: image-enricher-git-info
47+
templateRef:
48+
name: argo-hub.codefresh-csdp.1.1.8
49+
template: image-enricher-git-info
50+
arguments:
51+
parameters:
52+
- name: CF_API_KEY
53+
value: 'codefresh-token'
54+
- name: CF_API_KEY_SECRET_KEY
55+
value: 'token'
56+
- name: IMAGE_NAME
57+
value: 'gcr.io/codefresh/cfstep-helm:lastest'
58+
- name: GIT_PROVIDER
59+
value: 'github'
60+
- name: REPO
61+
value: 'codefresh/cfstep-helm'
62+
- name: BRANCH
63+
value: 'main'
64+
- name: GITHUB_TOKEN_SECRET_NAME
65+
value: 'github-creds'
66+
- name: GITHUB_TOKEN_SECRET_KEY
67+
value: 'token'
68+
```
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: 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.8
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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
* AWS_ACCESS_KEY (required) - The Kubernetes secret with the Amazon access key
24+
* AWS_ACCESS_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon access key. Default is 'aws-access-key'
25+
* AWS_SECRET_KEY (required) - The Kubernetes secret with the Amazon secret key
26+
* AWS_SECRET_KEY_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon secret key. Default is 'aws-secret-key'
27+
* AWS_REGION (required) - The Kubernetes secret with the Amazon region
28+
* AWS_REGION_SECRET_KEY (optional) - The key in the Kubernetes secret with the Amazon region. Default is 'aws-region'
29+
* DOCKER_CONFIG_FILE_PATH (required) - docker config json for authenticating to a registry (GCR, ECR, ACR not supported)
30+
* DOCKER_CONFIG_SECRET (required) - The Kubernetes secret containing the docker config json information. Default is 'docker-registry'
31+
* DOCKER_CONFIG_SECRET_KEY (optional) - The key in the Kubernetes secret containing the docker config json information. Default is '.dockerconfigjson'
32+
* DOCKERHUB_USERNAME (required) - The Kubernetes secret with the docker username
33+
* DOCKERHUB_USERNAME_SECRET_KEY (optional) The key in the Kubernetes secret with the docker username. Default is 'username'
34+
* DOCKERHUB_PASSWORD (required) - The Kubernetes secret with the docker password
35+
* DOCKERHUB_PASSWORD_SECRET_KEY (optional) The key in the Kubernetes secret with the docker password. Default is 'password'
36+
* REGISTRY_USERNAME (required) - The Kubernetes secret with the standard registry username
37+
* USERNAME_SECRET_KEY (optional) The key in the Kubernetes secret with the standard registry username. Default is 'username'
38+
* REGISTRY_PASSWORD (required) - The Kubernetes secret with the standard registry password
39+
* PASSWORD_SECRET_KEY (optional) The key in the Kubernetes secret with the standard registry password. Default is 'password'
40+
* REGISTRY_DOMAIN (required) - The Kubernetes secret with the standard registry domain
41+
* REGISTRY_DOMAIN_SECRET_KEY (optional) - The key in the Kubernetes secret with the standard registry domain. Default is 'domain'
42+
* AWS_ROLE_SECRET (required) - The Kubernetes secret with the Amazon role
43+
* AWS_ROLE_SECRET_KEY (optional) -The key in the Kubernetes secret with the standard Amazon role. Default is 'role'
44+
45+
### Outputs
46+
* `image-name` – name of the reported image
47+
* `image-sha` – SHA of the reported image
48+
* `image-link` – link to the image in codefresh
49+
* `exit-error` – message of the error that caused template failure
50+
51+
## Examples
52+
53+
### task Example
54+
```
55+
apiVersion: argoproj.io/v1alpha1
56+
kind: Workflow
57+
metadata:
58+
generateName: report-image-info-
59+
spec:
60+
entrypoint: main
61+
templates:
62+
- name: main
63+
dag:
64+
tasks:
65+
- name: report-image-info
66+
templateRef:
67+
name: argo-hub.codefresh-csdp.1.1.8
68+
template: report-image-info
69+
arguments:
70+
parameters:
71+
- name: CF_API_KEY
72+
value: 'codefresh-token'
73+
- name: CF_API_KEY_SECRET_KEY
74+
value: 'token'
75+
- name: IMAGE_NAME
76+
value: 'deniscodefresh/ppid-inspector:latest'
77+
- name: DOCKERHUB_USERNAME
78+
value: 'dockerhub-creds'
79+
- name: USERNAME_SECRET_KEY
80+
value: 'username'
81+
- name: DOCKERHUB_PASSWORD
82+
value: 'dockerhub-creds'
83+
- name: PASSWORD_SECRET_KEY
84+
value: 'password'
85+
```
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.0",
13+
"joi": "^17.6.0",
14+
"lodash": "^4.17.21"
15+
}
16+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
24+
// github
25+
githubApiHost: process.env.GITHUB_API_HOST_URL?.trim() || 'https://api.github.com',
26+
githubToken: process.env.GITHUB_TOKEN?.trim(),
27+
githubApiPathPrefix: process.env.GITHUB_API_PATH_PREFIX?.trim() || '/',
28+
githubContextName: process.env.GITHUB_CONTEXT?.trim(),
29+
30+
// gitlab
31+
gitlabHost: process.env.GITLAB_HOST_URL?.trim() || 'https://gitlab.com',
32+
gitlabToken: process.env.GITLAB_TOKEN?.trim(),
33+
34+
// bitbucket
35+
bitbucketHost: process.env.BITBUCKET_HOST_URL?.trim() || 'https://api.bitbucket.org/2.0',
36+
bitbucketUsername: process.env.BITBUCKET_USERNAME?.trim(),
37+
bitbucketPassword: process.env.BITBUCKET_PASSWORD?.trim(),
38+
39+
commitsByUserLimit: Number(process.env.CF_COMMITS_BY_USER_LIMIT?.trim()) || 5,
40+
};
41+
42+
const schema = Joi.object({
43+
GIT_PROVIDER: Joi.string().valid(...Object.values(providers)).required(),
44+
CF_HOST_URL: Joi.string().uri().empty(''),
45+
CF_API_KEY: Joi.string().required(),
46+
IMAGE_NAME: Joi.string().required(),
47+
REPO: Joi.string().required(),
48+
BRANCH: Joi.string().required(),
49+
50+
// others
51+
CF_COMMITS_BY_USER_LIMIT: Joi.number(),
52+
})
53+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.GITHUB) }).unknown(), {
54+
then: Joi.object({
55+
GITHUB_API_HOST_URL: Joi.string().uri().empty(''),
56+
GITHUB_TOKEN: Joi.string().empty(''),
57+
GITHUB_API_PATH_PREFIX: Joi.string().uri({ relativeOnly: true }).empty(''),
58+
GITHUB_CONTEXT: Joi.string().empty(''),
59+
}).xor('GITHUB_CONTEXT', 'GITHUB_TOKEN')
60+
})
61+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.GITLAB) }).unknown(), {
62+
then: Joi.object({
63+
GITLAB_HOST_URL: Joi.string().uri().empty(''),
64+
GITLAB_TOKEN: Joi.string().required()
65+
})
66+
})
67+
.when(Joi.object({ GIT_PROVIDER: Joi.valid(providers.BITBUCKET_SERVER, providers.BITBUCKET) }).unknown(), {
68+
then: Joi.object({
69+
BITBUCKET_HOST_URL: Joi.string().uri().empty(''),
70+
BITBUCKET_USERNAME: Joi.string().required(),
71+
BITBUCKET_PASSWORD: Joi.string().required()
72+
})
73+
});
74+
75+
module.exports = {
76+
inputs,
77+
78+
providers,
79+
80+
validateInputs() {
81+
const { error } = schema.validate(process.env, { allowUnknown: true });
82+
return [ error, this.inputs ];
83+
}
84+
}

0 commit comments

Comments
 (0)