-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deploy): test deployment to kubernetes azure
- Loading branch information
1 parent
4b278a9
commit ad0bdf0
Showing
7 changed files
with
145 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
const BaseUrlContext = React.createContext(null); | ||
|
||
export default BaseUrlContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import BaseUrlContext from './BaseUrlContext'; | ||
|
||
const EnvironmentStarter = ({ children }) => { | ||
const [baseUrl, setBaseUrl] = useState(''); | ||
const [statusData, setStatusData] = useState(null); | ||
|
||
useEffect(() => { | ||
let intervalId; | ||
|
||
if (baseUrl) { | ||
let tempBaseUrl = baseUrl; | ||
if(baseUrl.endsWith('/')) { | ||
tempBaseUrl = baseUrl.slice(0, -1); | ||
} | ||
if(baseUrl.endsWith('/function/api')) { | ||
tempBaseUrl = tempBaseUrl.replace('/function/api', ''); | ||
} | ||
console.log('tempBaseUrl:', tempBaseUrl); | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(`${tempBaseUrl}/status-functions`); | ||
const data = await response.json(); | ||
setStatusData(data); | ||
|
||
// Pour chaque élément, si NumberReady est 0, appeler /wake-function/<Name> | ||
data.forEach(async (item) => { | ||
if (item.NumberReady === 0) { | ||
await fetch(`${tempBaseUrl}/wake-function/${item.Name}`, { | ||
method: 'POST', | ||
}); | ||
} | ||
}); | ||
} catch (error) { | ||
console.error('Erreur lors de la récupération des données:', error); | ||
} | ||
}; | ||
|
||
// Appel initial | ||
fetchData(); | ||
|
||
// Mise en place de l'intervalle toutes les 5 secondes | ||
intervalId = setInterval(fetchData, 5000); | ||
|
||
// Nettoyage de l'intervalle lors du démontage ou du changement de baseUrl | ||
return () => clearInterval(intervalId); | ||
} | ||
|
||
// Nettoyage si baseUrl est vide | ||
return () => { | ||
if (intervalId) clearInterval(intervalId); | ||
}; | ||
}, [baseUrl]); | ||
|
||
if (!baseUrl) { | ||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="Entrez la baseUrl" | ||
value={baseUrl} | ||
onChange={(e) => setBaseUrl(e.target.value)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
if (!statusData) { | ||
return <div>Chargement des données...</div>; | ||
} | ||
|
||
const allReady = statusData.every((item) => item.NumberReady >= 1); | ||
|
||
if (allReady) { | ||
console.log('Tous les pods sont prêts'); | ||
console.log('baseUrl:', baseUrl); | ||
return ( | ||
<BaseUrlContext.Provider value={baseUrl}> | ||
{children} | ||
</BaseUrlContext.Provider> | ||
); | ||
} else { | ||
const startingPods = statusData | ||
.filter((item) => item.NumberReady === 0) | ||
.map((item) => item.Name) | ||
.join(', '); | ||
|
||
return ( | ||
<div> | ||
<p>Démarrage de l'environnement en cours...</p> | ||
<p>Pods en cours de démarrage : {startingPods}</p> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default EnvironmentStarter; |