From b26ae71d6b160edc057a63465ac2383c987ada5f Mon Sep 17 00:00:00 2001
From: rudra <rs01922@surrey.ac.uk>
Date: Sun, 7 May 2023 15:30:42 +0100
Subject: [PATCH] final deployment effort
---
commands | 20 +++++++
docker-compose copy.yaml | 87 +++++++++++++++++++++++++++++
docker-compose.yaml | 58 +++++++------------
feedMicroservice/Dockerfile | 3 +-
feedMicroservice/app.py | 20 ++++---
front-end/Dockerfile | 4 +-
front-end/src/App.js | 4 +-
front-end/src/Feed.js | 6 +-
front-end/src/Followers.js | 6 +-
front-end/src/Followings.js | 6 +-
front-end/src/Login.js | 4 +-
front-end/src/MyRates.js | 6 +-
front-end/src/Profile.js | 10 ++--
front-end/src/Register.js | 6 +-
front-end/src/Song.js | 10 ++--
front-end/src/User.js | 17 +++---
front-end/src/Widgets.js | 7 ++-
musicMicroservice/Dockerfile | 3 +-
musicMicroservice/app.py | 5 +-
userMicroservice/Dockerfile | 9 ++-
userMicroservice/config/config.json | 2 +-
userMicroservice/index.js | 5 +-
22 files changed, 213 insertions(+), 85 deletions(-)
create mode 100644 commands
create mode 100644 docker-compose copy.yaml
diff --git a/commands b/commands
new file mode 100644
index 00000000..e024479b
--- /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 00000000..8f19114c
--- /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 8f19114c..ca2cb9e2 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 61df2c27..0f18959a 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 23546cf4..e33240c8 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 4ea9d7bb..0a7919f8 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 955e9f6f..afd677d4 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 54bc1926..8f143e06 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 633926a9..ad24cd5e 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 0565784c..f8f8ebad 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 b2234295..e490afce 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 aa748cd9..f12682d3 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 93edf6fd..1ac2b3af 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 1c1416f7..2d39e80f 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 986e5220..580630d6 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 c3047f9a..01d06e31 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 e3301e9d..4e008042 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 875bb5a3..cdff3a07 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 39ee514e..31936475 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 c4e153f3..b50f45e5 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 aebc09d0..653784f3 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 be5827c1..cbf9ddcf 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}`);
});
});
--
GitLab