-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SlimFaasPlanetSaver): add npm component
- Loading branch information
1 parent
cdd18f6
commit a43108f
Showing
21 changed files
with
8,500 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ on: | |
branches: [ main ] | ||
types: [opened, synchronize, reopened] | ||
|
||
env: | ||
PNPM_VERSION: 8.6.11 | ||
NODE_VERSION: 18 | ||
|
||
jobs: | ||
sonarcloud: | ||
name: SonarCloud | ||
|
@@ -137,3 +141,36 @@ jobs: | |
secrets: | ||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | ||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
build_slimfaas_planet_saver: | ||
needs: tags | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: ${{ env.PNPM_VERSION }} | ||
run_install: false | ||
- name: pnpm ci | ||
run: pnpm i --frozen-lockfile | ||
working-directory: ./src/SlimFaasPlanetSaver | ||
- name: Git Configuration | ||
id: gitconfig | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub" | ||
- name: pnpm version ${{ steps.tag.outputs.new_version }} | ||
if: github.ref == 'refs/heads/main' | ||
run: | | ||
pnpm version ${{ steps.tag.outputs.new_version }} | ||
working-directory: ./src/SlimFaasPlanetSaver | ||
- id: Publish | ||
uses: JS-DevTools/npm-publish@v1 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
token: ${{ secrets.NPM_TOKEN }} | ||
package: ./src/SlimFaasPlanetSaver/package.json |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
*storybook.log |
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,78 @@ | ||
# @axa-fr/slimfaas-planet-saver | ||
|
||
![SlimFaas.png](https://github.com/AxaFrance/SlimFaas/blob/main/documentation/SlimFaas.png) | ||
|
||
A Vanilla JS project to save the planet. SlimFaas (https://github.com/AxaFrance/slimfaas) is the slimest and simplest Function As A Service on Kubernetes. | ||
It works as a proxy that you can be deployed in your namespace. | ||
|
||
SlimFaas API can give to the frontend information about the infrastructure state. **It is a mind changer !** | ||
|
||
**Why?** | ||
|
||
Because in production instead of setting up 2 replicas of your API backend, you can set up 0 replicas and use an UX that will show the user that the backend is down instead ! | ||
**@axa-fr/slimfaas-planet-saver** is here to for doing that easily. | ||
|
||
![SlimFaasPlanetSaver.gif](https://github.com/AxaFrance/SlimFaas/blob/main/documentation/SlimfaasPlanetSaver.gif) | ||
|
||
## Getting Started | ||
|
||
```javascript | ||
npm install @axa-fr/slimfaas-planet-saver | ||
``` | ||
|
||
Example usage with react : | ||
```javascript | ||
import React, { useState, useEffect } from 'react'; | ||
import SlimFaasPlanetSaver from "@axa-fr/slimfass-planet-saver"; | ||
|
||
const PlanetSaver = ({ children, baseUrl, fetch }) => { | ||
const [isFirstStart, setIsFirstStart] = useState(true); // State for first start | ||
|
||
useEffect(() => { | ||
if (!baseUrl) return; | ||
|
||
const environmentStarter = new SlimFaasPlanetSaver(baseUrl, { | ||
interval: 2000, | ||
fetch, | ||
updateCallback: (data) => { | ||
const allReady = data.every((item) => item.NumberReady >= 1); | ||
if (allReady && isFirstStart) { | ||
setIsFirstStart(false); | ||
} | ||
}, | ||
errorCallback: (error) => { | ||
console.error('Error detected :', error); | ||
environmentStarter.updateOverlayMessage('An error occured when starting environment. Please contact an administrator.'); | ||
}, | ||
overlayMessage: 'Starting the environment...', | ||
}); | ||
|
||
// Start polling | ||
environmentStarter.startPolling(); | ||
|
||
// Cleanup | ||
return () => environmentStarter.cleanup(); | ||
}, [baseUrl, isFirstStart]); | ||
|
||
// During the first start, display a loading message | ||
if (isFirstStart) { | ||
return null; | ||
} | ||
|
||
// Once the environment is started, display the children | ||
return <>{children}</>; | ||
|
||
}; | ||
|
||
export default PlanetSaver; | ||
|
||
``` | ||
|
||
## Run the demo | ||
|
||
```javascript | ||
git clone https://github.com/AxaFrance/slimfaas.git | ||
cd slimfaas/src/SlimFaasPlanetSaver | ||
npm i | ||
npm run dev | ||
``` |
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,38 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import react from 'eslint-plugin-react' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
|
||
export default [ | ||
{ ignores: ['dist'] }, | ||
{ | ||
files: ['**/*.{js,jsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
ecmaFeatures: { jsx: true }, | ||
sourceType: 'module', | ||
}, | ||
}, | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
react, | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...js.configs.recommended.rules, | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
...reactHooks.configs.recommended.rules, | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
] |
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,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="icon" type="image/png" href="/AXA.png" /> | ||
<title>SlimFaas Planet Saver</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.