Skip to content

Commit 328cb01

Browse files
authored
feat: Add architecture to requirements cache directory name (#645)
1 parent 89b3bab commit 328cb01

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

lib/pip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ async function installRequirementsIfNeeded(
640640
const workingReqsFolder = getRequirementsWorkingPath(
641641
reqChecksum,
642642
requirementsTxtDirectory,
643-
options
643+
options,
644+
serverless
644645
);
645646

646647
// Check if our static cache is present and is valid

lib/shared.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ function checkForAndDeleteMaxCacheVersions({ serverless, options, log }) {
6262
* @param {string} subfolder
6363
* @param {string} servicePath
6464
* @param {Object} options
65+
* @param {Object} serverless
6566
* @return {string}
6667
*/
6768
function getRequirementsWorkingPath(
6869
subfolder,
6970
requirementsTxtDirectory,
70-
options
71+
options,
72+
serverless
7173
) {
7274
// If we want to use the static cache
7375
if (options && options.useStaticCache) {
7476
if (subfolder) {
75-
subfolder = subfolder + '_slspyc';
77+
const architecture = serverless.service.provider.architecture || 'x86_64';
78+
subfolder = `${subfolder}_${architecture}_slspyc`;
7679
}
7780
// If we have max number of cache items...
7881

test.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,12 +2115,15 @@ test(
21152115
sls(['package']);
21162116
const cachepath = getUserCachePath();
21172117
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
2118+
const arch = 'x86_64';
21182119
t.true(
21192120
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
21202121
'http exists in download-cache'
21212122
);
21222123
t.true(
2123-
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
2124+
pathExistsSync(
2125+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}flask`
2126+
),
21242127
'flask exists in static-cache'
21252128
);
21262129
t.end();
@@ -2137,12 +2140,15 @@ test(
21372140
sls(['--dockerizePip=true', 'package']);
21382141
const cachepath = getUserCachePath();
21392142
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
2143+
const arch = 'x86_64';
21402144
t.true(
21412145
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
21422146
'http exists in download-cache'
21432147
);
21442148
t.true(
2145-
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
2149+
pathExistsSync(
2150+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}flask`
2151+
),
21462152
'flask exists in static-cache'
21472153
);
21482154
t.end();
@@ -2159,20 +2165,23 @@ test(
21592165
sls(['package']);
21602166
const cachepath = getUserCachePath();
21612167
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
2168+
const arch = 'x86_64';
21622169
t.true(
2163-
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
2170+
pathExistsSync(
2171+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}flask`
2172+
),
21642173
'flask exists in static-cache'
21652174
);
21662175
t.true(
21672176
pathExistsSync(
2168-
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}.completed_requirements`
2177+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}.completed_requirements`
21692178
),
21702179
'.completed_requirements exists in static-cache'
21712180
);
21722181

21732182
// py3.6 checking that static cache actually pulls from cache (by poisoning it)
21742183
writeFileSync(
2175-
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}injected_file_is_bad_form`,
2184+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}injected_file_is_bad_form`,
21762185
'injected new file into static cache folder'
21772186
);
21782187
sls(['package']);
@@ -2197,13 +2206,16 @@ test(
21972206
const cachepath = '.requirements-cache';
21982207
sls([`--cacheLocation=${cachepath}`, 'package']);
21992208
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
2209+
const arch = 'x86_64';
22002210
t.true(
2201-
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
2211+
pathExistsSync(
2212+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}flask`
2213+
),
22022214
'flask exists in static-cache'
22032215
);
22042216
t.true(
22052217
pathExistsSync(
2206-
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}.completed_requirements`
2218+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}.completed_requirements`
22072219
),
22082220
'.completed_requirements exists in static-cache'
22092221
);
@@ -2221,20 +2233,23 @@ test(
22212233
sls(['--dockerizePip=true', '--slim=true', 'package']);
22222234
const cachepath = getUserCachePath();
22232235
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
2236+
const arch = 'x86_64';
22242237
t.true(
2225-
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
2238+
pathExistsSync(
2239+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}flask`
2240+
),
22262241
'flask exists in static-cache'
22272242
);
22282243
t.true(
22292244
pathExistsSync(
2230-
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}.completed_requirements`
2245+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}.completed_requirements`
22312246
),
22322247
'.completed_requirements exists in static-cache'
22332248
);
22342249

22352250
// py3.6 checking that static cache actually pulls from cache (by poisoning it)
22362251
writeFileSync(
2237-
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}injected_file_is_bad_form`,
2252+
`${cachepath}${sep}${cacheFolderHash}_${arch}_slspyc${sep}injected_file_is_bad_form`,
22382253
'injected new file into static cache folder'
22392254
);
22402255
sls(['--dockerizePip=true', '--slim=true', 'package']);

0 commit comments

Comments
 (0)