@@ -52,7 +52,7 @@ function get_slim() {
52
52
}
53
53
}
54
54
catch ( _a ) {
55
- throw new Error ( ' ERROR! Could not retrieve the current Slim version number.' ) ;
55
+ throw new Error ( ` ERROR! Could not get the Slim version ${ VER } .` ) ;
56
56
}
57
57
URL = `https://downloads.dockerslim.com/releases/${ VER } ` ;
58
58
// Get kernel name and machine architecture.
@@ -89,39 +89,61 @@ function get_slim() {
89
89
}
90
90
// Derive the filename
91
91
FILENAME = `dist_${ DIST } .${ EXT } ` ;
92
- const file = const_1 . fs . createWriteStream ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ) ;
93
- yield new Promise ( ( resolve , reject ) => {
94
- const_1 . https . get ( `${ URL } /${ FILENAME } ` , ( response ) => {
95
- response . pipe ( file ) ;
96
- file . on ( 'finish' , ( ) => {
97
- file . close ( ) ;
98
- resolve ( file ) ;
99
- } ) ;
100
- } ) . on ( 'error' , ( error ) => {
101
- const_1 . fs . unlinkSync ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ) ;
102
- reject ( error ) ;
103
- } ) ;
104
- } ) ;
105
- const_1 . core . debug ( `Unpacking ${ const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) } ` ) ;
106
- if ( EXT === 'zip' ) {
107
- const extract = require ( 'extract-zip' ) ;
108
- yield extract ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) , {
109
- dir : const_1 . TMP_DIR
110
- } ) ;
92
+ // Get the bin from cache
93
+ const cachePrefix = `slim-${ VER } ` ;
94
+ const cacheKey = `${ cachePrefix } -${ DIST } ` ;
95
+ const cachePath = const_1 . path . join ( '/tmp' , cacheKey ) ;
96
+ try {
97
+ const_1 . core . debug ( 'Restoring cache' ) ;
98
+ const cacheResult = yield const_1 . cache . restoreCache ( [ cachePath ] , cacheKey , [ `${ cachePrefix } -` ] ) ;
99
+ if ( typeof cacheResult === 'undefined' ) {
100
+ throw new Error ( `ERROR! Cache miss: ${ cacheKey } was not found in the cache.` ) ;
101
+ }
102
+ const_1 . core . debug ( `${ cacheKey } cache was restored.` ) ;
103
+ SLIM_PATH = cachePath ;
111
104
}
112
- else if ( EXT === 'tar.gz' ) {
113
- const tar = require ( 'tar' ) ;
114
- yield tar . x ( {
115
- file : const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ,
116
- cwd : const_1 . TMP_DIR
105
+ catch ( e ) {
106
+ const_1 . core . error ( e ) ;
107
+ const file = const_1 . fs . createWriteStream ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ) ;
108
+ yield new Promise ( ( resolve , reject ) => {
109
+ const_1 . https . get ( `${ URL } /${ FILENAME } ` , ( response ) => {
110
+ response . pipe ( file ) ;
111
+ file . on ( 'finish' , ( ) => {
112
+ file . close ( ) ;
113
+ resolve ( file ) ;
114
+ } ) ;
115
+ } ) . on ( 'error' , ( error ) => {
116
+ const_1 . fs . unlinkSync ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ) ;
117
+ reject ( error ) ;
118
+ } ) ;
117
119
} ) ;
120
+ const_1 . core . debug ( `Unpacking ${ const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) } ` ) ;
121
+ if ( EXT === 'zip' ) {
122
+ const extract = require ( 'extract-zip' ) ;
123
+ yield extract ( const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) , {
124
+ dir : const_1 . TMP_DIR
125
+ } ) ;
126
+ }
127
+ else if ( EXT === 'tar.gz' ) {
128
+ const tar = require ( 'tar' ) ;
129
+ yield tar . x ( {
130
+ file : const_1 . path . join ( const_1 . TMP_DIR , FILENAME ) ,
131
+ cwd : const_1 . TMP_DIR
132
+ } ) ;
133
+ }
134
+ else {
135
+ throw new Error ( 'ERROR! Unexpected file extension.' ) ;
136
+ }
137
+ SLIM_PATH = const_1 . path . join ( const_1 . TMP_DIR , `dist_${ DIST } ` ) ;
138
+ const_1 . core . debug ( `Copying ${ SLIM_PATH } -> (${ cachePath } )` ) ;
139
+ yield const_1 . io . cp ( SLIM_PATH , cachePath , { recursive : true , force : true } ) ;
140
+ const cacheId = yield const_1 . cache . saveCache ( [ cachePath ] , cacheKey ) ;
141
+ const_1 . core . debug ( `${ cacheKey } cache saved (ID: ${ cacheId } )` ) ;
118
142
}
119
- else {
120
- throw new Error ( 'ERROR! Unexpected file extension.' ) ;
143
+ finally {
144
+ const_1 . core . addPath ( SLIM_PATH ) ;
145
+ const_1 . core . info ( `Using slim version ${ VER } ` ) ;
121
146
}
122
- SLIM_PATH = const_1 . path . join ( const_1 . TMP_DIR , `dist_${ DIST } ` ) ;
123
- const_1 . core . addPath ( SLIM_PATH ) ;
124
- const_1 . core . info ( `Using slim version ${ VER } ` ) ;
125
147
} ) ;
126
148
}
127
149
function run ( ) {
0 commit comments