Skip to content

Commit 3907ea8

Browse files
committed
added repository option
1 parent 6b795db commit 3907ea8

9 files changed

+162
-7
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
All notable changes to this project will be documented in this file.
55

6+
## Version 0.2.2 - 2024-06-19
7+
8+
### Added
9+
10+
- Added repository option
11+
612
## Version 0.2.1 - 2024-05-16
713

814
### Fixed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Build tool to containerize cloud applications.
2525
-p | --push pushes the images to specified repository
2626
-h | --help get detailed usage information
2727
-v | --version get version of the package
28+
--repository repository to push the images to
2829

2930
EXAMPLES
3031
ctz build.yaml

lib/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ${font.bold} OPTIONS
1414
${font.bold} -p | --push ${font.reset}pushes the images to specified repository
1515
${font.bold} -h | --help ${font.reset}get detailed usage information
1616
${font.bold} -v | --version ${font.reset}get version of the package
17+
${font.bold} --repository ${font.reset}repository to push the images to
1718
1819
${font.bold} EXAMPLES${font.reset}
1920
ctz build.yaml

lib/execute.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const readline = require('readline')
88
const args = process.argv.slice(3);
99
const options = {
1010
push: args.includes('--push') || args.includes('-p'),
11-
log: args.includes('--log') || args.includes('-l')
11+
log: args.includes('--log') || args.includes('-l'),
12+
repository: args.find(arg => arg.startsWith('--repository'))?.split('=')[1] ?? ''
1213
}
1314

1415
function logMessage(message) {
@@ -53,7 +54,7 @@ async function tagAndPush(modules, repository) {
5354

5455
async function processModule(filename) {
5556
try {
56-
const { repository = '', before_all = [], commands: modules = [] } = parse_yaml(filename)
57+
const { repository = '', before_all = [], commands: modules = [] } = parse_yaml(filename, options.repository)
5758
if (!repository || !modules) return
5859

5960
for (const command of before_all) await execCommand(command, '--log')

lib/parse_yaml.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ function processBuildpack(build_parameters, name, tag) {
6262
return [buildCommand]
6363
}
6464

65-
function parse_yaml(filename) {
65+
function parse_yaml(filename, repositoryOption = '') {
6666
try {
6767
const moduleFile = yaml.load(fs.readFileSync(path.join(process.cwd(), filename), 'utf8'))
68-
const { repository, modules, tag: globalTag = 'latest' } = moduleFile
68+
const { repository: repositoryModule, modules, tag: globalTag = 'latest' } = moduleFile
69+
const repository = repositoryOption == '' ? repositoryModule : repositoryOption
6970
const before_all = moduleFile['before-all'] ? moduleFile['before-all'].map(command => command.trim().split(" ")) : []
7071
if (!modules) throw new Error("Modules not defined")
7172

npm-shrinkwrap.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ctz",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Build tool to containerize cloud applications",
55
"homepage": "https://github.com/SAP/ctz",
66
"keywords": [

test/expected/repositoryOption.json

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"commands": [
3+
{
4+
"name": "bookshop-approuter",
5+
"tag": "v1",
6+
"buildCmd": [
7+
[
8+
"pack",
9+
"build",
10+
"bookshop-approuter",
11+
"--path",
12+
"app",
13+
[
14+
"--buildpack",
15+
"gcr.io/paketo-buildpacks/nodejs"
16+
],
17+
"--builder",
18+
"paketobuildpacks/builder-jammy-base",
19+
"--env",
20+
"BP_NODE_RUN_SCRIPTS=\"\""
21+
]
22+
],
23+
"tagCmd": [
24+
"docker",
25+
"tag",
26+
"bookshop-approuter:v1",
27+
"my-repository/bookshop-approuter:v1"
28+
],
29+
"pushCmd": [
30+
"docker",
31+
"push",
32+
"my-repository/bookshop-approuter:v1"
33+
]
34+
},
35+
{
36+
"name": "book-srv",
37+
"tag": "latest",
38+
"buildCmd": [
39+
[
40+
"pack",
41+
"build",
42+
"book-srv",
43+
"--path",
44+
".",
45+
[
46+
"--buildpack",
47+
"gcr.io/paketo-buildpacks/sap-machine"
48+
],
49+
[
50+
"--buildpack",
51+
"gcr.io/paketo-buildpacks/java"
52+
],
53+
"--builder",
54+
"paketobuildpacks/builder-jammy-buildpackless-base",
55+
"--env",
56+
"SPRING_PROFILES_ACTIVE=cloud",
57+
"--env",
58+
"BP_JVM_VERSION=17",
59+
"--env",
60+
"BP_MAVEN_BUILT_ARTIFACT=srv/target/book-exec.jar"
61+
]
62+
],
63+
"tagCmd": [
64+
"docker",
65+
"tag",
66+
"book-srv:latest",
67+
"my-repository/book-srv:latest"
68+
],
69+
"pushCmd": [
70+
"docker",
71+
"push",
72+
"my-repository/book-srv:latest"
73+
]
74+
},
75+
{
76+
"name": "dockerfile-image",
77+
"tag": "latest",
78+
"buildCmd": [
79+
[
80+
"docker",
81+
"build",
82+
"-t",
83+
"dockerfile-image:latest",
84+
"-f",
85+
"dockerfiles/sample.Dockerfile",
86+
"."
87+
]
88+
],
89+
"tagCmd": [
90+
"docker",
91+
"tag",
92+
"dockerfile-image:latest",
93+
"my-repository/dockerfile-image:latest"
94+
],
95+
"pushCmd": [
96+
"docker",
97+
"push",
98+
"my-repository/dockerfile-image:latest"
99+
]
100+
},
101+
{
102+
"name": "bookshop-hana-deployer",
103+
"tag": "latest",
104+
"buildCmd": [
105+
[
106+
"pack",
107+
"build",
108+
"bookshop-hana-deployer",
109+
"--buildpack",
110+
"gcr.io/paketo-buildpacks/nodejs",
111+
"--path",
112+
"db",
113+
"--builder",
114+
"paketobuildpacks/builder-jammy-base"
115+
]
116+
],
117+
"tagCmd": [
118+
"docker",
119+
"tag",
120+
"bookshop-hana-deployer:latest",
121+
"my-repository/bookshop-hana-deployer:latest"
122+
],
123+
"pushCmd": [
124+
"docker",
125+
"push",
126+
"my-repository/bookshop-hana-deployer:latest"
127+
]
128+
}
129+
],
130+
"before_all": [
131+
[
132+
"npx",
133+
"cds",
134+
"build",
135+
"--production"
136+
]
137+
],
138+
"repository": "my-repository"
139+
}

test/parse.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ describe('parse yaml', () => {
1111
})
1212
})
1313

14+
describe('parse yaml with --repository option', () => {
15+
test('test yaml parsing', () => {
16+
expect(parse_yaml("/test/files/build.yaml", 'my-repository')).toEqual(readJSON(__dirname + "/expected/repositoryOption.json"))
17+
})
18+
})
19+
1420
describe('parse yaml without builder', () => {
1521
test('test yaml parsing without builder', () => {
1622
expect(parse_yaml("/test/files/buildWithoutBuilder.yaml")).toEqual(readJSON(__dirname + "/expected/buildWithoutBuilder.json"))

0 commit comments

Comments
 (0)