From ad79076300a0aeacdf84a1392642a5e9dae958f6 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Thu, 5 Dec 2024 07:20:06 +0200 Subject: [PATCH 1/2] refactor(dev-env): let `dev-tools` handle their volume --- assets/dev-env.lando.template.yml.ejs | 13 +++++- src/lib/constants/dev-environment.ts | 2 +- .../dev-environment/dev-environment-lando.ts | 40 ------------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/assets/dev-env.lando.template.yml.ejs b/assets/dev-env.lando.template.yml.ejs index b7ab57bac..d94a42d37 100644 --- a/assets/dev-env.lando.template.yml.ejs +++ b/assets/dev-env.lando.template.yml.ejs @@ -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 @@ -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 @@ -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 diff --git a/src/lib/constants/dev-environment.ts b/src/lib/constants/dev-environment.ts index a00b9979f..196c86fb7 100644 --- a/src/lib/constants/dev-environment.ts +++ b/src/lib/constants/dev-environment.ts @@ -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'; diff --git a/src/lib/dev-environment/dev-environment-lando.ts b/src/lib/dev-environment/dev-environment-lando.ts index 0d6c7090f..026e976d1 100644 --- a/src/lib/dev-environment/dev-environment-lando.ts +++ b/src/lib/dev-environment/dev-environment-lando.ts @@ -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 { @@ -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 From f77bded836de077cb54b6ff8b0e9405a736c8dde Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Sat, 7 Dec 2024 09:10:45 +0200 Subject: [PATCH 2/2] fix: set dependencies between services --- assets/dev-env.lando.template.yml.ejs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/assets/dev-env.lando.template.yml.ejs b/assets/dev-env.lando.template.yml.ejs index d94a42d37..ccf72dfd0 100644 --- a/assets/dev-env.lando.template.yml.ejs +++ b/assets/dev-env.lando.template.yml.ejs @@ -22,10 +22,6 @@ services: volumes: - devtools:/dev-tools - scripts:/scripts - environment: - LANDO_NO_USER_PERMS: 1 - LANDO_NO_SCRIPTS: 1 - LANDO_NEEDS_EXEC: 1 volumes: devtools: {} scripts: @@ -38,14 +34,13 @@ services: 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 @@ -77,6 +72,16 @@ services: <% } %> 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