Skip to content

Commit

Permalink
Merge pull request #148 from adobe/stage
Browse files Browse the repository at this point in the history
Changes required for aio stage deployment
  • Loading branch information
Himavanth authored Apr 6, 2021
2 parents 562e9d0 + faa58d1 commit 5abe8e9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/remote-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ module.exports = class RemoteStorage {
const uploadParams = {
Key: urlJoin(prefix, path.basename(file)),
Body: content,
ACL: 'public-read',
CacheControl: cacheControlString
}
// s3 misses some mime types like for css files
Expand Down
4 changes: 2 additions & 2 deletions src/deploy-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const deployWeb = async (config, log) => {
await getTvmCredentials(config.ow.namespace, config.ow.auth, config.s3.tvmUrl, config.s3.credsCacheFile)

const remoteStorage = new RemoteStorage(creds)
const exists = await remoteStorage.folderExists(config.s3.folder)
const exists = await remoteStorage.folderExists(config.s3.folder + '/')

if (exists) {
if (log) {
log('warning: an existing deployment will be overwritten')
}
await remoteStorage.emptyFolder(config.s3.folder)
await remoteStorage.emptyFolder(config.s3.folder + '/')
}
const _log = log ? (f) => log(`deploying ${path.relative(dist, f)}`) : null
await remoteStorage.uploadDir(dist, config.s3.folder, config.app, _log)
Expand Down
39 changes: 39 additions & 0 deletions test/src/deploy-web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,44 @@ describe('deploy-web', () => {
expect(RemoteStorage).toHaveBeenCalledTimes(1)
})

test('calls to s3 should use ending slash', async () => {
const config = {
ow: {
namespace: 'ns',
auth: 'password'
},
s3: {
credsCacheFile: 'file',
tvmUrl: 'url',
folder: 'nsfolder'
},
app: {
hasFrontend: true,
hostname: 'host'
},
web: {
distProd: 'dist'
}
}
const emptyFolder = jest.fn()
const folderExists = jest.fn(() => true)
RemoteStorage.mockImplementation(() => {
return {
emptyFolder,
folderExists,
uploadDir: jest.fn()
}
})
fs.existsSync.mockReturnValue(true)
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
const mockLogger = jest.fn()
fs.readdirSync.mockReturnValue({ length: 1 })
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
expect(getTvmCredentials).toHaveBeenCalled()
expect(RemoteStorage).toHaveBeenCalledTimes(1)
expect(folderExists).toHaveBeenLastCalledWith('nsfolder/')
expect(emptyFolder).toHaveBeenLastCalledWith('nsfolder/')
})

// if !tvm creds, then we require config.ow.namespace, config.ow.auth, config.s3.tvmUrl, config.s3.credsCacheFile
})

0 comments on commit 5abe8e9

Please sign in to comment.