Skip to content

Commit

Permalink
#822: Refactor legacy build steps to honor new restart rebuild boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 2, 2018
1 parent e57c2ca commit ae4ceab
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
42 changes: 35 additions & 7 deletions examples/new-build-process/.lando.yml
Expand Up @@ -45,14 +45,42 @@ services:
#
command: npm start

# Install some extra server packages
# run_as_root:
# - "apt-get update -y"
# - "apt-get install vim -y"
# Install server dependencies and packages that your app needs to run
# These run BEFORE your app boots up and are things that require root access
# Installing extra php extensions is a good example
install_dependencies_as_root:
- apt-get update -y
- apt-get install vim -y

# Print a message just to demonstrate this
# run:
# - "cd $LANDO_MOUNT & echo 'Holla!'"
# Install app dependencies and packages that your app needs to run
# These also run BEFORE your app boots up but are things you don't want to
# install as root.
# Running `npm install` or `yarn` is a good example
install_dependencies_as_me:
- yarn

# We encourage you to use events to automate commands that should run AFTER
# your app starts eg a watch task

# DEPRECATED BUILD STEPS, these will still run as they did pre-RC1 but we
# HIGHLY ENCOURAGE you to move to the new build step format above.
#
# See https://docs.devwithlando.io/config/build.html#build-steps
#
# Note that *_internal steps should not be invoked like they are here
# these channels are meant only for lando to use programmatically
run_as_root_internal:
- echo "run as root internal $(whoami)"
run_as_root:
- echo "run as root $(whoami)"
extras:
- echo "extras $(whoami)"
run_internal:
- echo "run internal $(whoami)"
run_root:
- echo "run $(whoami)"
build:
- echo "build $(whoami)"

# Add some nice command routing
tooling:
Expand Down
28 changes: 13 additions & 15 deletions plugins/lando-services/index.js
Expand Up @@ -185,9 +185,9 @@ module.exports = lando => {
});
});

// Remove build cache on an uninstall
// Remove build lock on an uninstall
app.events.on('post-uninstall', () => {
lando.cache.remove(app.name + '.last_build');
lando.cache.remove(app.name + '.build-lock');
});

// Add some logic that extends start until healthchecked containers report as healthy
Expand Down Expand Up @@ -215,7 +215,7 @@ module.exports = lando => {

// Handle build steps
// Go through each service and run additional build commands as needed
app.events.on('post-start', () => {
app.events.on('app-ready', () => {
// Start up a build collector and set target build services
const buildServices = app.config.services;

Expand All @@ -240,6 +240,7 @@ module.exports = lando => {
compose: app.compose,
project: app.name,
opts: {
pre: 'cd /app',
app: app,
mode: 'attach',
user: (step.type === 'root') ? 'root' : user,
Expand All @@ -248,21 +249,18 @@ module.exports = lando => {
};
});

// Only proceed if build is non-empty
if (!_.isEmpty(build)) {
// Compute the build hash
const newHash = lando.node.hasher(app.config);

// If our new hash is different then lets build
if (lando.cache.get(app.name + '.last_build') !== newHash) {
// Run the stuff
// Run the legacy build steps stuff
app.events.on('post-start', () => {
// Only proceed if build is non-empty and we aren't locked
// console.log(!_.isEmpty(build) && !lando.cache.get(app.name + '.build-lock'))
// console.log('RUN BUILD?')
// process.exit(1)
if (!_.isEmpty(build) && !lando.cache.get(app.name + '.build-lock')) {
return lando.engine.run(build)

// Save the new hash if everything works out ok
.then(() => {
lando.cache.set(app.name + '.last_build', newHash, {persist: true});
lando.cache.set(app.name + '.build-lock', 'YOU SHALL NOT PASS', {persist: true});
})

// Make sure we don't save a hash if our build fails
.catch(error => {
lando.log.error('Looks like one of your build steps failed with %s', error);
Expand All @@ -271,7 +269,7 @@ module.exports = lando => {
lando.log.debug('Build error %s', error.stack);
});
}
}
});
});
});

Expand Down

0 comments on commit ae4ceab

Please sign in to comment.