Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit f8ea520

Browse files
author
Sladyn
authored
Multiple environments support (#88)
* Fixed proxy according to docker container * Trying out multiple environments * Change environment variables * Add documentation for default values * Added readme instructions * Fix Dockerfile * Added readme instructions * Commit suggestions * Trigger Build * Invoked correct function call * Fixed url 404 error * Add environment variable to docker infra
1 parent ec4c1cf commit f8ea520

File tree

13 files changed

+220
-10
lines changed

13 files changed

+220
-10
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ COPY pom.xml /build/
1010
# Copies the src directory into the build directory in the image.
1111
COPY src /build/src/
1212

13+
# Copies the config directory into the build directory in the image.
1314
COPY config /build/config/
1415

1516
# Set Workdir

Dockerfile.infra

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ WORKDIR /build
1515
COPY frontend/package* /build/
1616
RUN npm install
1717
COPY frontend/ /build/
18+
ENV REACT_APP_API_URL /
1819
RUN npm run build
1920

2021
FROM openjdk:8-jre-alpine

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,102 @@ Run the containers:
3333
docker-compose up
3434
```
3535

36+
### Run without docker
37+
38+
#### Prerequisites
39+
40+
a) [maven](https://maven.apache.org/install.html)
41+
42+
b) [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
43+
44+
You can run the backend spring boot server from the root directory using:
45+
```
46+
mvn spring-boot:run
47+
```
48+
49+
You can run the front end using the following:
50+
```
51+
cd frontend/
52+
npm install
53+
npm start
54+
```
55+
56+
## Environment Variable configuration
57+
58+
We currently have two environment variables
59+
60+
a) REACT_APP_API_URL: This variable points to the base API_URL to which the service makes calls to.If you decide to run the backend on another port this variable should be set. The default value is set to `http://localhost:8080`
61+
62+
b) REACT_APP_GITHUB_COMMUNITY_URL: This variable points to the URL at which you would like to store your community configurations on github. It needs to be in the format of:
63+
`https://api.github.com/repos/{repo-owner}/{repo-name}/contents/{path-to-folder}`
64+
65+
The default configuration is:
66+
67+
`https://api.github.com/repos/sladyn98/custom-distribution-service-community-configurations/contents/configurations`
68+
69+
70+
## How to change ports and run without Docker
71+
72+
In order to change the ports on which spring-boot runs you need to execute the following command. For example if you need to run the spring boot server on port 8081 these are the commands you would want to run.
73+
74+
* For UNIX
75+
```
76+
SERVER_PORT=8081 mvn spring-boot:run
77+
```
78+
79+
Once you have started the spring boot server the next thing is to configure the front-end environment file so that the react server knows where to find the backend server.
80+
81+
* The file that needs to be changed is the `.env` inside the frontend folder.
82+
83+
* Inside this file this line needs to be changed `REACT_APP_API_URL=INSERT_NEW_PORT_HERE`
84+
for eg: If the backend is running on port 8081
85+
```
86+
REACT_APP_API_URL=http://localhost:8081
87+
```
88+
89+
## How to change ports and run with Docker
90+
91+
In order to change the docker port the following file need to changed
92+
93+
* Inside the docker-compose.yml the line:
94+
95+
```
96+
ports:
97+
- "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
98+
```
99+
100+
needs to be changed to the port you want to run it at.
101+
102+
Eg: The port on the left indicates the port that needs to be exposed on the host machine, so it needs to be changed according to our requirement. So in order to run on port 8081 we need to make the following change.
103+
```
104+
ports:
105+
- "8081:8080"
106+
```
107+
108+
Once you have started the spring boot server the next thing is to configure the front-end environment file so that the react server knows where to find the backend server.
109+
110+
* The file that needs to be changed is the `.env.docker` inside the frontend folder.
111+
112+
* Inside this file this line needs to be changed `REACT_APP_API_URL=INSERT_NEW_PORT_HERE`
113+
for eg: If the backend is running on port 8081
114+
```
115+
REACT_APP_API_URL=http://localhost:8081
116+
```
117+
118+
## How to change Community-Configurations URL
119+
120+
### For Docker Environment
121+
122+
* The file that needs to be changed is the `.env.docker` inside the frontend folder.
123+
124+
* Inside this file this line needs to be changed `REACT_APP_GITHUB_COMMUNITY_URL=ENTER_URL_HERE`
125+
126+
### For Non-Docker Environment
127+
128+
* The file that needs to be changed is the `.env` inside the frontend folder.
129+
130+
* Inside this file this line needs to be changed `REACT_APP_GITHUB_COMMUNITY_URL=ENTER_URL_HERE`
131+
36132
## Documentation
37133

