diff --git a/commands b/commands new file mode 100644 index 0000000000000000000000000000000000000000..e024479be950029ba39e3baa15c3c25189b0ad30 --- /dev/null +++ b/commands @@ -0,0 +1,20 @@ +⯠docker build -t gcr.io/best-listens-385813/postgres:11.5 . +⯠docker build -t gcr.io/best-listens-385813/best-listens-music-microservice:latest . +⯠docker build -t gcr.io/best-listens-385813/best-listens-feed-microservice:latest . +⯠docker build -t gcr.io/best-listens-385813/best-listens-user-microservice:latest . +⯠docker build -t gcr.io/best-listens-385813/best-listens-front-end:latest . + +⯠docker push gcr.io/best-listens-385813/postgres:11.5 +⯠docker push gcr.io/best-listens-385813/best-listens-music-microservice:latest +⯠docker push gcr.io/best-listens-385813/best-listens-feed-microservice:latest +⯠docker push gcr.io/best-listens-385813/best-listens-user-microservice:latest +⯠docker push gcr.io/best-listens-385813/best-listens-front-end:latest + +gcloud run deploy best-listens-user-microservice --image gcr.io/best-listens-385813/best-listens-user-microservice:latest --platform managed --allow-unauthenticated +gcloud run deploy best-listens-feed-microservice --image gcr.io/best-listens-385813/best-listens-feed-microservice:latest --platform managed --allow-unauthenticated +gcloud run deploy best-listens-music-microservice --image gcr.io/best-listens-385813/best-listens-music-microservice:latest --platform managed --allow-unauthenticated +gcloud run deploy best-listens-front-end --image gcr.io/best-listens-385813/best-listens-front-end:latest --platform managed --allow-unauthenticated + +gcloud run deploy best-listens-postgres --image postgres:11.5 --set-env-vars POSTGRES_PASSWORD=password,POSTGRES_DB=best-listens --port 5432 --platform managed --allow-unauthenticated + +⯠docker build --platform linux/amd64 -t gcr.io/best-listens-385813/best-listens-music-microservice:latest . \ No newline at end of file diff --git a/docker-compose copy.yaml b/docker-compose copy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8f19114cbb112d59b0359ac35e360d66ea3b1477 --- /dev/null +++ b/docker-compose copy.yaml @@ -0,0 +1,87 @@ +# recommendation is to remove all ports as we do not need to +# expose them to the outside world. just need to expose the +# front-end. add networks here so the containers can communicate +# within themselves using this docker network. + +# networks: +# app_net: + +version: "3.8" +services: + + #networks: + # - app_net + music-microservice: + build: + context: musicMicroservice + dockerfile: Dockerfile + ports: + - "${PORT}:5050" # changed to dynamic port + container_name: musicMicroservice_c + restart: unless-stopped + volumes: + - ./musicMicroservice:/app + depends_on: + - postgres + #networks: + # - app_net + + user-microservice: + build: + context: userMicroservice + dockerfile: Dockerfile + restart: unless-stopped + container_name: userMicroservice_c + ports: + - "${PORT}:3002" # changed to dynamic port + volumes: + - ./userMicroservice:/app + depends_on: + - postgres + #networks: + # - app_net + + feed-microservice: + build: + context: feedMicroservice + dockerfile: Dockerfile + ports: + - "${PORT}:5051" # changed to dynamic port + container_name: feedMicroservice_c + restart: unless-stopped + volumes: + - ./feedMicroservice:/app + depends_on: + - user-microservice + #networks: + # - app_net + + front-end: + build: + context: front-end + dockerfile: Dockerfile + container_name: front-end_c + restart: always + ports: + - "${PORT}:3000" # changed to dynamic port + #stdin_open: true # GCP does not support might remove + #tty: true # GCP does not support might remove + depends_on: + - user-microservice + #networks: + # - app_net + +volumes: + postgresDB_c: + musicMicroservice_c: + userMicroservice_c: + feedMicroservice_c: +#These are named volumes, which can be used to persist data between +#container restarts and even between deployments. Each named volume +#is associated with a specific microservice, and allows that microservice +#to store and access data that is specific to it. +#For example, the named volume "postgresDB_c" is associated with +#the PostgreSQL service and is used to store the PostgreSQL database data. +#Similarly, the named volume "userMicroservice_c" is associated with the User +#microservice and is used to store any data that the User microservice needs +#to persist between container restarts. diff --git a/docker-compose.yaml b/docker-compose.yaml index 8f19114cbb112d59b0359ac35e360d66ea3b1477..ca2cb9e2753a7a58127be81a19229b66349ad193 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,30 +1,29 @@ -# recommendation is to remove all ports as we do not need to -# expose them to the outside world. just need to expose the -# front-end. add networks here so the containers can communicate -# within themselves using this docker network. - -# networks: -# app_net: - version: "3.8" services: + postgres: + image: postgres:11.5 + restart: always + environment: + - POSTGRES_PASSWORD=password + - POSTGRES_DB=best-listens + ports: + - "5432:5432" + container_name: postgresDB_c + volumes: + - ./userMicroservice/postgres-db:/var/lib/postgresql/data - #networks: - # - app_net music-microservice: build: context: musicMicroservice dockerfile: Dockerfile ports: - - "${PORT}:5050" # changed to dynamic port + - "5050:5050" container_name: musicMicroservice_c restart: unless-stopped volumes: - ./musicMicroservice:/app depends_on: - postgres - #networks: - # - app_net user-microservice: build: @@ -33,28 +32,25 @@ services: restart: unless-stopped container_name: userMicroservice_c ports: - - "${PORT}:3002" # changed to dynamic port + - "3002:3002" volumes: - ./userMicroservice:/app depends_on: - postgres - #networks: - # - app_net feed-microservice: build: context: feedMicroservice dockerfile: Dockerfile ports: - - "${PORT}:5051" # changed to dynamic port + - "5051:5051" container_name: feedMicroservice_c restart: unless-stopped volumes: - ./feedMicroservice:/app depends_on: + - postgres - user-microservice - #networks: - # - app_net front-end: build: @@ -63,25 +59,9 @@ services: container_name: front-end_c restart: always ports: - - "${PORT}:3000" # changed to dynamic port - #stdin_open: true # GCP does not support might remove - #tty: true # GCP does not support might remove + - "3000:3000" + stdin_open: true + tty: true depends_on: + - postgres - user-microservice - #networks: - # - app_net - -volumes: - postgresDB_c: - musicMicroservice_c: - userMicroservice_c: - feedMicroservice_c: -#These are named volumes, which can be used to persist data between -#container restarts and even between deployments. Each named volume -#is associated with a specific microservice, and allows that microservice -#to store and access data that is specific to it. -#For example, the named volume "postgresDB_c" is associated with -#the PostgreSQL service and is used to store the PostgreSQL database data. -#Similarly, the named volume "userMicroservice_c" is associated with the User -#microservice and is used to store any data that the User microservice needs -#to persist between container restarts. diff --git a/feedMicroservice/Dockerfile b/feedMicroservice/Dockerfile index 61df2c271d9ad9705f6c6a5c6dc87bc1e62d15ab..0f18959a022215f8867e93909e85972e6fd366a6 100644 --- a/feedMicroservice/Dockerfile +++ b/feedMicroservice/Dockerfile @@ -18,4 +18,5 @@ EXPOSE $PORT #CMD ["python", "app.py"] # idk if this is correct, will have to try deploying it -CMD ["gunicorn", "-b", "0.0.0.0:${PORT}", "app:app"] \ No newline at end of file +# CMD ["gunicorn", "-b", "0.0.0.0:${PORT}", "app:app"] +CMD gunicorn -b 0.0.0.0:$PORT app:app diff --git a/feedMicroservice/app.py b/feedMicroservice/app.py index 23546cf43404f62b1e1b349c04a2f5280b4e52e0..e33240c86419ff50220b0e1d590dbe1c9415292d 100644 --- a/feedMicroservice/app.py +++ b/feedMicroservice/app.py @@ -1,6 +1,11 @@ from flask import Flask, request from flask_cors import CORS import requests +import os + +MUSIC_MICROSERVICE_URL = os.environ.get('MUSIC_MICROSERVICE_URL', 'http://musicMicroservice_c:5050') +USER_MICROSERVICE_URL = os.environ.get('USER_MICROSERVICE_URL', 'http://userMicroservice_c:3002') + app = Flask(__name__) CORS(app) @@ -16,7 +21,7 @@ def getFeed(): headers = {"accessToken": accessToken} - followings = (requests.post('http://userMicroservice_c:3002/followings/getFollowings', + followings = (requests.post(f'{USER_MICROSERVICE_URL}/followings/getFollowings', json={"userID": userID}, headers=headers)).json() @@ -32,12 +37,12 @@ def getFeed(): for i in range (len(followingsID)): id = int(followingsID[i]) # person your followings ID # followerRatings = that users all ratings for all songs - followerRatings = (requests.get(f'http://musicMicroservice_c:5050/all_ratings?userID={id}')).json() - user = (requests.post(f'http://userMicroservice_c:3002/auth/getUser', json={"userID": id}, headers=headers)).json() + followerRatings = (requests.get(f'{MUSIC_MICROSERVICE_URL}/all_ratings?userID={id}')).json() + user = (requests.post(f'{USER_MICROSERVICE_URL}/auth/getUser', json={"userID": id}, headers=headers)).json() name = (user['username']) for j in range (len(followerRatings)): - song = (requests.get(f'http://musicMicroservice_c:5050/search_id/{followerRatings[j][0]}')).json() + song = (requests.get(f'{MUSIC_MICROSERVICE_URL}/search_id/{followerRatings[j][0]}')).json() song.append(followerRatings[j][1]) song.append(followerRatings[j][2]) song.append(name) @@ -48,12 +53,13 @@ def getFeed(): @app.route('/getFeedGeneric') def getFeedGeneric(): feed = [] - topRatings = (requests.get('http://musicMicroservice_c:5050/top_ratings/')).json() + topRatings = (requests.get(f'{MUSIC_MICROSERVICE_URL}/top_ratings/')).json() for i in range(len(topRatings)): - song = (requests.get(f'http://musicMicroservice_c:5050/search_id/{topRatings[i][0]}')).json() + song = (requests.get(f'{MUSIC_MICROSERVICE_URL}/search_id/{topRatings[i][0]}')).json() song.append(topRatings[i][1]) feed.append(song) return feed if __name__ == '__main__': - app.run(host='0.0.0.0',port=5051) \ No newline at end of file + # app.run(host='0.0.0.0',port=5051) + app.run(host='0.0.0.0',port=int(os.environ.get('PORT', 5051))) \ No newline at end of file diff --git a/front-end/Dockerfile b/front-end/Dockerfile index 4ea9d7bbd38876c08d48d8b3cc01ce0be32bb14c..0a7919f896e5234e5c08d30a4847aaaf2ceedefe 100644 --- a/front-end/Dockerfile +++ b/front-end/Dockerfile @@ -21,4 +21,6 @@ RUN npm run build # start the application #CMD ["serve", "-s", "build"] -CMD ["serve", "-s", "build", "-l", "tcp://0.0.0.0:${PORT}"] +# CMD ["serve", "-s", "build", "-l", "tcp://0.0.0.0:${PORT}"] +CMD serve -s build -l tcp://0.0.0.0:$PORT + diff --git a/front-end/src/App.js b/front-end/src/App.js index 955e9f6f3958d55d8c832fa8fbc4fff0dd9f8594..afd677d485f128148482bd2f7c94cb4241aed07f 100644 --- a/front-end/src/App.js +++ b/front-end/src/App.js @@ -24,13 +24,15 @@ import "react-toastify/dist/ReactToastify.css"; import Followers from "./Followers"; import Followings from "./Followings"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + function App() { const [authState, setAuthState] = useState(false); const [userID, setUserID] = useState(false); useEffect(() => { axios - .get("http://localhost:3002/auth/auth", { + .get(`${userMicroserviceUrl}/auth/auth`, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/front-end/src/Feed.js b/front-end/src/Feed.js index 54bc19269b315b973de0a426f9f5686624e0a4b6..8f143e0687b3d50e7fd4b2f00bca42217ce0949b 100644 --- a/front-end/src/Feed.js +++ b/front-end/src/Feed.js @@ -4,6 +4,8 @@ import { AuthContext } from "./helpers/AuthContext"; import axios from "axios"; import { ToastContainer, toast } from "react-toastify"; +const feedMicroserviceUrl = process.env.FEEDMICROSERVICE_URL || "http://localhost:5051"; + function Feed() { const { userID, authState } = useContext(AuthContext); const [feedData, setFeedData] = useState([]); @@ -12,7 +14,7 @@ function Feed() { async function getFeed() { setNotified(false); await axios - .get(`http://localhost:5051/getFeed?userID=${userID}`, { + .get(`${feedMicroserviceUrl}/getFeed?userID=${userID}`, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -28,7 +30,7 @@ function Feed() { } async function getGenericFeed() { - await axios.get(`http://localhost:5051/getFeedGeneric`).then((response) => { + await axios.get(`${feedMicroserviceUrl}/getFeedGeneric`).then((response) => { if (response.data.error) { alert(response.data.error); } else { diff --git a/front-end/src/Followers.js b/front-end/src/Followers.js index 633926a907c2d9df2354f670329489ecfc611759..ad24cd5ed304650decf74671b31e89e4d1846a22 100644 --- a/front-end/src/Followers.js +++ b/front-end/src/Followers.js @@ -6,6 +6,8 @@ import axios from "axios"; import "./Followers.css"; import { Link } from "react-router-dom"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + export default function Followers() { const navigate = useNavigate(); const { userID, authState } = useContext(AuthContext); @@ -15,7 +17,7 @@ export default function Followers() { async function getFollowers() { const data = { userID: userID }; await axios - .post("http://localhost:3002/followings/getFollowers", data, { + .post(`${userMicroserviceUrl}/followings/getFollowers`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -38,7 +40,7 @@ export default function Followers() { async function getUser(followerID) { const data = { userID: followerID }; await axios - .post("http://localhost:3002/auth/getUser", data, { + .post(`${userMicroserviceUrl}/auth/getUser`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/front-end/src/Followings.js b/front-end/src/Followings.js index 0565784cacac0381674c809aba13a3a9cf2ba6da..f8f8ebad489d6d2edc6054da89eecc2239366a5c 100644 --- a/front-end/src/Followings.js +++ b/front-end/src/Followings.js @@ -5,6 +5,8 @@ import axios from "axios"; import "./Followers.css"; import { Link } from "react-router-dom"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + export default function Followings() { const { userID, authState } = useContext(AuthContext); const [followings, setFollowings] = useState([]); @@ -14,7 +16,7 @@ export default function Followings() { setFollowings([]); const data = { userID: userID }; await axios - .post("http://localhost:3002/followings/getFollowings", data, { + .post(`${userMicroserviceUrl}/followings/getFollowings`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -37,7 +39,7 @@ export default function Followings() { async function getUser(userID) { const data = { userID: userID }; await axios - .post("http://localhost:3002/auth/getUser", data, { + .post(`${userMicroserviceUrl}/auth/getUser`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/front-end/src/Login.js b/front-end/src/Login.js index b223429577569080b78184005292c8a4d3be2774..e490afceb149a30da67132d0dc9aff8ee7d24d6f 100644 --- a/front-end/src/Login.js +++ b/front-end/src/Login.js @@ -6,6 +6,8 @@ import { Button } from "@material-ui/core"; import "./Login.css"; import "./Home.css"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + function Login() { const navigate = useNavigate(); @@ -18,7 +20,7 @@ function Login() { const login = (username, password) => { const data = { username: username, password: password }; - axios.post("http://localhost:3002/auth/login", data).then((response) => { + axios.post(`${userMicroserviceUrl}/auth/login`, data).then((response) => { if (response.data.error) { alert(response.data.error); } else { diff --git a/front-end/src/MyRates.js b/front-end/src/MyRates.js index aa748cd94629be90dd959c810fdf342d1824c922..f12682d31695237e7a3ea24d73c054e7fca56e8b 100644 --- a/front-end/src/MyRates.js +++ b/front-end/src/MyRates.js @@ -6,13 +6,15 @@ import axios from "axios"; import { AuthContext } from "./helpers/AuthContext"; import { Link } from "react-router-dom"; +const musicMicroserviceUrl = process.env.MUSICMICROSERVICE_URL || "http://localhost:5050"; + function MyRates() { const { userID } = useContext(AuthContext); const [allRatings, setAllRatings] = useState({ ratings: [] }); async function getRatings() { const response = await axios.get( - `http://localhost:5050/all_ratings/?userID=${userID}` + `${musicMicroserviceUrl}/all_ratings/?userID=${userID}` ); const ratings = response.data || []; const updatedRatings = []; @@ -20,7 +22,7 @@ function MyRates() { const id = ratings[i][0]; const rating = ratings[i][1]; const songInfoResponse = await axios.get( - `http://localhost:5050/search_id/${id}` + `${musicMicroserviceUrl}/search_id/${id}` ); const songInfo = songInfoResponse.data[0]; updatedRatings.push([ diff --git a/front-end/src/Profile.js b/front-end/src/Profile.js index 93edf6fdf44d06c236f10838c4b904c51d235ff4..1ac2b3afe340fd7c332d3fa66a5c7dacdbcf3b33 100644 --- a/front-end/src/Profile.js +++ b/front-end/src/Profile.js @@ -5,6 +5,8 @@ import { AuthContext } from "./helpers/AuthContext"; import ProfileCard from "./ProfileCard"; import Widgets from "./Widgets"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + function Profile() { const { userID } = useContext(AuthContext); const [followers, setFollowers] = useState([]); @@ -14,7 +16,7 @@ function Profile() { async function getFollowers() { const data = { userID: userID }; axios - .post("http://localhost:3002/followings/getFollowers", data, { + .post(`${userMicroserviceUrl}/followings/getFollowers`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -32,7 +34,7 @@ function Profile() { async function getFollowings() { const data = { userID: userID }; axios - .post("http://localhost:3002/followings/getFollowings", data, { + .post(`${userMicroserviceUrl}/followings/getFollowings`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -50,7 +52,7 @@ function Profile() { async function changeUsername() { const data = { userID: userID, username: "newUsername" }; axios - .post("http://localhost:3002/auth/changeUsername", data, { + .post(`${userMicroserviceUrl}/auth/changeUsername`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -67,7 +69,7 @@ function Profile() { async function getUser() { const data = { userID: userID }; axios - .post("http://localhost:3002/auth/getUser", data, { + .post(`${userMicroserviceUrl}/auth/getUser`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/front-end/src/Register.js b/front-end/src/Register.js index 1c1416f78d4afa1afe8fd1f39adfebf67dbf6431..2d39e80fa9ae898877cfd50c59415c3ee79e4ae5 100644 --- a/front-end/src/Register.js +++ b/front-end/src/Register.js @@ -7,6 +7,8 @@ import * as Yup from "yup"; import axios from "axios"; import { useNavigate } from "react-router-dom"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; + function Register() { const navigate = useNavigate(); const initialValues = { @@ -51,7 +53,7 @@ function Register() { async function addUser(data) { await axios - .post("http://localhost:3002/auth/createUser", data) + .post(`${userMicroserviceUrl}/auth/createUser`, data) .then((response) => { if (response.data.error) { alert(response.data.error); @@ -68,7 +70,7 @@ function Register() { async function addPassword(username, password) { let userPassword = { username: username, password: password }; await axios - .post("http://localhost:3002/auth/addPassword", userPassword) + .post(`${userMicroserviceUrl}/auth/addPassword`, userPassword) .then((response) => { console.log(response); }); diff --git a/front-end/src/Song.js b/front-end/src/Song.js index 986e5220de3f9ecedeff8f4ee9fd35c36d3b3f6f..580630d6eaf7de951d06cf6a35ebb49ccf3fb8eb 100644 --- a/front-end/src/Song.js +++ b/front-end/src/Song.js @@ -6,6 +6,8 @@ import { useParams } from "react-router-dom"; import axios from "axios"; import { AuthContext } from "./helpers/AuthContext"; +const musicMicroserviceUrl = process.env.MUSICMICROSERVICE_URL || "http://localhost:5050"; + function Song() { const { id } = useParams(); const [searchResults, setSearchResults] = useState({ @@ -23,7 +25,7 @@ function Song() { const { authState, userID } = useContext(AuthContext); function getSongInfo() { - axios.get(`http://localhost:5050/search_id/${id}`).then((response) => { + axios.get(`${musicMicroserviceUrl}/search_id/${id}`).then((response) => { setSearchResults({ title: response.data[0][1] || [], artist: response.data[0][2] || [], @@ -34,7 +36,7 @@ function Song() { } function getSongRating() { - axios.get(`http://localhost:5050/av_rating/${id}`).then((response) => { + axios.get(`${musicMicroserviceUrl}/av_rating/${id}`).then((response) => { setRatingResult({ rating: response.data || [], }); @@ -50,7 +52,7 @@ function Song() { } else { axios .get( - `http://localhost:5050/check_rating/?songID=${id}&userID=${userID}` + `${musicMicroserviceUrl}/check_rating/?songID=${id}&userID=${userID}` ) .then((response) => { setUserRatingResult({ @@ -69,7 +71,7 @@ function Song() { } else { axios .get( - `http://localhost:5050/add_rating?songID=${id}&rating=${rate}&userID=${userID}` + `${musicMicroserviceUrl}/add_rating?songID=${id}&rating=${rate}&userID=${userID}` ) .then((response) => { console.log(response); diff --git a/front-end/src/User.js b/front-end/src/User.js index c3047f9a9e45e7c81bb366bf50f72c7f29681056..01d06e312c47f15d194827e4cc57dbae091e438c 100644 --- a/front-end/src/User.js +++ b/front-end/src/User.js @@ -7,6 +7,9 @@ import ProfileCard from "./ProfileCard"; import Widgets from "./Widgets"; import { Link } from "react-router-dom"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; +const musicMicroserviceUrl = process.env.MUSICMICROSERVICE_URL || "http://localhost:5050"; + export default function User() { const { id } = useParams(); const [followers, setFollowers] = useState([]); @@ -17,7 +20,7 @@ export default function User() { function getUser() { const data = { userID: id }; axios - .post("http://localhost:3002/auth/getUser", data, { + .post(`${userMicroserviceUrl}/auth/getUser`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -35,7 +38,7 @@ export default function User() { function getFollowers() { const data = { userID: id }; axios - .post("http://localhost:3002/followings/getFollowers", data, { + .post(`${userMicroserviceUrl}/followings/getFollowers`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -53,7 +56,7 @@ export default function User() { async function getFollowings() { const data = { userID: id }; axios - .post("http://localhost:3002/followings/getFollowings", data, { + .post(`${userMicroserviceUrl}/followings/getFollowings`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -70,7 +73,7 @@ export default function User() { async function getRatings() { const response = await axios.get( - `http://localhost:5050/all_ratings/?userID=${id}` + `${musicMicroserviceUrl}/all_ratings/?userID=${id}` ); const ratings = response.data || []; const updatedRatings = []; @@ -78,7 +81,7 @@ export default function User() { const id = ratings[i][0]; const rating = ratings[i][1]; const songInfoResponse = await axios.get( - `http://localhost:5050/search_id/${id}` + `${musicMicroserviceUrl}/search_id/${id}` ); const songInfo = songInfoResponse.data[0]; updatedRatings.push([ @@ -109,7 +112,7 @@ export default function User() { const userData = { userID: userID }; var follower = [] await axios - .post("http://localhost:3002/auth/getUser", userData, { + .post(`${userMicroserviceUrl}/auth/getUser`, userData, { headers: { accessToken: localStorage.getItem("accessToken"), }, @@ -123,7 +126,7 @@ export default function User() { }); const data = {user: user.username, follower: follower} await axios - .post("http://localhost:3002/followings/follow", data, { + .post(`${userMicroserviceUrl}/followings/follow`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/front-end/src/Widgets.js b/front-end/src/Widgets.js index e3301e9deeeb9d4deed62f5a3753db9cebe03843..4e00804210ba664ba6d5c045f8527c7647f29dde 100644 --- a/front-end/src/Widgets.js +++ b/front-end/src/Widgets.js @@ -4,6 +4,9 @@ import SearchIcon from "@material-ui/icons/Search"; import axios from "axios"; import { Link } from "react-router-dom"; +const userMicroserviceUrl = process.env.USERMICROSERVICE_URL || "http://localhost:3002"; +const musicMicroserviceUrl = process.env.MUSICMICROSERVICE_URL || "http://localhost:5050"; + export default function Widgets() { const [searchValue, setSearchValue] = useState(""); const [searchResults, setSearchResults] = useState({ @@ -19,7 +22,7 @@ export default function Widgets() { if (searchValue.trim()) { // Check if searchValue is not blank await axios - .get(`http://localhost:5050/search2/?search=${searchValue}`) + .get(`${musicMicroserviceUrl}/search2/?search=${searchValue}`) .then((response) => { setSearchResults({ songs: response.data[0] || [], @@ -38,7 +41,7 @@ export default function Widgets() { if (searchValue.trim()) { // Check if searchValue is not blank await axios - .post(`http://localhost:3002/auth/searchUsers`, data, { + .post(`${userMicroserviceUrl}/auth/searchUsers`, data, { headers: { accessToken: localStorage.getItem("accessToken"), }, diff --git a/musicMicroservice/Dockerfile b/musicMicroservice/Dockerfile index 875bb5a3bf1c433178bd6d57a53033ce70f85111..cdff3a07e562e61ce68e3ad733c72c7779f11e79 100644 --- a/musicMicroservice/Dockerfile +++ b/musicMicroservice/Dockerfile @@ -16,4 +16,5 @@ ENV PORT=5050 EXPOSE $PORT #CMD ["python", "app.py"] -CMD ["gunicorn", "-b", "0.0.0.0:${PORT}", "app:app"] +# CMD ["gunicorn", "-b", "0.0.0.0:${PORT}", "app:app"] +CMD gunicorn -b 0.0.0.0:$PORT app:app diff --git a/musicMicroservice/app.py b/musicMicroservice/app.py index 39ee514eceaf15ed06cd5879f3d9789c89d6590b..319364759f10092a5a79e7efc2841259b57b40b2 100644 --- a/musicMicroservice/app.py +++ b/musicMicroservice/app.py @@ -3,6 +3,8 @@ from flask_cors import CORS import sqlite3 from sqlite3 import Error from flask import jsonify +import os + app = Flask(__name__) CORS(app) @@ -145,4 +147,5 @@ def top_ratings(): return jsonify(top_tracks) if __name__ == '__main__': - app.run(host='0.0.0.0',port=5050) \ No newline at end of file + # app.run(host='0.0.0.0',port=5050) + app.run(host='0.0.0.0',port=int(os.environ.get('PORT', 5050))) \ No newline at end of file diff --git a/userMicroservice/Dockerfile b/userMicroservice/Dockerfile index c4e153f39f108b5ead3682065aabfa79c8e2cd03..b50f45e588413fab20cf73f153bbac6bea9efb71 100644 --- a/userMicroservice/Dockerfile +++ b/userMicroservice/Dockerfile @@ -1,6 +1,7 @@ FROM node:14 as Production ENV NODE_ENV=development +ENV PORT=3002 WORKDIR /app @@ -15,9 +16,11 @@ RUN npm install COPY . . -EXPOSE 3002 +EXPOSE $PORT # required for docker desktop port mapping # RUN npm start -CMD ["npm", "run", "dev"] -#CMD ["npm", "start"] ?? +#CMD ["npm", "run", "dev"] +# CMD ["npm", "start"] +CMD npm start + diff --git a/userMicroservice/config/config.json b/userMicroservice/config/config.json index aebc09d0bd7f2b39ceffb2222826aae86cfba1f7..653784f3b472bd9ddead3fe929bcfcef18238296 100644 --- a/userMicroservice/config/config.json +++ b/userMicroservice/config/config.json @@ -3,7 +3,7 @@ "username": "postgres", "password": "password", "database": "best-listens", - "host": "postgres", + "host": "best-listens-postgres-bsui3euuva-nw.a.run.app", "dialect": "postgres", "port": "5432" } diff --git a/userMicroservice/index.js b/userMicroservice/index.js index be5827c1540ef9560def18bcefe561fac1bd65df..cbf9ddcf7e61587652d489bcb1617ddcdebbbab0 100644 --- a/userMicroservice/index.js +++ b/userMicroservice/index.js @@ -14,7 +14,8 @@ const followersRouter = require("./routes/Followers"); app.use("/followings", followersRouter); db.sequelize.sync().then(() => { - app.listen(3002, () => { - console.log("Server running on port 3002"); + const PORT = process.env.PORT || 3002; + app.listen(PORT, () => { + console.log(`Server running on port ${PORT}`); }); });