@@ -3,67 +3,91 @@ import { $ } from 'bun';
3
3
const img = 'nozich/bunode'
4
4
5
5
async function main ( ) {
6
- await $ `docker pull ${ img } :latest`
6
+ await $ `docker pull ${ img } :latest`
7
7
8
- const inspect = await $ `docker buildx inspect | grep 'Platforms:' | sed 's/Platforms: //'` . text ( ) ;
8
+ // linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/arm/v7, linux/arm/v6
9
+ const inspect = await $ `docker buildx inspect | grep 'Platforms:' | sed 's/Platforms: //'` . text ( ) ;
9
10
10
- const platforms = inspect . split ( ',' ) . map ( e => e . trim ( ) ) . map ( ( p ) => ( {
11
- platform : p ,
12
- os : p . split ( '/' ) [ 0 ] ,
13
- arch : p . split ( '/' ) [ 1 ] ,
14
- tag : p . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '-' ) . toLowerCase ( )
15
- } ) ) ;
11
+ // Manuelly set the platforms
12
+ const inspects = [ ] ;
13
+ if ( inspect . includes ( 'linux/arm64' ) ) {
14
+ inspects . push ( 'linux/arm64' ) ;
15
+ }
16
+ if ( inspect . includes ( 'linux/amd64' ) ) {
17
+ inspects . push ( 'linux/amd64' ) ;
18
+ }
16
19
17
- console . log ( `platforms ` , platforms . map ( ( p ) => p . tag ) . join ( ',' ) ) ;
20
+ console . log ( `inspects ` , inspects ) ;
18
21
19
- const built = ( await Promise . all ( platforms . map ( async ( { platform, tag } ) => {
20
- const build = await $ `docker buildx build --platform=${ platform } -t ${ img } :${ tag } --push .` . text ( )
21
- . catch ( ( e ) => e ) ;
22
+ const platforms = inspects . split ( ',' ) . map ( e => e . trim ( ) ) . map ( ( p ) => ( {
23
+ platform : p ,
24
+ os : p . split ( '/' ) [ 0 ] ,
25
+ arch : p . split ( '/' ) [ 1 ] ,
26
+ tag : p . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '-' ) . toLowerCase ( )
27
+ } ) ) ;
22
28
23
- console . log ( `[BUILD] [END] [${ platform } ] [${ tag } ] {exitCode: ${ build . exitCode } }` ) ;
29
+ console . log ( `platforms` , JSON . stringify ( platforms ) ) ;
30
+ // console.log(`platforms`, platforms.map((p) => p.tag).join(','));
24
31
25
- return ( build . exitCode === 0 ) && tag
26
- } ) ) ) . filter ( Boolean ) ;
32
+ const built = ( await Promise . all ( platforms . map ( async ( { platform , tag } ) => {
33
+ console . log ( { platform , img , tag } ) ;
27
34
28
- console . log ( `built` , built ) ;
35
+ const build = await $ `docker buildx build --platform=${ platform } -t ${ img } :${ tag } --push .` . text ( )
36
+ . catch ( ( e ) => e ) ;
29
37
30
- if ( built . length === 0 ) {
31
- console . error ( 'No images were built' ) ;
32
- return ;
33
- }
38
+ console . log ( { platform, tag, build } ) ;
34
39
35
- const currents = await fetch ( `https://registry.hub.docker.com/v2/repositories/${ img } /tags/` )
36
- . then ( ( res ) => res . json ( ) )
37
- . then ( ( data ) => data . results
38
- . find ( ( r ) => r . name === 'latest' )
39
- . images . map ( ( i ) => ( {
40
- ...i ,
41
- arch : i . architecture ,
42
- tag : i . variant ? `${ i . os } -${ i . architecture } -${ i . variant } ` : `${ i . os } -${ i . architecture } `
43
- } ) ) ) ;
40
+ console . log ( `[BUILD] [END] [${ platform } ] [${ tag } ] {exitCode: ${ build . exitCode } }` ) ;
44
41
45
- const annotates = currents || [ ]
42
+ return ( build . exitCode === 0 ) && tag
43
+ } ) ) ) . filter ( Boolean ) ;
46
44
47
- const news = platforms . filter ( ( p ) => built . includes ( p . tag ) )
45
+ console . log ( `built` , built ) ;
48
46
49
- news . forEach ( ( p ) => {
50
- if ( annotates . find ( ( a ) => a . tag === p . tag ) ) return ;
51
- annotates . push ( p ) ;
52
- } ) ;
47
+ if ( built . length === 0 ) {
48
+ console . error ( 'No images were built' ) ;
49
+ return ;
50
+ }
53
51
54
- console . log ( `annotates` , annotates . map ( ( { tag, os, arch } ) => ( { tag, os, arch } ) ) ) ;
52
+ const currentsFetch = await fetch ( `https://registry.hub.docker.com/v2/repositories/${ img } /tags/` )
53
+ . then ( ( res ) => res . json ( ) )
54
+ . then ( ( data ) => data . results ) ;
55
55
56
- const tags = annotates . map ( ( { tag } ) => ` ${ img } : ${ tag } ` )
56
+ console . log ( `currentsFetch` , currentsFetch ) ;
57
57
58
- tags . unshift ( `${ img } :latest` )
58
+ const currents = currentsFetch . find ( ( r ) => r . name === 'latest' )
59
+ . images . map ( ( i ) => ( {
60
+ ...i ,
61
+ arch : i . architecture ,
62
+ tag : i . variant ? `${ i . os } -${ i . architecture } -${ i . variant } ` : `${ i . os } -${ i . architecture } `
63
+ } ) ) ;
59
64
60
- await $ `docker manifest create --amend ${ tags } ` ;
65
+ const annotates = currents || [ ] ;
61
66
62
- await Promise . all ( annotates . map ( async ( { os, arch, tag } ) => {
63
- return $ `docker manifest annotate ${ img } :latest ${ img } :${ tag } --os ${ os } --arch ${ arch } ` ;
64
- } ) ) ;
67
+ console . log ( `annotates` , annotates ) ;
65
68
66
- await $ `docker manifest push --purge ${ img } :latest`
69
+ const news = platforms . filter ( ( p ) => built . includes ( p . tag ) ) ;
70
+
71
+ console . log ( `news` , news ) ;
72
+
73
+ news . forEach ( ( p ) => {
74
+ if ( annotates . find ( ( a ) => a . tag === p . tag ) ) return ;
75
+ annotates . push ( p ) ;
76
+ } ) ;
77
+
78
+ console . log ( `annotates` , annotates . map ( ( { tag, os, arch } ) => ( { tag, os, arch } ) ) ) ;
79
+
80
+ const tags = annotates . map ( ( { tag } ) => `${ img } :${ tag } ` )
81
+
82
+ tags . unshift ( `${ img } :latest` )
83
+
84
+ await $ `docker manifest create --amend ${ tags } ` ;
85
+
86
+ await Promise . all ( annotates . map ( async ( { os, arch, tag } ) => {
87
+ return $ `docker manifest annotate ${ img } :latest ${ img } :${ tag } --os ${ os } --arch ${ arch } ` ;
88
+ } ) ) ;
89
+
90
+ await $ `docker manifest push --purge ${ img } :latest`
67
91
}
68
92
69
93
main ( ) ;
0 commit comments