Skip to content

Commit

Permalink
Merge pull request #2139 from Automattic/dev-env-volume-fun
Browse files Browse the repository at this point in the history
refactor(dev-env): let `dev-tools` handle their volumes
  • Loading branch information
sjinks authored Dec 12, 2024
2 parents b32b0b6 + f77bded commit c12f9d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 51 deletions.
36 changes: 26 additions & 10 deletions assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,28 @@ services:
type: compose
services:
image: ghcr.io/automattic/vip-container-images/dev-tools:0.9
command: /bin/true
volumes:
- devtools:/dev-tools
- scripts:/scripts
environment:
LANDO_NO_USER_PERMS: 1
LANDO_NO_SCRIPTS: 1
LANDO_NEEDS_EXEC: 1
volumes:
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
ssl: true
sslExpose: false
services:
image: ghcr.io/automattic/vip-container-images/nginx:latest
command: nginx -g "daemon off;"
environment:
LANDO_NEEDS_EXEC: 1
LANDO_WEBROOT_USER: nginx
LANDO_WEBROOT_GROUP: nginx
volumes:
- ./nginx/extra.conf:/etc/nginx/conf.extra/extra.conf
<% wpVolumes() %>
depends_on:
php:
condition: service_started
entrypoint: /usr/sbin/nginx -g "daemon off;"

php:
type: compose
Expand All @@ -66,6 +61,27 @@ 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
wordpress:
condition: service_started
<% if ( muPlugins.mode == 'image' ) { %>
vip-mu-plugins:
condition: service_started
<% } %>
<% if ( appCode.mode == 'image' ) { %>
demo-app-code:
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 c12f9d4

Please sign in to comment.