From 24f449244ae55b21c3dc420d8d4e52b89a41e24f Mon Sep 17 00:00:00 2001 From: Tomer Nosrati Date: Sat, 22 Aug 2020 03:21:49 +0300 Subject: [PATCH] Added make rename command to automatically rename the service accross the code --- Makefile | 3 +++ README.md | 6 ++++-- rename_service.sh | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 rename_service.sh diff --git a/Makefile b/Makefile index d9da8de..58d328f 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ install: ## setup the flask Docker container, install the requirements... clean: ## Clean __pycache__ files py3clean . +rename: ## Renames the micro-service (see git diff to review the changes afterwards), e.g make rename FROM=service_name TO=new_name + ./rename_service.sh $(FROM) $(TO) + ## Start the Dockerized flask application in local environment gunicorn: ## gunicorn and hot-reload diff --git a/README.md b/README.md index fba7feb..ad66576 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ src -> Root folder for the source code ``` This gives you a basic file structure with a working mechanism for running an app in a microservice. -From here on you need to rename some of the places with your own microservice name and add your own APIs and that's it, everything else is already set. +From here on you need to rename the microservice and add your own APIs and that's it, everything else is already set. + +Oh and by the way, renaming is also automatic using `make rename FROM=service_name TO=new_name` (see `make help` for more info). Feel free to remove the example [APIs](./src/openapi/openapi.yaml#L10) and change them with your own. @@ -43,7 +45,7 @@ The package uses a [Makefile](./Makefile) for easy CLI but there are also the co 1) So first clone this repository. 2) Run `git submodule update --init --recursive` inside the repository (to get the sdk's code). -3) Run `make install` in the root repository directory. +3) Run `make install` in the root repository directory (or `make rename FROM=service_name TO=new_name` before to rename the microservice). 4) Try it out using one of the available running options:s * Run `run_locally.sh` to run locally as a script (with auto-create a .venv and use that) - does not requires `make install` prior to running this way. diff --git a/rename_service.sh b/rename_service.sh new file mode 100755 index 0000000..93690a1 --- /dev/null +++ b/rename_service.sh @@ -0,0 +1,15 @@ +#!/bin/bash + + +find_replace_in_file() { + FROM="$1" + TO="$2" + FILE_NAME=$3 + FILE_CONTENT=$(<./$FILE_NAME) + echo "$FILE_CONTENT" | sed "s/$FROM/$TO/g" > $FILE_NAME +} + +find_replace_in_file $1 $2 ".env" +find_replace_in_file $1 $2 "Makefile" +find_replace_in_file $1 $2 "docker-compose.yml" +find_replace_in_file "PyBackendBoilerplate Microservice Boilerplate" $2 "src/openapi/openapi.yaml" \ No newline at end of file