I use simple grep
inside function in bash script to receive properties from .properties
file.
This properties file I use in two places - to setup dev environment and as application parameters.
I believe that grep
may work slow in big loops but it solves my needs when I want to prepare dev
environment.
Hope, someone will find this useful.
Example:
File: setup.sh
#!/bin/bash
ENV=${1:-dev}
function prop {
grep "${1}" env/${ENV}.properties|cut -d'=' -f2
}
docker create
--name=myapp-storage
-p $(prop 'app.storage.address'):$(prop 'app.storage.port'):9000
-h $(prop 'app.storage.host')
-e STORAGE_ACCESS_KEY="$(prop 'app.storage.access-key')"
-e STORAGE_SECRET_KEY="$(prop 'app.storage.secret-key')"
-e STORAGE_BUCKET="$(prop 'app.storage.bucket')"
-v "$(prop 'app.data-path')/storage":/app/storage
myapp-storage:latest
docker create
--name=myapp-database
-p "$(prop 'app.database.address')":"$(prop 'app.database.port')":5432
-h "$(prop 'app.database.host')"
-e POSTGRES_USER="$(prop 'app.database.user')"
-e POSTGRES_PASSWORD="$(prop 'app.database.pass')"
-e POSTGRES_DB="$(prop 'app.database.main')"
-e PGDATA="/app/database"
-v "$(prop 'app.data-path')/database":/app/database
postgres:9.5
File: env/dev.properties
app.data-path=/apps/myapp/
#==========================================================
# Server properties
#==========================================================
app.server.address=127.0.0.70
app.server.host=dev.myapp.com
app.server.port=8080
#==========================================================
# Backend properties
#==========================================================
app.backend.address=127.0.0.70
app.backend.host=dev.myapp.com
app.backend.port=8081
app.backend.maximum.threads=5
#==========================================================
# Database properties
#==========================================================
app.database.address=127.0.0.70
app.database.host=database.myapp.com
app.database.port=5432
app.database.user=dev-user-name
app.database.pass=dev-password
app.database.main=dev-database
#==========================================================
# Storage properties
#==========================================================
app.storage.address=127.0.0.70
app.storage.host=storage.myapp.com
app.storage.port=4569
app.storage.endpoint=http://storage.myapp.com:4569
app.storage.access-key=dev-access-key
app.storage.secret-key=dev-secret-key
app.storage.region=us-east-1
app.storage.bucket=dev-bucket
Usage:
./setup.sh dev
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…