Skip to content

Commit

Permalink
Merge branch 'microservice' into ft/database-microservice-api
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodinemma committed May 23, 2024
2 parents 850568f + 8e355e3 commit 15a2fb8
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 38 deletions.
134 changes: 134 additions & 0 deletions .github/workflows/microservice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Microservice deployment

on:
push:
branches:
- microservice

workflow_dispatch:

jobs:
build:
outputs:
image: ${{ steps.export.outputs.image }}
tag: ${{ steps.export.outputs.tag }}

runs-on: ubuntu-latest
env:
namespace: cranecloud-microservice
image: cranecloud/frontend
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install (Buildx)
uses: docker/setup-buildx-action@v1

- name: Set up Docker Buildx
run: |
docker buildx create --use
docker buildx version # Print information to verify that Buildx is set up
if: runner.os == 'Linux' # Only run on Linux runners

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Install kubectl
run: |
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
- id: meta
name: Tag
uses: docker/metadata-action@v3
with:
flavor: |
latest=true
images: ${{ env.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Add Env vars
env:
REACT_APP_API_BASE_URL: https://product.renu-01.cranecloud.io
REACT_APP_ACTIVITY_LOGS_API_URL: https://logger.renu-01.cranecloud.io/api
REACT_APP_MONITORING_API_URL: https://monitoring.renu-01.cranecloud.io
REACT_APP_MIRA_API_URL: ${{ secrets.REACT_APP_MIRA_API_URL }}
REACT_APP_FLUTTERWAVE_PUBLIC_KEY_TESTING: ${{ secrets.REACT_APP_FLUTTERWAVE_PUBLIC_KEY_TESTING }}
REACT_APP_GITHUB_CLEINT_ID: ${{ secrets.REACT_APP_GITHUB_CLEINT_ID_STAGING }}
REACT_APP_EXCHANGE_RATE_KEY: ${{ secrets.REACT_APP_EXCHANGE_RATE_KEY }}
REACT_APP_DOCS_URL: ${{ secrets.REACT_APP_DOCS_URL_STAGING }}
REACT_APP_DOCKER_EMAIL: ${{ secrets.REACT_APP_DOCKER_EMAIL }}
REACT_APP_DOCKER_PASSWORD: ${{ secrets.REACT_APP_DOCKER_PASSWORD }}
REACT_APP_MONITORING_APP: ${{ secrets.REACT_APP_MONITORING_APP_STAGING }}
run: |
chmod +x ./.github/workflows/bin/create_envs.sh
./.github/workflows/bin/create_envs.sh
- name: Build
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: docker/prod/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}

- id: export
name: Export
uses: actions/github-script@v5
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
if (fullUrl == null) {
core.error('Unable to find sha tag of image')
} else {
const tag = fullUrl.split(':')[1]
core.setOutput('image', fullUrl)
core.setOutput('tag', tag)
}
Microservice:
name: Deploy (Staging)

needs:
- build

runs-on: ubuntu-latest
env:
namespace: cranecloud-microservice
image: cranecloud/frontend
deployment: cranecloud-frontend

steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: azure/k8s-set-context@v1
with:
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}

- name: Deploy or Update Deployment
run: |
if kubectl get deployment $deployment -n $namespace > /dev/null 2>&1; then
echo "Deployment exists. Updating image..."
kubectl set image deployment/$deployment $deployment=${{ env.image }}:${{ needs.build.outputs.tag }} --record -n $namespace
else
echo "Deployment does not exist. Creating deployment..."
kubectl apply -f docker/prod/deployment.yml -n $namespace
fi
- name: Monitor Rollout
run: |
kubectl rollout status deployment/$deployment --timeout=300s --namespace $namespace
36 changes: 36 additions & 0 deletions docker/prod/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cranecloud-frontend
namespace: cranecloud-microservice
labels:
app: cranecloud-frontend
spec:
replicas: 1
selector:
matchLabels:
app: cranecloud-frontend
template:
metadata:
labels:
app: cranecloud-frontend
spec:
containers:
- name: cranecloud-frontend
image: cranecloud/frontend:latest
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: cranecloud-frontend
namespace: cranecloud-microservice
spec:
selector:
app: cranecloud-frontend
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: ClusterIP
3 changes: 2 additions & 1 deletion src/apis/apis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "../axios";
import axios,{userActivityLoggerAxios} from "../axios";


