From 2b2b5ccd5a83c05602a8681414a68328dbc7e28d Mon Sep 17 00:00:00 2001 From: Aaron Feledy Date: Tue, 13 Aug 2024 20:47:59 -0400 Subject: [PATCH 1/2] allow specifying services to destroy --- .github/workflows/pr-core-tests.yml | 1 + examples/destroy/.gitignore | 1 + examples/destroy/.lando.yml | 19 ++++++++++ examples/destroy/README.md | 56 +++++++++++++++++++++++++++++ tasks/destroy.js | 18 +++++++--- 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 examples/destroy/.gitignore create mode 100644 examples/destroy/.lando.yml create mode 100644 examples/destroy/README.md diff --git a/.github/workflows/pr-core-tests.yml b/.github/workflows/pr-core-tests.yml index f489cbeb7..955ac5774 100644 --- a/.github/workflows/pr-core-tests.yml +++ b/.github/workflows/pr-core-tests.yml @@ -24,6 +24,7 @@ jobs: - certs - config - debug + - destroy - envfile # - environment - events diff --git a/examples/destroy/.gitignore b/examples/destroy/.gitignore new file mode 100644 index 000000000..55f47a3ef --- /dev/null +++ b/examples/destroy/.gitignore @@ -0,0 +1 @@ +.lando diff --git a/examples/destroy/.lando.yml b/examples/destroy/.lando.yml new file mode 100644 index 000000000..98cecba9a --- /dev/null +++ b/examples/destroy/.lando.yml @@ -0,0 +1,19 @@ +name: lando-destroy +services: + node1: + api: 4 + image: node + command: sleep infinity + user: node + storage: + - /usr/share/node + node2: + api: 4 + image: node + command: sleep infinity + user: node + storage: + - /usr/share/node + +plugins: + "@lando/core": "../.." diff --git a/examples/destroy/README.md b/examples/destroy/README.md new file mode 100644 index 000000000..d69b18f6a --- /dev/null +++ b/examples/destroy/README.md @@ -0,0 +1,56 @@ +# Destroy Example + +This example exists primarily to test the following documentation: + +* [`lando destroy`](https://docs.lando.dev/cli/destroy.html) + +See the [Landofiles](https://docs.lando.dev/config/lando.html) in this directory for the exact magicks. + +## Start up tests + +```bash +# Should start successfully +lando poweroff +lando start +``` + +## Verification commands + +Run the following commands to verify things work as expected + +```bash +# Services, volumes, and networks should exist +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node1_1 +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node2_1 +docker volume ls | grep landodestroy-node1-usr-share-node +docker volume ls | grep landodestroy-node2-usr-share-node +docker network ls | grep landodestroy_default + +# Should destroy the specified services +lando destroy --service node1 --yes +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node1_1; [ $? -ne 0 ] +docker volume ls | grep landodestroy-node1-usr-share-node; [ $? -ne 0 ] + +# Should not destroy the unspecified services +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node2_1 +docker volume ls | grep landodestroy-node2-usr-share-node +docker network ls | grep landodestroy_default + +# Should rebuild the destroyed service +lando start +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node1_1 +docker volume ls | grep landodestroy-node1-usr-share-node +``` + +## Destroy tests + +```bash +# Should destroy successfully +lando destroy -y +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node1_1; [ $? -ne 0 ] +docker ps --filter label=com.docker.compose.project=landodestroy | grep landodestroy_node2_1; [ $? -ne 0 ] +docker volume ls | grep landodestroy-node1-usr-share-node; [ $? -ne 0 ] +docker volume ls | grep landodestroy-node2-usr-share-node; [ $? -ne 0 ] +docker network ls | grep landodestroy_default; [ $? -ne 0 ] +lando poweroff +``` diff --git a/tasks/destroy.js b/tasks/destroy.js index 85479bdc5..ce128be63 100644 --- a/tasks/destroy.js +++ b/tasks/destroy.js @@ -3,16 +3,21 @@ module.exports = lando => { return { command: 'destroy', - describe: 'Destroys your app', - usage: '$0 destroy [--yes]', + describe: 'Destroys your app and all its data', + usage: '$0 destroy [--service ...] [--yes]', examples: [ - '$0 destroy --yes', + '$0 destroy --service database --yes', ], options: { + service: { + describe: 'Destroys only the specified services', + alias: ['s'], + array: true, + }, yes: lando.cli.confirm('Are you sure you want to DESTROY?'), }, run: async options => { - // Stop rebuild if user decides its a nogo + // Stop destroy if user decides its a nogo if (!options.yes) { console.log(lando.cli.makeArt('appDestroy', {phase: 'abort'})); return; @@ -21,6 +26,11 @@ module.exports = lando => { const app = lando.getApp(options._app.root); // Destroy the app if (app) { + // If user has given us options then set those + if (options.service?.length) { + app.opts = Object.assign({}, app.opts, {services: options.service}); + } + console.log(lando.cli.makeArt('appDestroy', {name: app.name, phase: 'pre'})); await app.destroy(); console.log(lando.cli.makeArt('appDestroy', {name: app.name, phase: 'post'})); From 5822972cb6098884a8a138dd9a96850d622e0f21 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Wed, 14 Aug 2024 11:42:16 -0700 Subject: [PATCH 2/2] Satisfy link checker. --- docs/lando-service.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lando-service.md b/docs/lando-service.md index 360493692..3b4779281 100644 --- a/docs/lando-service.md +++ b/docs/lando-service.md @@ -111,7 +111,7 @@ services: #### Mount with a different flag -Set `app_mount` to any valid Docker bind mount [third field](https://docs.docker.com/storage/bind-mounts/). +Set `app_mount` to any valid Docker bind mount [third field](https://docs.docker.com/engine/storage/bind-mounts/). **Landofile** ```yaml