1
1
import { Command } from 'commander' ;
2
- import { bake } from './utils/docker.mjs' ;
2
+ import { logger } from '../lib/logger' ;
3
+ import { parsePositiveInt , parseVersion } from './utils' ;
4
+ import { bake } from './utils/docker' ;
3
5
4
6
const program = new Command ( 'pnpm build:docker' ) ;
5
7
6
- /**
7
- *
8
- * @param {string | undefined } val
9
- */
10
- function parseInt ( val ) {
11
- if ( ! val ) {
12
- return 0 ;
13
- }
14
- const r = Number . parseInt ( val , 10 ) ;
15
- if ( ! Number . isFinite ( r ) || r < 0 ) {
16
- throw new Error ( `Invalid number: ${ val } ` ) ;
17
- }
18
-
19
- return r ;
20
- }
21
-
22
- /**
23
- *
24
- * @param {string | undefined } val
25
- */
26
- function parseVersion ( val ) {
27
- if ( ! val ) {
28
- return val ;
29
- }
30
-
31
- if ( ! / ^ \d + \. \d + \. \d + (?: - .+ ) ? $ / . test ( val ) ) {
32
- throw new Error ( `Invalid version: ${ val } ` ) ;
33
- }
34
-
35
- return val ;
36
- }
37
-
38
8
program
39
9
. command ( 'build' )
40
10
. description ( 'Build docker images' )
41
11
. option ( '--platform <type>' , 'docker platforms to build' )
42
12
. option ( '--version <version>' , 'version to use as tag' , parseVersion )
43
- . option ( '--tries <tries>' , 'number of tries on failure' , parseInt )
13
+ . option ( '--tries <tries>' , 'number of tries on failure' , parsePositiveInt )
14
+ . option (
15
+ '--delay <delay>' ,
16
+ 'delay between tries for docker build (eg. 5s, 10m, 1h)' ,
17
+ '30s' ,
18
+ )
44
19
. action ( async ( opts ) => {
45
- console . log ( 'Building docker images ...' ) ;
20
+ logger . info ( 'Building docker images ...' ) ;
46
21
await bake ( 'build' , opts , opts . tries - 1 ) ;
47
22
} ) ;
48
23
@@ -52,7 +27,7 @@ program
52
27
. option ( '--platform <type>' , 'docker platforms to build' )
53
28
. option ( '--version <version>' , 'version to use as tag' , parseVersion )
54
29
. action ( async ( opts ) => {
55
- console . log ( 'Publishing docker images ...' ) ;
30
+ logger . info ( 'Publishing docker images ...' ) ;
56
31
await bake ( 'push' , opts ) ;
57
32
} ) ;
58
33
0 commit comments