Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dev-env): let dev-tools handle their volumes #2139

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward compatibility :-(


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
Loading