Skip to content

Commit bfdbe41

Browse files
committed
Refactor things and support compose.yml files
1 parent dd1fa36 commit bfdbe41

35 files changed

+546
-800
lines changed

.circleci/config.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ insert_final_newline = true
66
charset = utf-8
77
indent_size = 4
88
indent_style = space
9+
10+
[*.{yml,yaml}]
11+
indent_size = 2

.github/workflows/zunit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
9+
workflow_dispatch: ~
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v5
16+
17+
- name: Install ZUnit
18+
run: |
19+
curl -L https://github.com/zunit-zsh/zunit/releases/download/v0.8.2/zunit > /usr/local/bin/zunit
20+
curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > /usr/local/bin/revolver
21+
curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > /usr/local/bin/color
22+
chmod +x /usr/local/bin/{color,revolver,zunit}
23+
chmod +x tests/_support/bin/*
24+
25+
- name: Run tests
26+
run: zunit

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.vscode
2+
/.idea
3+
/tests/_output

.zunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ directories:
33
tests: tests
44
output: tests/_output
55
support: tests/_support
6-
time_limit: 30
6+
time_limit: 5
77
fail_fast: false
88
allow_risky: false

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Copyright 2019-2020 Maarten de Boer, Cloudstek
1+
Copyright 2019-2025 Maarten de Boer <[email protected]>
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

7-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ This plugins adds `start`, `restart`, `stop`, `up` and `down` commands when it d
88
in the current directory (e.g. your application). Just run `up` and get coding! This saves you typing `docker-compose`
99
or `vagrant` every time or aliasing them. Also gives you one set of commands that work for both environments.
1010

11-
### Docker
12-
13-
Aside from simply running `up`, you can also extend your configuration by running `up <name>`, which will
14-
run `docker-compose` with both `docker-compose.yml` and extend it with `docker-compose.<name>.yml`. For more on
15-
extending please see the [official docker documentation](https://docs.docker.com/compose/extends). Additional arguments
16-
will be directly supplied to the docker-compose.
17-
1811
### Vagrant
1912

2013
Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively but don't worry, that's been taken care of
@@ -30,44 +23,66 @@ supplied to vagrant.
3023
| start | [up](https://www.vagrantup.com/docs/cli/up.html) | [start](https://docs.docker.com/compose/reference/start/) |
3124
| restart | [reload](https://www.vagrantup.com/docs/cli/reload.html) | [restart](https://docs.docker.com/compose/reference/restart/) |
3225
| stop | [halt](https://www.vagrantup.com/docs/cli/halt.html) | [stop](https://docs.docker.com/compose/reference/stop/) |
33-
| enter | | [exec](https://docs.docker.com/compose/reference/exec/) /bin/bash -l (or custom command/shell, e.g. with `enter /bin/sh`) |
26+
27+
#### Enter command
28+
29+
There is one extra command that doesn't map to either Vagrant or Docker natively. Currently it is only implemented for
30+
Docker and allows you to quickly open a shell in a container.
31+
32+
```shell
33+
enter my-container # Spawns /bin/bash -l in my-container
34+
enter my-container /bin/sh # Spawns /bin/sh in my-container (useful for Alpine based images)
35+
```
3436

3537
## Installation
3638

3739
### oh-my-zsh
3840

39-
1. Clone this repository in `$ZSH_CUSTOM/plugins/appup`:
41+
1. Clone this repository to `$ZSH_CUSTOM/plugins/appup`.
42+
2. Edit your `.zshrc` and add `appup` to the list of plugins.
4043

41-
```bash
42-
git clone https://github.com/Cloudstek/zsh-plugin-appup.git "$ZSH_CUSTOM/plugins/appup"
43-
```
44-
2. Edit `~/.zshrc` and add `appup` to the list of plugins
44+
### Antidote
4545

46-
### Plain ZSH
46+
```shell
47+
antidote install mdeboer/zsh-plugin-appup
48+
```
4749

48-
1. Clone this repository somewhere
50+
### Antigen
51+
52+
```shell
53+
antigen bundle mdeboer/zsh-plugin-appup
54+
```
4955

50-
2. Edit your `~/.zshrc` and add this line near the bottom of the file:
56+
### ZI
5157

52-
```bash
53-
source path/to/the/repository/appup.plugin.zsh
54-
```
58+
```shell
59+
zi load mdeboer/zsh-plugin-appup
60+
```
5561

56-
## Updating
62+
### Plain ZSH
5763

58-
1. Go to the directory where you cloned the plugin repository
59-
2. Run `git pull origin master`
64+
1. Clone this repository somewhere
65+
2. Edit your `.zshrc` and `source` the `appup.plugin.zsh` somewhere:
6066

6167
## Configuration options
6268

63-
AppUp has a few configuration options to customise its behaviour. Please make sure you define these in `~/.zshrc`
64-
*before* you load any plugins.
69+
This plugin has a few configuration options to customise its behaviour. Please make sure you define these in your
70+
`.zshrc` file *before* you load any plugins.
71+
72+
For more information about `zstyle`, see the man page `zshmodules(1)`.
73+
74+
| Option | Values | Default | Description |
75+
|----------------------------------------------|--------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
76+
| `':omz:plugins:appup:docker' check-started` | yes/no | no | Enable/disable checking if docker is running. |
77+
| `':omz:plugins:appup:docker' docker-machine` | yes/no | no | If both docker (e.g. Docker Desktop) and docker-machine are installed, check if docker-machine (when `yes`) or docker (when `no`) is running. |
78+
| `':omz:plugins:appup:docker' env-files` | array | | Additional env files to load (if they exist) when running `up` (adds `--env-file=...` arguments to the docker compose command). |
6579

66-
Currently these options only affect docker.
80+
### Example
6781

68-
| Name | Values | Default | Description |
69-
|----------------------|------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------|
70-
| APPUP_CHECK_STARTED | true/false | true | Enable/disable checking if docker is running completely. |
71-
| APPUP_DOCKER_MACHINE | true/false | true | If both docker (e.g. Docker Desktop) and docker-machine are installed, check if docker-machine (when `true`) or docker (when `false`) is running. |
72-
| APPUP_LOAD_ENVS | true/false | true | When true, load .env, .env.local, .env.docker and .env.docker.local if they exist with `docker compose --env-file`. |
82+
```shell
83+
zstyle ':omz:plugins:appup:docker' check-started yes
84+
zstyle ':omz:plugins:appup:docker' docker-machine no
85+
zstyle ':omz:plugins:appup:docker' env-files .env.foo .env.bar # Will also load .env.foo and/or .env.bar if they exist.
7386

87+
# Load the plugin here...
88+
```

UPGRADING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Upgrading
2+
3+
## 1.4.x - 2.0.x
4+
5+
### Repository URL
6+
7+
The repository moved from https://github.com/Cloudstek/zsh-plugin-appup to https://github.com/mdeboer/zsh-plugin-appup.
8+
The owner has not changed, still me.
9+
10+
### Projects (Docker)
11+
12+
There is no longer any support for "projects" where for example `up foo` would look to see if `docker-compose.foo.yml`
13+
exists and would call `docker compose -f docker-compose.yml -f docker-compose.foo.yml up ...`.
14+
15+
The implementation was fragile and a pain to maintain. Composer itself now has plenty of (better) options to manage
16+
scenarios like this and it is often better to supply the arguments themselves if needed.
17+
18+
### Configuration options
19+
20+
The configuration options have changed from environment variables to using `zstyle` (see the `zshmodules` man page).
21+
22+
| Old | New | Notes |
23+
|----------------------|----------------------------------------------|---------------------------------------------------------|
24+
| APPUP_CHECK_STARTED | `':omz:plugins:appup:docker' check-started` | |
25+
| APPUP_DOCKER_MACHINE | `':omz:plugins:appup:docker' docker-machine` | |
26+
| APPUP_LOAD_ENVS | `':omz:plugins:appup:docker' env-files` | Please see the [README](README.md), minor changes here. |

_docker.zsh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
COMPOSER_FILES=('compose.yaml' 'compose.yml' 'docker-compose.yaml' 'docker-compose.yml')
2+
3+
_appup_docker () {
4+
if hash docker >/dev/null 2>&1 -neq 0; then
5+
echo >&2 "Docker compose file found but docker compose is not installed."
6+
return 1
7+
fi
8+
9+
# Check if docker has been started
10+
if zstyle -t ':omz:plugins:appup:docker' check-started; then
11+
if hash docker-machine >/dev/null 2>&1 && zstyle -t ':omz:plugins:appup:docker' docker-machine; then
12+
if docker-machine status | grep -qi "Stopped"; then
13+
read -r -k 1 "REPLY?Docker Machine is not running, would you like to start it? [y/N] "
14+
echo ""
15+
16+
if [[ "${REPLY:l}" != "y" ]]; then
17+
return 0
18+
fi
19+
20+
docker-machine start default && eval $(docker-machine env default)
21+
echo ""
22+
fi
23+
elif docker ps 2>&1 | grep -qi "Is the docker daemon running?"; then
24+
if [[ "${OSTYPE:l}" != "darwin"* ]]; then
25+
echo "Docker is not running."
26+
return 1
27+
fi
28+
29+
read -r -k 1 "REPLY?Docker for Mac is not running, would you like to start it? [y/N] "
30+
echo ""
31+
32+
if [[ "${REPLY:l}" != "y" ]]; then
33+
return 0
34+
fi
35+
36+
open -a Docker
37+
38+
echo ""
39+
echo "Waiting for docker to start.."
40+
echo ""
41+
42+
# Wait for it to start
43+
while true; do
44+
if docker ps 2>&1 | grep -qi "Is the docker daemon running?" || docker ps 2>&1 | grep -qi "connection refused"; then
45+
sleep 5
46+
else
47+
break
48+
fi
49+
done
50+
fi
51+
fi
52+
53+
# Env files
54+
env_files=()
55+
56+
if [[ "$1" == "up" ]]; then
57+
zstyle -a ':omz:plugins:appup:docker' env-files opt_env_files
58+
59+
for f in $opt_env_files; do
60+
if [ -e "$f" ]; then
61+
env_files+=( "$f" )
62+
fi
63+
done
64+
fi
65+
66+
# Run docker compose.
67+
docker compose --env-file=$^env_files $1 "${@:2}"
68+
}
69+
70+
_appup_docker_file_found() {
71+
for f in "${COMPOSER_FILES[@]}"; do
72+
if [ -e "$f" ]; then
73+
return 0
74+
fi
75+
done
76+
77+
return 1
78+
}

_vagrant.zsh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_appup_vagrant () {
2+
if hash vagrant >/dev/null 2>&1; then
3+
vagrant $1 "${@:2}"
4+
else
5+
echo >&2 "Vagrant file found but vagrant is not installed."
6+
fi
7+
}

0 commit comments

Comments
 (0)