Skip to content

Commit

Permalink
refactor(dev-env): let dev-tools handle their volume
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Dec 12, 2024
1 parent b32b0b6 commit ad79076
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
13 changes: 12 additions & 1 deletion assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
type: compose
services:
image: ghcr.io/automattic/vip-container-images/dev-tools:0.9
command: /bin/true
volumes:
- devtools:/dev-tools
- scripts:/scripts
Expand All @@ -31,6 +30,7 @@ services:
devtools: {}
scripts:
initOnly: true
entrypoint: sh -c 'test -d /dev-tools-orig && /usr/bin/rsync -a --delete /dev-tools-orig/ /dev-tools/ || true'

nginx:
type: compose
Expand Down Expand Up @@ -66,6 +66,17 @@ services:
<% } %>
LANDO_NO_USER_PERMS: 'enable'
LANDO_NEEDS_EXEC: 1
depends_on:
database:
condition: service_started
memcached:
condition: service_started
<% if ( elasticsearch ) { %>
elasticsearch:
condition: service_started
<% } %>
devtools:
condition: service_completed_successfully
volumes:
- type: volume
source: devtools
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants/dev-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export const DEV_ENVIRONMENT_DEFAULTS = {
phpVersion: Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ],
} as const;

export const DEV_ENVIRONMENT_VERSION = '2.1.2';
export const DEV_ENVIRONMENT_VERSION = '2.1.3';
40 changes: 0 additions & 40 deletions src/lib/dev-environment/dev-environment-lando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ export async function landoRebuild( lando: Lando, instancePath: string ): Promis

const app = await getLandoApplication( lando, instancePath );

app.events.on( 'post-uninstall', async () => removeDevToolsVolumes( lando, app ) );

await ensureNoOrphantProxyContainer( lando );
await app.rebuild();
} finally {
Expand Down Expand Up @@ -704,44 +702,6 @@ export async function landoShell(
} );
}

/**
* Dev-tools volumes can get stale and is not updated when the new version of dev-tools
* image is installed. Removing it during rebuild ensures the content is freshly populated
* on startup.
*
* @param {Lando} lando
* @param {App} app
*/
async function removeDevToolsVolumes( lando: Lando, app: App ) {
debug( 'Attempting to removing dev-tools volumes' );

const scanResult = await lando.engine.docker.listVolumes();
const devToolsVolumeNames = scanResult.Volumes.map( volume => volume.Name )
// eslint-disable-next-line security/detect-non-literal-regexp
.filter( volumeName => new RegExp( `${ app.project }.*devtools` ).test( volumeName ) );

debug( 'Will remove', devToolsVolumeNames );

const removalPromises = devToolsVolumeNames.map( volumeName =>
removeVolume( lando, volumeName )
);
await Promise.all( removalPromises );
}

/**
* Remove volume
*/
async function removeVolume( lando: Lando, volumeName: string ): Promise< void > {
debug( `Removing devtools volume ${ volumeName }` );
const devToolsVolume = lando.engine.docker.getVolume( volumeName );
try {
await devToolsVolume.remove();
debug( `${ volumeName } volume removed` );
} catch ( err ) {
debug( `Failed to remove volume ${ volumeName }`, err );
}
}

/**
* Sometimes the proxy network seems to disapper leaving only orphant stopped proxy container.
* It seems to happen while restarting/powering off computer. This container would then failed
Expand Down

0 comments on commit ad79076

Please sign in to comment.