Skip to content

Commit

Permalink
Added make rename command to automatically rename the service accross…
Browse files Browse the repository at this point in the history
… the code
  • Loading branch information
Nusnus committed Aug 22, 2020
1 parent 4942f82 commit 24f4492
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions rename_service.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 24f4492

Please sign in to comment.