Skip to content

Commit

Permalink
adding hostname dependency (#122)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhinav Chobey <[email protected]>
  • Loading branch information
abhinavchobey and Abhinav Chobey authored Sep 20, 2023
1 parent 5dfc773 commit 3cde65b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
5 changes: 3 additions & 2 deletions docker-compose-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ services:
dockerfile: ./server/Dockerfile
restart: always
environment:
MYIP: ${IP}
MYIP: ${IP:-127.0.0.1}
HOSTNAME: ${hostname:-None}
ports:
- "8080:80"
expose:
- 8000

ui:
image: ui:latest
container_name: ui-server
Expand All @@ -27,6 +27,7 @@ services:
restart: always
environment:
REACT_APP_MY_IP: ${IP}
REACT_APP_MY_HOSTNAME: ${hostname}
ports:
- "3000:3000"
expose:
Expand Down
31 changes: 17 additions & 14 deletions docs/cmf_server/cmf-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,24 @@ There are two ways to start cmf server -
....
```
4. Execute following command to start both the containers. `IP` variable is the IP address of the machine on which you are executing the following command.
```
IP=200.200.200.200 docker compose -f docker-compose-server.yml up
```
> Replace `docker compose` with `docker-compose` for older versions.
> Also you can adjust `$IP` in `docker-compose-server.yml` to reflect the server IP and run the `docker compose` command without specifying
IP=200.200.200.200.
```
.......
environment:
REACT_APP_MY_IP: ${IP}
......
```
4. Execute following command to start both the containers. `IP` variable is the IP address and `hostname` is host name of the machine on which you are executing the following command.
You can use either way.
```
IP=200.200.200.200 docker compose -f docker-compose-server.yml up
OR
hostname=host_name docker compose -f docker-compose-server.yml up
```
> Replace `docker compose` with `docker-compose` for older versions.
> Also you can adjust `$IP` in `docker-compose-server.yml` to reflect the server IP and run the `docker compose` command without specifying
IP=200.200.200.200.
```
.......
environment:
REACT_APP_MY_IP: ${IP}
......
```
5. Stop the containers.
```
docker compose -f docker-compose-server.yml stop
Expand Down
6 changes: 5 additions & 1 deletion server/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
templates = Jinja2Templates(directory=str(BASE_PATH/"template"))
app.mount("/cmf-server/data/static", StaticFiles(directory="/cmf-server/data/static"), name="static")
server_store_path = "/cmf-server/data/mlmd"
if os.environ.get("MYIP") != "127.0.0.1":
url="http://"+os.environ.get('MYIP')+":3000"
else:
url="http://"+os.environ.get('HOSTNAME')+":3000"

origins = [
"http://localhost:3000",
"localhost:3000",
"http://"+os.environ.get('MYIP')+":3000"
url
]

app.add_middleware(
Expand Down
10 changes: 8 additions & 2 deletions ui/src/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import runtimeEnv from "@mars/heroku-js-runtime-env";

let url="";
const env = runtimeEnv();

if (process.env.REACT_APP_MY_IP !== "127.0.0.1") {
url="http://"+process.env.REACT_APP_MY_IP+":8080";
}
else {
url="http://"+process.env.REACT_APP_MY_HOSTNAME+":8080";
}
const config = {
apiBasePath: env.REACT_APP_API_BASE_PATH || "http://"+process.env.REACT_APP_MY_IP+":8080",
apiBasePath: env.REACT_APP_API_BASE_PATH || url,
reactAppMode: process.env.REACT_APP_MODE || "dev",
};

Expand Down

0 comments on commit 3cde65b

Please sign in to comment.