https://github.com/luanphandinh/env
Start working environment with a single script. Including databases, elastic search, nginx, etc
https://github.com/luanphandinh/env
docker docker-compose workspace
Last synced: 3 months ago
JSON representation
Start working environment with a single script. Including databases, elastic search, nginx, etc
- Host: GitHub
- URL: https://github.com/luanphandinh/env
- Owner: luanphandinh
- Created: 2019-08-14T07:14:16.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T14:09:36.000Z (about 5 years ago)
- Last Synced: 2025-03-24T12:36:34.480Z (over 1 year ago)
- Topics: docker, docker-compose, workspace
- Language: Shell
- Homepage:
- Size: 204 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# env  
Easy, clean and faster way to spin up docker containers: mysql, adminer, es, rabbitmq, ...\
Seprate profile and highly confirgurable.
## install
clone this project to anywhwere in your computer, then `cd `
```bash
make install
```
`cli` is the `alias` refer to `/cli.sh` file, if the `make install` command doesn't include the `alias cli -> /cli.sh`, you could create alias on your own.
## help
```bash
cli -h
cli docker -h
```
## docker
run:
```
cli docker run mysql adminer
```
The command above will look into `./env/etc/docker/` and find `mysql.yaml`, `adminer.yaml` and use `docker-compose` to start docker services.
run with profile (`cli -p docker run mysql adminer`):
```
cli -p new_to_env docker run mysql adminer
```
Add new docker-compose file that not existed in current repository\
Simply add `.yml` into `env/etc/docker`.\
```
cli/etc
|__docker
| |__ .PORTS // This file content all the default PORTS that will be used accross all dockers config file
| |__mysql.yaml
| |__adminer.yaml
|
|__profile
| |__default
| | |__ .env
| |__ new_to_env
| | |__ .env
```
example file (`etc/docker/mysql.yaml`):
```yaml
version: '3.3'
services:
mysql:
container_name: "${__DOCKER_SERVICE_PREFIX__}_mysql"
hostname: "${__DOCKER_SERVICE_PREFIX__}_mysql"
image: mysql
volumes:
- '${__DOCKER_PATH__}/mysql:/var/lib/mysql'
command:
- --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: rootroot
MYSQL_DATABASE: workspace
MYSQL_USER: admin
MYSQL_PASSWORD: admin
ports:
- ${MYSQL_PORT}:3306
```
configs:
* `__DOCKER_PATH__` refer to `var/lib/docker//`\
Highly recommended to use this path, it allows you to seperate your runtime data with profile
* `__DOCKER_DIR__` refer to current config path `env/etc/docker/`
If you want to bind some config that will be reused and not seperate by profile, could be put them into this place\
Seem more at `env/etc/docker/vault.yaml`
* `__DOCKER_SERVICE_PREFIX__` auto generated by cli, value as `docker__`
* `*_PORTS` can be found under `env/etc/docker/.PORTS`.\
Highly recommend your new service has default dynamic env binding port to outside, as it will be easier to running with profiles later
## Profile
set:
```
cli -p new_to_env set ADMINER_PORT=4444
```
Then run docker service with profile:
```
cli -p new_to_env docker run adminer
```
This will up and running `cli_new_to_env_adminer` container on port `4444`, cause the profile override the default `ADMINER_PORT=4000`
run:
```
cli -p new_to_env run npm run dev
```
Suppose you have service written in javascript, you can facilitate using profile with all its `.env` config and apply to process that run `npm run dev`.
## Config file:
Run all services:
```bash
cli up ./test/config.dev.yaml
```
Run optional services:
```
cli up ./test/config.dev.yaml node something
```
```yaml
version: '2.1'
import_profile: service
env:
- ADMINER_PORT=5555
- SAY=Bonjour
dockers:
- redis
- adminer
run:
- node
- php
- something
# - not_run
jobs:
something:
env:
- THIS=THIS
- WILLDO=WILLDO
path: $__ENV_ROOT__/test/
run: chmod +x ./willdo.sh && ./willdo.sh
node:
import_profile: pt
env:
- NAME=CLI
- SAY=$SAY
path: $__ENV_ROOT__/test/
run: node ./service.js
php:
env:
- SAY=$SAY
- NAME=CLI_PHP
path: $__ENV_ROOT__/test/
run: php -S localhost:8080 router.php
not_run:
env:
- SAY=This should not be running
- NAME=CLI_PHP
path: $__ENV_ROOT__/somewhere/
run: php -S localhost:8080 router.php
# also_not_run:
# env:
# - SAY=This should not be running
# - NAME=CLI_PHP
# path: $__ENV_ROOT__/somewhere/
# run: php -S localhost:8080 router.php
```
env scope:
`default (.PORTS) -> profile(etc/config//.env) -> [env] from config file`