38134
You can find more documentation about how to use the service here:

frontend/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
REACT_APP_GITHUB_COMMUNITY_URL=https://api.github.com/repos/sladyn98/custom-distribution-service-community-configurations/contents/configurations
2+
REACT_APP_API_URL=http://localhost:8080

frontend/.env.docker

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_API_URL=http://localhost:8080
2+
REACT_APP_GITHUB_COMMUNITY_URL=https://api.github.com/repos/sladyn98/custom-distribution-service-community-configurations/contents/configurations

frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ COPY . .
1919
EXPOSE 3000
2020

2121
# Finally runs the application
22-
CMD [ "npm", "start" ]
22+
CMD [ "npm", "run", "start:docker" ]

frontend/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@testing-library/user-event": "^7.1.2",
99
"axios": "^0.19.2",
1010
"bootstrap": "^4.5.0",
11+
"env-cmd": "^10.1.0",
1112
"node-sass": "^4.14.1",
1213
"prismjs": "^1.20.0",
1314
"react": "^16.13.1",
@@ -20,13 +21,13 @@
2021
},
2122
"scripts": {
2223
"start": "react-scripts start",
24+
"start:docker": "env-cmd -f .env.docker react-scripts start",
2325
"build": "react-scripts build",
2426
"test": "react-scripts test",
2527
"eject": "react-scripts eject",
2628
"lint": "eslint --ext .ts,.js --ignore-path .gitignore .",
2729
"lint:fix": "eslint --fix --ext .ts,.js --ignore-path .gitignore ."
2830
},
29-
"proxy": "http://app-server:8080",
3031
"eslintConfig": {
3132
"extends": "react-app"
3233
},

frontend/src/components/CommunityConfiguration/communityConfigLayout.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ class communityConfigLayout extends React.Component {
1414
}
1515

1616
async componentDidMount() {
17-
const response = await fetch(process.env.REACT_APP_GITHUB_COMMUNITY_URL);
17+
18+
// Use the default GITHUB_API_URL
19+
let GITHUB_API_URL = "https://api.github.com/repos/sladyn98/custom-distribution-service-community-configurations/contents/configurations"
20+
21+
// If environment variable has been set it will override the default
22+
if (process.env.REACT_APP_GITHUB_COMMUNITY_URL) {
23+
console.log("Environment variable has been set")
24+
GITHUB_API_URL = process.env.REACT_APP_GITHUB_COMMUNITY_URL
25+
}
26+
27+
const response = await fetch(GITHUB_API_URL);
1828
const body = await response.json();
1929
this.setState({data: body})
2030
}

frontend/src/components/CommunityConfiguration/configurationCard.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@ class configurationCard extends React.Component {
1515
super(props)
1616
}
1717

18-
1918
async viewDetails(configName) {
2019
console.log(configName)
21-
const response = await fetch('https://raw.githubusercontent.com/sladyn98/custom-distribution-service-community-configurations/master/configurations/' + configName);
20+
let urlSplit = this.getCommunityConfigURL().split('/')
21+
const response = await fetch('https://raw.githubusercontent.com/' + urlSplit[4] + '/' + urlSplit[5] + '/master/configurations/' + configName);
2222
const body = await response.text();
2323
localStorage.setItem("packageConfigYAML", body)
2424
// Once the fetch call is achieved naviagte to the editor page.
2525
window.location.assign("/generatePackage")
2626
}
2727

28+
getCommunityConfigURL() {
29+
// Use the default GITHUB_API_URL
30+
let GITHUB_API_URL = "https://api.github.com/repos/sladyn98/custom-distribution-service-community-configurations/contents/configurations"
31+
// If environment variable has been set it will override the default
32+
if (process.env.REACT_APP_GITHUB_COMMUNITY_URL) {
33+
console.log("Environment variable has been set")
34+
GITHUB_API_URL = process.env.REACT_APP_GITHUB_COMMUNITY_URL
35+
}
36+
return GITHUB_API_URL
37+
}
38+
2839
render() {
2940
return(
3041
<div>

0 commit comments

Comments
 (0)