From 5c68a885996dae7caf0b74d75f9e76119418b779 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Thu, 30 Nov 2017 03:50:24 +0200 Subject: [PATCH] Fn-prefix everything (#545) * Fn-prefix everything Closes: #492 * Global replacement * missed one fn_ --- Makefile | 4 ++-- README.md | 2 +- api/server/server.go | 16 ++++++++-------- api_test.sh | 8 ++++---- build.ps1 | 2 +- docs/definitions.md | 4 ++-- docs/operating/databases/README.md | 6 +++--- docs/operating/databases/mysql.md | 2 +- docs/operating/databases/postgres.md | 2 +- docs/operating/kubernetes/README.md | 11 ++++++----- docs/operating/kubernetes/fn-service.yaml | 18 +++++++++--------- docs/operating/logs/README.md | 14 +++++++------- docs/operating/mqs/README.md | 4 ++-- docs/operating/options.md | 11 ++++++----- docs/operating/ui.md | 2 +- fnlb/README.md | 2 +- test/fn-api-tests/README.md | 4 ++-- test/fn-api-tests/utils.go | 7 +++++-- 18 files changed, 62 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index dd96a0b8f..631bc6aa8 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ docker-build: docker build --build-arg HTTPS_PROXY --build-arg HTTP_PROXY -t fnproject/fnserver:latest . docker-run: docker-build - docker run --rm --privileged -it -e NO_PROXY -e HTTP_PROXY -e LOG_LEVEL=debug -e "DB_URL=sqlite3:///app/data/fn.db" -v ${CURDIR}/data:/app/data -p 8080:8080 fnproject/fnserver + docker run --rm --privileged -it -e NO_PROXY -e HTTP_PROXY -e FN_LOG_LEVEL=debug -e "FN_DB_URL=sqlite3:///app/data/fn.db" -v ${CURDIR}/data:/app/data -p 8080:8080 fnproject/fnserver docker-test-run-with-sqlite3: ./api_test.sh sqlite3 4 @@ -51,7 +51,7 @@ docker-test-run-with-postgres: ./api_test.sh postgres 4 docker-test: - docker run -ti --privileged --rm -e LOG_LEVEL=debug \ + docker run -ti --privileged --rm -e FN_LOG_LEVEL=debug \ -v /var/run/docker.sock:/var/run/docker.sock \ -v ${CURDIR}:/go/src/github.com/fnproject/fn \ -w /go/src/github.com/fnproject/fn \ diff --git a/README.md b/README.md index 894722b2d..848a8d21b 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ you can update your code and run `fn deploy myapp` again. We also have an open source graphical user interface for Fn. It's very easy to use, simply run the command below: ```sh -docker run --rm -it --link functions:api -p 4000:4000 -e "API_URL=http://api:8080" fnproject/ui +docker run --rm -it --link functions:api -p 4000:4000 -e "FN_API_URL=http://api:8080" fnproject/ui ``` For more information, see: [https://github.com/fnproject/ui](https://github.com/fnproject/ui) diff --git a/api/server/server.go b/api/server/server.go index 605683ab3..9694ea051 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -37,13 +37,13 @@ var ( ) const ( - EnvLogLevel = "LOG_LEVEL" - EnvMQURL = "MQ_URL" - EnvDBURL = "DB_URL" - EnvLOGDBURL = "LOGSTORE_URL" - EnvPort = "PORT" // be careful, Gin expects this variable to be "port" - EnvAPICORS = "API_CORS" - EnvZipkinURL = "ZIPKIN_URL" + EnvLogLevel = "FN_LOG_LEVEL" + EnvMQURL = "FN_MQ_URL" + EnvDBURL = "FN_DB_URL" + EnvLOGDBURL = "FN_LOGSTORE_URL" + EnvPort = "FN_PORT" // be careful, Gin expects this variable to be "port" + EnvAPICORS = "FN_API_CORS" + EnvZipkinURL = "FN_ZIPKIN_URL" // Defaults DefaultLogLevel = "info" @@ -298,7 +298,7 @@ func (s *Server) Start(ctx context.Context) { func (s *Server) startGears(ctx context.Context, cancel context.CancelFunc) { // By default it serves on :8080 unless a - // PORT environment variable was defined. + // FN_PORT environment variable was defined. listen := fmt.Sprintf(":%d", getEnvInt(EnvPort, DefaultPort)) const runHeader = ` diff --git a/api_test.sh b/api_test.sh index 574cab8af..7668234cc 100755 --- a/api_test.sh +++ b/api_test.sh @@ -23,7 +23,7 @@ case "$1" in "sqlite3" ) rm -fr /tmp/fn_integration_tests.db touch /tmp/fn_integration_tests.db - DB_URL="sqlite3:///tmp/fn_integration_tests.db" + FN_DB_URL="sqlite3:///tmp/fn_integration_tests.db" ;; "mysql" ) @@ -33,7 +33,7 @@ case "$1" in sleep 15 MYSQL_HOST=`host ${DB_CONTAINER}` MYSQL_PORT=3306 - DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs" + FN_DB_URL="mysql://root:root@tcp(${MYSQL_HOST}:${MYSQL_PORT})/funcs" ;; @@ -44,9 +44,9 @@ case "$1" in sleep 15 POSTGRES_HOST=`host ${DB_CONTAINER}` POSTGRES_PORT=5432 - DB_URL="postgres://postgres:root@${POSTGRES_HOST}:${POSTGRES_PORT}/funcs?sslmode=disable" + FN_DB_URL="postgres://postgres:root@${POSTGRES_HOST}:${POSTGRES_PORT}/funcs?sslmode=disable" ;; esac -cd test/fn-api-tests && API_URL="http://localhost:8080" DB_URL=${DB_URL} go test -v -parallel ${2:-1} ./...; cd ../../ +cd test/fn-api-tests && FN_API_URL="http://localhost:8080" FN_DB_URL=${FN_DB_URL} go test -v -parallel ${2:-1} ./...; cd ../../ diff --git a/build.ps1 b/build.ps1 index ffe0167f3..e9733f125 100644 --- a/build.ps1 +++ b/build.ps1 @@ -25,7 +25,7 @@ function build () { docker build -t fnproject/fnserver:latest . function run () { - docker run --rm --name functions -it -v /var/run/docker.sock:/var/run/docker.sock -e LOG_LEVEL=debug -e "DB_URL=sqlite3:///app/data/fn.db" -v $PWD/data:/app/data -p 8080:8080 fnproject/fnserver + docker run --rm --name functions -it -v /var/run/docker.sock:/var/run/docker.sock -e FN_LOG_LEVEL=debug -e "FN_DB_URL=sqlite3:///app/data/fn.db" -v $PWD/data:/app/data -p 8080:8080 fnproject/fnserver } switch ($cmd) diff --git a/docs/definitions.md b/docs/definitions.md index 6718e4c3d..ed339a85a 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -165,7 +165,7 @@ that can be used to track call status using following command: ```sh - curl -v -X GET ${API_URL}/v1/calls/f5621e8b-725a-4ba9-8323-b8cdc02ce37 + curl -v -X GET ${FN_API_URL}/v1/calls/f5621e8b-725a-4ba9-8323-b8cdc02ce37 ``` @@ -213,7 +213,7 @@ Corresponding HTTP header is `Fn_call_id`. In order get list of per-route calls please use following command: ```sh -curl -X GET ${API_URL}/v1/app/{app}/calls/{route} +curl -X GET ${FN_API_URL}/v1/app/{app}/calls/{route} ``` Server will replay with following JSON response: diff --git a/docs/operating/databases/README.md b/docs/operating/databases/README.md index 809dd9c5c..63e546aec 100644 --- a/docs/operating/databases/README.md +++ b/docs/operating/databases/README.md @@ -1,10 +1,10 @@ # Databases -We currently support the following databases and they are passed in via the `DB_URL` environment variable. For example: +We currently support the following databases and they are passed in via the `FN_DB_URL` environment variable. For example: ```sh -docker run -e "DB_URL=postgres://user:pass@localhost:6212/mydb" ... +docker run -e "FN_DB_URL=postgres://user:pass@localhost:6212/mydb" ... ``` ## sqlite3 (default) @@ -12,7 +12,7 @@ docker run -e "DB_URL=postgres://user:pass@localhost:6212/mydb" ... URL: `sqlite3:///functions/data/functions.db` SQLite3 is an embedded database which stores to disk. If you want to use this, be sure you don't lose the data directory by mounting -the directory on your host. eg: `docker run -v $PWD/data:/functions/data -e DB_URL=sqlite3:///functions/data/fn.db ...` +the directory on your host. eg: `docker run -v $PWD/data:/functions/data -e FN_DB_URL=sqlite3:///functions/data/fn.db ...` ## [PostgreSQL](http://www.postgresql.org/) diff --git a/docs/operating/databases/mysql.md b/docs/operating/databases/mysql.md index 3c56e5b3e..adadecdf3 100644 --- a/docs/operating/databases/mysql.md +++ b/docs/operating/databases/mysql.md @@ -15,6 +15,6 @@ For more configuration options, see [docker mysql docs](https://hub.docker.com/_ ``` docker run --rm --privileged --link "func-mysql:mysql" \ - -e "DB_URL=mysql://func:funcpass@tcp(mysql:3306)/funcs" \ + -e "FN_DB_URL=mysql://func:funcpass@tcp(mysql:3306)/funcs" \ -it -p 8080:8080 fnproject/fn ``` diff --git a/docs/operating/databases/postgres.md b/docs/operating/databases/postgres.md index 5c970f849..a1f6074fd 100644 --- a/docs/operating/databases/postgres.md +++ b/docs/operating/databases/postgres.md @@ -29,6 +29,6 @@ docker run -it --rm --link func-postgres:postgres postgres \ ```sh docker run --rm --privileged --link "func-postgres:postgres" \ - -e "DB_URL=postgres://postgres:funcpass@postgres/funcs?sslmode=disable" \ + -e "FN_DB_URL=postgres://postgres:funcpass@postgres/funcs?sslmode=disable" \ -it -p 8080:8080 fnproject/fnserver ``` diff --git a/docs/operating/kubernetes/README.md b/docs/operating/kubernetes/README.md index 9aa511ce7..9e5b03d9c 100644 --- a/docs/operating/kubernetes/README.md +++ b/docs/operating/kubernetes/README.md @@ -31,31 +31,32 @@ Note that `fn-service` is initially pending on allocating an external IP. The `k If you are using a Kubernetes setup that can expose a public load balancer, run: ```bash -$ export API_URL=http://$(kubectl -n fn get service/fn-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}:{.spec.ports[?(@.name=="fn-service")].port}') +$ export FN_API_URL=http://$(kubectl -n fn get service/fn-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}:{.spec.ports[?(@.name=="fn-service")].port}') ``` If you are using a Kubernetes setup like minikube, run ```bash -$ export API_URL=$(minikube -n fn service fn-service --url) +$ export FN_API_URL=$(minikube -n fn service fn-service --url) ``` Now, test by creating a function via curl: ```bash -$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' $API_URL/v1/apps +$ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' $FN_API_URL/v1/apps {"message":"App successfully created","app":{"name":"myapp","config":null}} -$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"fnproject/hello" } }' $API_URL/v1/apps/myapp/routes +$ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"fnproject/hello" } }' $FN_API_URL/v1/apps/myapp/routes {"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"fnproject/hello","memory":128,"headers":{},"type":"sync","format":"default","timeout":30,"idle_timeout":30,"config":{}}} -$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' $API_URL/r/myapp/hello-sync +$ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' $FN_API_URL/r/myapp/hello-sync Hello Johnny! ``` You can also use the [Fn CLI](https://github.com/fnproject/cli): ```bash +$ export FN_API_URL=http://192.168.99.100:30966 $ fn apps list myapp diff --git a/docs/operating/kubernetes/fn-service.yaml b/docs/operating/kubernetes/fn-service.yaml index e49d7a376..d47dd3ba6 100644 --- a/docs/operating/kubernetes/fn-service.yaml +++ b/docs/operating/kubernetes/fn-service.yaml @@ -9,9 +9,9 @@ metadata: name: fn-service-config namespace: fn data: - MQ_URL: redis://fn-redis-master.fn - DB_URL: mysql://root:fnsecretpassword@tcp(fn-mysql-master.fn:3306)/fn - API_URL: http://fn-service.fn:8080 + FN_MQ_URL: redis://fn-redis-master.fn + FN_DB_URL: mysql://root:fnsecretpassword@tcp(fn-mysql-master.fn:3306)/fn + FN_API_URL: http://fn-service.fn:8080 --- apiVersion: v1 kind: Service @@ -56,16 +56,16 @@ spec: ports: - containerPort: 8080 env: - - name: MQ_URL + - name: FN_MQ_URL valueFrom: configMapKeyRef: name: fn-service-config - key: MQ_URL - - name: DB_URL + key: FN_MQ_URL + - name: FN_DB_URL valueFrom: configMapKeyRef: name: fn-service-config - key: DB_URL + key: FN_DB_URL --- apiVersion: v1 kind: Service @@ -108,11 +108,11 @@ spec: env: - name: PORT value: "80" - - name: API_URL + - name: FN_API_URL valueFrom: configMapKeyRef: name: fn-service-config - key: API_URL + key: FN_API_URL --- apiVersion: v1 kind: Service diff --git a/docs/operating/logs/README.md b/docs/operating/logs/README.md index 88ccdf0d8..6fa217c55 100644 --- a/docs/operating/logs/README.md +++ b/docs/operating/logs/README.md @@ -1,38 +1,38 @@ # Function logs We currently support the following function logs stores and they are passed in -via the `LOGSTORE_URL` environment variable. For example: +via the `FN_LOGSTORE_URL` environment variable. For example: ```sh -docker run -e "LOGSTORE_URL=sqlite3:///functions/logs/fn.db" ... +docker run -e "FN_LOGSTORE_URL=sqlite3:///functions/logs/fn.db" ... ``` -settings `LOGSTORE_URL` to `DB_URL` will put logs in the same database as +settings `FN_LOGSTORE_URL` to `FN_DB_URL` will put logs in the same database as other data, this is not recommended for production. ## sqlite3 / postgres / mysql (default) -NOTE: if you leave LOGSTORE_URL empty, it will default to DB_URL. this is +NOTE: if you leave FN_LOGSTORE_URL empty, it will default to FN_DB_URL. this is recommended if you are not using a separate place for your logs for connection pooling reasons. example URL: `sqlite3:///functions/logs/fn.db` sqlite3 is an embedded database which stores to disk. If you want to use this, be sure you don't lose the data directory by mounting -the directory on your host. eg: `docker run -v $PWD/data:/functions/data -e LOGSTORE_URL=sqlite3:///functions/data/fn.db ...` +the directory on your host. eg: `docker run -v $PWD/data:/functions/data -e FN_LOGSTORE_URL=sqlite3:///functions/data/fn.db ...` sqlite3 isn't recommended for production environments ## minio / s3 If you have an s3-compatible object store, we are using only `put_object` and -`get_object` and you may point `LOGSTORE_URL` at that api's url appropriately. +`get_object` and you may point `FN_LOGSTORE_URL` at that api's url appropriately. If you don't have one of those running, you may run minio, an example is below: ```sh $ docker run -d -p 9000:9000 --name minio -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=password" minio/minio server /data -$ docker run --privileged --link minio -e "LOGSTORE_URL=s3://admin:password@minio:9000/us-east-1/fnlogs" fnproject/functions:latest +$ docker run --privileged --link minio -e "FN_LOGSTORE_URL=s3://admin:password@minio:9000/us-east-1/fnlogs" fnproject/fnserver:latest ``` you may include any other necessary args for fnproject, this example only diff --git a/docs/operating/mqs/README.md b/docs/operating/mqs/README.md index 2bad892f8..abf28972b 100644 --- a/docs/operating/mqs/README.md +++ b/docs/operating/mqs/README.md @@ -2,10 +2,10 @@ A message queue is used to coordinate asynchronous function calls that run through Fn. -We currently support the following message queues and they are passed in via the `MQ_URL` environment variable. For example: +We currently support the following message queues and they are passed in via the `FN_MQ_URL` environment variable. For example: ```sh -docker run -e "MQ_URL=redis://localhost:6379/" ... +docker run -e "FN_MQ_URL=redis://localhost:6379/" ... ``` ## [Bolt](https://github.com/boltdb/bolt) (default) diff --git a/docs/operating/options.md b/docs/operating/options.md index b52de66c8..5ddd1c307 100644 --- a/docs/operating/options.md +++ b/docs/operating/options.md @@ -21,11 +21,12 @@ docker run -e VAR_NAME=VALUE ... | Env Variables | Description | Default values | | --------------|-------------|----------------| -| `DB_URL` | The database URL to use in URL format. See [Databases](databases/README.md) for more information. | sqlite3:///app/data/fn.db | -| `MQ_URL` | The message queue to use in URL format. See [Message Queues](mqs/README.md) for more information. | bolt:///app/data/worker_mq.db | -| `PORT` | Sets the port to run on | 8080 | -| `LOG_LEVEL` | Set to DEBUG to enable debugging | INFO | -| `DOCKER_HOST` | Docker remote API URL | /var/run/docker.sock:/var/run/docker.sock | +| `FN_DB_URL` | The database URL to use in URL format. See [Databases](databases/README.md) for more information. | sqlite3:///app/data/fn.db | +| `FN_MQ_URL` | The message queue to use in URL format. See [Message Queues](mqs/README.md) for more information. | bolt:///app/data/worker_mq.db | +| `FN_API_URL` | The primary Fn API URL to that this instance will talk to. In a production environment, this would be your load balancer URL. | N/A | +| `FN_PORT `| Sets the port to run on | 8080 | +| `FN_LOG_LEVEL` | Set to DEBUG to enable debugging | INFO | +| `DOCKER_HOST` | Docker remote API URL | /var/run/docker.sock | | `DOCKER_API_VERSION` | Docker remote API version | 1.24 | | `DOCKER_TLS_VERIFY` | Set this option to enable/disable Docker remote API over TLS/SSL. | 0 | | `DOCKER_CERT_PATH` | Set this option to specify where CA cert placeholder | ~/.docker/cert.pem | diff --git a/docs/operating/ui.md b/docs/operating/ui.md index 05f33dc4e..f8a46f1f2 100644 --- a/docs/operating/ui.md +++ b/docs/operating/ui.md @@ -3,7 +3,7 @@ ### Run Functions UI ```sh -docker run --rm -it --link functions:api -p 4000:4000 -e "API_URL=http://api:8080" fnproject/ui +docker run --rm -it --link functions:api -p 4000:4000 -e "FN_API_URL=http://api:8080" fnproject/ui ``` For more information, see: https://github.com/fnproject/ui diff --git a/fnlb/README.md b/fnlb/README.md index 3299418c6..c8e5aec8e 100644 --- a/fnlb/README.md +++ b/fnlb/README.md @@ -41,7 +41,7 @@ docker run -d --name fnlb --link fn-8080 -p 8081:8081 fnproject/fnlb:latest --no To make functions requests against the lb with the cli: ```sh -API_URL=http:// fn call my/function +FN_API_URL=http:// fn call my/function ``` To add a functions node later: diff --git a/test/fn-api-tests/README.md b/test/fn-api-tests/README.md index a541554f6..1fb512062 100644 --- a/test/fn-api-tests/README.md +++ b/test/fn-api-tests/README.md @@ -7,13 +7,13 @@ Test dependencies ```bash DOCKER_HOST - for building images -API_URL - Fn API endpoint +FN_API_URL - Fn API endpoint ``` How to run tests? ----------------- ```bash -export API_URL=http://localhost:8080 +export FN_API_URL=http://localhost:8080 go test -v ./... ``` diff --git a/test/fn-api-tests/utils.go b/test/fn-api-tests/utils.go index 8d72c9e97..f234a91ee 100644 --- a/test/fn-api-tests/utils.go +++ b/test/fn-api-tests/utils.go @@ -24,7 +24,10 @@ import ( const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" func Host() string { - apiURL := "http://localhost:8080" + apiURL := os.Getenv("FN_API_URL") + if apiURL == "" { + apiURL = "http://localhost:8080" + } u, err := url.Parse(apiURL) if err != nil { @@ -59,7 +62,7 @@ func getServerWithCancel() (*server.Server, context.CancelFunc) { common.SetLogLevel("fatal") timeString := time.Now().Format("2006_01_02_15_04_05") - dbURL := os.Getenv("DB_URL") + dbURL := os.Getenv(server.EnvDBURL) tmpDir := os.TempDir() tmpMq := fmt.Sprintf("%s/fn_integration_test_%s_worker_mq.db", tmpDir, timeString) tmpDb := fmt.Sprintf("%s/fn_integration_test_%s_fn.db", tmpDir, timeString)