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

Allow specifying services to destroy #194

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/pr-core-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- certs
- config
- debug
- destroy
- envfile
# - environment
- events
Expand Down
2 changes: 1 addition & 1 deletion docs/lando-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/destroy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.lando
19 changes: 19 additions & 0 deletions examples/destroy/.lando.yml
Original file line number Diff line number Diff line change
@@ -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": "../.."
56 changes: 56 additions & 0 deletions examples/destroy/README.md
Original file line number Diff line number Diff line change
@@ -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
```
18 changes: 14 additions & 4 deletions tasks/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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;
Expand All @@ -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'}));
Expand Down
Loading