Create a download-only mode for Docker builds
I would like to revisit the suggestion in #11 for a separate "download only" mode, specifically for use in Dockerfiles.
Currently my team is doing something like this:
RUN npx flyway -c flyway.js info; exit 0
The exit 0 is needed because there is no database connectivity at image build time, which causes the info command to fail. We need this command to succeed in order for the Docker build to continue. The big issue with this workaround is that we have no way of knowing if the download itself fails.
I would like to be able to have something like this instead, whereby omitting the command still executes the download:
RUN npx flyway -c flyway.js
This way, if the download fails, the Docker build is aborted.
@michaelmarcus-ml I just wrote a script to do this and I call it during my docker build:
# Cache flyway
RUN npm run cache:flywaydb
and in my package.json I have:
"scripts": {
"cache:flywaydb": "node ./scripts/cache-flywaydb.js"
}
Lastly, I have ./scripts/cache-flywaydb.js as:
'use strict'
const config = require('../db/conf/flyway')
const download = require('node-flywaydb/lib/download') // I don't want to maintain yet another fork of a dead library
/**
* Usage: node ./scripts/cache-flywaydb
*/
try {
download.ensureArtifacts(config, (err, _flywaybin) => {
if (err) {
console.error('Unable to download Flyway')
throw err
}
console.debug('Successfully finished caching flyway OR using cache')
process.exit(0)
})
} catch (err) {
console.error(err)
process.exit(1)
}