Skip to content

Commit 9ed5305

Browse files
committed
Merge branch 'develop'
2 parents 925835c + dd1fa36 commit 9ed5305

File tree

3 files changed

+83
-27
lines changed

3 files changed

+83
-27
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_size = 4
8+
indent_style = space

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@
44
55
[![CircleCI](https://circleci.com/gh/Cloudstek/zsh-plugin-appup.svg?style=svg)](https://circleci.com/gh/Cloudstek/zsh-plugin-appup)
66

7-
This plugins adds `start`, `restart`, `stop`, `up` and `down` commands when it detects a docker-compose or Vagrant file in the current directory (e.g. your application). Just run `up` and get coding! This saves you typing `docker-compose` or `vagrant` every time or aliasing them. Also gives you one set of commands that work for both environments.
7+
This plugins adds `start`, `restart`, `stop`, `up` and `down` commands when it detects a docker-compose or Vagrant file
8+
in the current directory (e.g. your application). Just run `up` and get coding! This saves you typing `docker-compose`
9+
or `vagrant` every time or aliasing them. Also gives you one set of commands that work for both environments.
810

911
### Docker
1012

11-
Aside from simply running `up`, you can also extend your configuration by running `up <name>`, which will run `docker-compose` with both `docker-compose.yml` and extend it with `docker-compose.<name>.yml`. For more on extending please see the [official docker documentation](https://docs.docker.com/compose/extends). Additional arguments will be directly supplied to the docker-compose.
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.
1217

1318
### Vagrant
1419

15-
Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively but don't worry, that's been taken care of and running those commands will actually run vagrant's equivalent commands. Additional arguments will be directly supplied to vagrant.
20+
Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively but don't worry, that's been taken care of
21+
and running those commands will actually run vagrant's equivalent commands. Additional arguments will be directly
22+
supplied to vagrant.
1623

1724
### Command mapping
1825

19-
| Command | Vagrant command | Docker command |
20-
| ------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
21-
| up | [up](https://www.vagrantup.com/docs/cli/up.html) | [up](https://docs.docker.com/compose/reference/up/) |
22-
| down | [destroy](https://www.vagrantup.com/docs/cli/destroy.html) | [down](https://docs.docker.com/compose/reference/down/) |
23-
| start | [up](https://www.vagrantup.com/docs/cli/up.html) | [start](https://docs.docker.com/compose/reference/start/) |
26+
| Command | Vagrant command | Docker command |
27+
|---------|------------------------------------------------------------|---------------------------------------------------------------|
28+
| up | [up](https://www.vagrantup.com/docs/cli/up.html) | [up](https://docs.docker.com/compose/reference/up/) |
29+
| down | [destroy](https://www.vagrantup.com/docs/cli/destroy.html) | [down](https://docs.docker.com/compose/reference/down/) |
30+
| start | [up](https://www.vagrantup.com/docs/cli/up.html) | [start](https://docs.docker.com/compose/reference/start/) |
2431
| restart | [reload](https://www.vagrantup.com/docs/cli/reload.html) | [restart](https://docs.docker.com/compose/reference/restart/) |
25-
| stop | [halt](https://www.vagrantup.com/docs/cli/halt.html) | [stop](https://docs.docker.com/compose/reference/stop/) |
32+
| 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`) |
2634

2735
## Installation
2836

@@ -52,11 +60,14 @@ Vagrant doesn't have a `down`, `restart`, `start` or `stop` commands natively bu
5260

5361
## Configuration options
5462

55-
AppUp has a few configuration options to customise its behaviour. Please make sure you define these in `~/.zshrc` *before* you load any plugins.
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.
5665

57-
| Name | Values | Default | Description |
58-
| -------------------- | ---------- | ------- | ------------------------------------------------------------ |
59-
| APPUP_CHECK_STARTED | true/false | true | Enable/disable checking if docker is running completely. |
66+
Currently these options only affect docker.
67+
68+
| Name | Values | Default | Description |
69+
|----------------------|------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------|
70+
| APPUP_CHECK_STARTED | true/false | true | Enable/disable checking if docker is running completely. |
6071
| 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. |
61-
| | | | |
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`. |
6273

appup.plugin.zsh

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,64 @@ _appup_docker () {
4040
fi
4141
fi
4242

43-
# Check YAML extension
43+
# Find docker-compose file
4444
compose_file=''
45-
compose_project_file=''
4645

4746
if [ -e "docker-compose.yml" ]; then
4847
compose_file='docker-compose.yml'
4948
elif [ -e "docker-compose.yaml" ]; then
5049
compose_file='docker-compose.yaml'
5150
fi
51+
52+
# Env files
53+
env_files=()
54+
55+
if [ "${APPUP_LOAD_ENVS:-true}" = true ]; then
56+
if [ -e ".env" ]; then
57+
env_files+=( .env )
58+
fi
59+
if [ -e ".env.local" ]; then
60+
env_files+=( .env.local )
61+
fi
62+
if [ -e ".env.docker" ]; then
63+
env_files+=( .env.docker )
64+
fi
65+
if [ -e ".env.docker.local" ]; then
66+
env_files+=( .env.docker.local )
67+
fi
68+
fi
5269

5370
# <cmd> <project name> will look for docker-compose.<project name>.yml
5471
if [ -n "$2" ]; then
72+
# Find project-specific docker-compose file
73+
compose_project_file=''
74+
5575
if [ -e "docker-compose.$2.yml" ]; then
5676
compose_project_file="docker-compose.$2.yml"
5777
elif [ -e "docker-compose.$2.yaml" ]; then
5878
compose_project_file="docker-compose.$2.yaml"
5979
fi
60-
61-
if [ -n "$compose_project_file" ]; then
62-
# Override project name from custom env
63-
if [ -e ".env.$2" ]; then
64-
project=$(source ".env.$2"; echo $COMPOSE_PROJECT_NAME)
65-
66-
if [ -n $project ]; then
67-
docker-compose -p "${project}" -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
68-
return
80+
81+
if [ -n "$compose_project_file" ]; then
82+
# Project specific env file
83+
if [ "${APPUP_LOAD_ENVS:-true}" = true ]; then
84+
if [ -e ".env.$2" ]; then
85+
env_files+=( ".env.$2" )
86+
fi
87+
if [ -e ".env.$2.local" ]; then
88+
env_files+=( ".env.$2.local" )
6989
fi
7090
fi
7191

72-
docker-compose -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
92+
# Run docker compose.
93+
docker-compose -f "$compose_file" -f "$compose_project_file" --env-file=$^env_files $1 "${@:3}"
94+
7395
return
7496
fi
7597
fi
7698

77-
docker-compose $1 "${@:2}"
99+
# Run docker compose.
100+
docker-compose --env-file=$^env_files $1 "${@:2}"
78101
else
79102
echo >&2 "Docker compose file found but docker-compose is not installed."
80103
fi
@@ -139,3 +162,17 @@ stop () {
139162
env stop "$@"
140163
fi
141164
}
165+
166+
enter () {
167+
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
168+
CMD=( "${@:2}" )
169+
170+
if [ $# -eq 1 ]; then
171+
CMD=( /bin/bash -l )
172+
fi
173+
174+
_appup_docker exec "$1" $CMD
175+
elif hash enter >/dev/null 2>&1; then
176+
env enter "$@"
177+
fi
178+
}

0 commit comments

Comments
 (0)