export const handlePostRequestWithDataObject = (
data,
Expand Down
38 changes: 31 additions & 7 deletions src/axios.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import axios from "axios";
import { API_BASE_URL, DATABASE_API_URL } from "./config";

const databaseAxios = axios.create({
baseURL: DATABASE_API_URL,
});
import { API_BASE_URL, ACTIVITY_LOGS_API_URL, MONITORING_API_URL, DATABASE_API_URL } from "./config";

// Create main backend axios instance
const instance = axios.create({
baseURL: API_BASE_URL,
});

// Create activity axios instance
const userActivityLoggerAxios = axios.create({
baseURL: ACTIVITY_LOGS_API_URL,
});

// Create monitoring axios instance
const monitoringAxios = axios.create({
baseURL: MONITORING_API_URL,
});

// Create database axios instance
const databaseAxios = axios.create({
baseURL: DATABASE_API_URL,
});

// Set default headers
const token = localStorage.getItem("token");
instance.defaults.headers.Authorization = `Bearer ${token}`;
userActivityLoggerAxios.defaults.headers.Authorization = `Bearer ${token}`;
monitoringAxios.defaults.headers.Authorization = `Bearer ${token}`;
databaseAxios.defaults.headers.Authorization = `Bearer ${token}`;

// Define response interceptor function
const responseInterceptor = (response) => response;

const errorInterceptor = (error) => {
Expand All @@ -28,9 +44,17 @@ const errorInterceptor = (error) => {
return Promise.reject(e);
};

// response interceptors to both instances
// Add response interceptors to both instances
instance.interceptors.response.use(responseInterceptor, errorInterceptor);
databaseAxios.interceptors.response.use(responseInterceptor, errorInterceptor);
userActivityLoggerAxios.interceptors.response.use(
responseInterceptor,
errorInterceptor
);
monitoringAxios.interceptors.response.use(
responseInterceptor,
errorInterceptor
);

export { instance, databaseAxios };
export { instance, userActivityLoggerAxios, monitoringAxios, databaseAxios };
export default instance;
6 changes: 3 additions & 3 deletions src/components/ActivityLogs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styles from "./ActivityLogs.module.css";
import { handleGetRequest } from "../../apis/apis.js";
import { handleUserActivitiesGetRequest } from "../../apis/apis.js";
import { ReactComponent as CheckMark } from "../../assets/images/check-circle.svg";
import { ReactComponent as Danger } from "../../assets/images/alert-octagon.svg";
// import { ReactComponent as CloudOff } from "../../assets/images/cloud-off.svg";
Expand Down Expand Up @@ -32,7 +32,7 @@ const ActivityLogs = ({ projectID }) => {
//api
const [loading, setLoading] = useState(false);
const [logs, setLogs] = useState([]);
const baseLinkRef = useRef(`/users/activities?`);
const baseLinkRef = useRef(`/activities?`);
// const baseLink = baseLinkRef.current;
useEffect(() => {
if (projectID) {
Expand All @@ -49,7 +49,7 @@ const ActivityLogs = ({ projectID }) => {

const fetchActivityLogs = (link) => {
setLoading(true);
handleGetRequest(link)
handleUserActivitiesGetRequest(link)
.then((response) => {
if (response.data.data.activity.length > 0) {
setLogs(response.data.data.activity);
Expand Down
4 changes: 3 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export const MIRA_DOCS_URL =
"https://docs.cranecloud.io/applications/deployWithMira/";

// microservices
export const DATABASE_API_URL = process.env.REACT_APP_DATABASE_API;
export const DATABASE_API_URL = process.env.REACT_APP_DATABASE_API_URL;
export const ACTIVITY_LOGS_API_URL = process.env.REACT_APP_ACTIVITY_LOGS_API_URL;
export const MONITORING_API_URL = process.env.REACT_APP_MONITORING_API_URL;
6 changes: 3 additions & 3 deletions src/pages/AdminLogsPage/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
// import { useParams } from "react-router-dom";
import { handleGetRequest } from "../../apis/apis.js";
import { handleGetRequest, handleUserActivitiesGetRequest } from "../../apis/apis.js";
import InformationBar from "../../components/InformationBar";
import Header from "../../components/Header";
import SideNav from "../../components/SideNav";
Expand All @@ -21,7 +21,7 @@ import AppFooter from "../../components/appFooter/index.js";
const AdminLogsPage = () => {
const clusterID = localStorage.getItem("clusterID");

const baseLink = "/users/activities?";
const baseLink = "/activities?";
const [loading, setLoading] = useState(false);
const [logs, setLogs] = useState([]);
const [users, setUsers] = useState([]);
Expand Down Expand Up @@ -85,7 +85,7 @@ const AdminLogsPage = () => {
const fetchActivityLogs = (link) => {
setLoading(true);
//projectID
handleGetRequest(link)
handleUserActivitiesGetRequest(link)
.then((response) => {
if (response.data.data.activity.length > 0) {
setLogs(response.data.data.activity);
Expand Down
10 changes: 7 additions & 3 deletions src/redux/actions/appCPU.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "../../axios";
import { monitoringAxios } from "../../axios";
import {
FETCH_APP_CPU_SUCCESS,
FETCH_APP_CPU_FAILED,
Expand Down Expand Up @@ -34,8 +34,12 @@ const clearAppCPU = () => ({
const getAppCPU = (projectID, appID, params) => (dispatch) => {
dispatch(startFetchingCPUMetrics());

return axios
.post(`/projects/${projectID}/apps/${appID}/dashboardcpu`, params)
return monitoringAxios
.post(`/apps/cpu/metrics`, {
...params,
project_id: projectID,
app_id: appID,
})
.then((response) => {
dispatch(getAppCPUMetricsSuccess(appID, response));
})
Expand Down
10 changes: 7 additions & 3 deletions src/redux/actions/appMemory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "../../axios";
import { monitoringAxios } from "../../axios";
import {
FETCH_APP_MEMORY_SUCCESS,
FETCH_APP_MEMORY_FAILED,
Expand Down Expand Up @@ -34,8 +34,12 @@ const clearAppMemory = () => ({
const getAppMemory = (projectID, appID, params) => (dispatch) => {
dispatch(startFetchingAppMemoryMetrics());

return axios
.post(`/projects/${projectID}/apps/${appID}/dashboardmemory`, params)
return monitoringAxios
.post(`/apps/memory/metrics`, {
...params,
project_id: projectID,
app_id: appID,
})
.then((response) => {
dispatch(getAppMemoryMetricsSuccess(appID, response));
})
Expand Down
10 changes: 7 additions & 3 deletions src/redux/actions/appNetwork.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "../../axios";
import { monitoringAxios } from "../../axios";
import {
FETCH_APP_NETWORK_SUCCESS,
FETCH_APP_NETWORK_FAILED,
Expand Down Expand Up @@ -34,8 +34,12 @@ const clearAppNetwork = () => ({
const getAppNetwork = (projectID, appID, params) => (dispatch) => {
dispatch(startFetchingAppNetworkMetrics());

return axios
.post(`/projects/${projectID}/apps/${appID}/dashboardnetwork`, params)
return monitoringAxios
.post(`/apps/network/metrics`, {
...params,
project_id: projectID,
app_id: appID,
})
.then((response) => {
dispatch(getAppNetworkMetricsSuccess(appID, response));
})
Expand Down
9 changes: 4 additions & 5 deletions src/redux/actions/getUserActivities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "../../axios";
import {userActivityLoggerAxios} from "../../axios";
import {
GETTING_USER_ACTIVITIES,
USER_ACTIVITIES_SUCCESS,
Expand Down Expand Up @@ -27,12 +27,11 @@ const getUserActivities = (qeuryParams, currentPage) => (dispatch) => {

let link;
if (qeuryParams !== "" && currentPage !== "") {
link = `/users/activities?${qeuryParams}&page=${currentPage}`;
link = `/activities?${qeuryParams}&page=${currentPage}`;
} else {
link = `/users/activities?page=${currentPage}`;
link = `/activities?page=${currentPage}`;
}

return axios
return userActivityLoggerAxios
.get(link)
.then((response) => {
dispatch(userActivitiesSuccess(response));
Expand Down
Loading

0 comments on commit 15a2fb8

Please sign in to comment.