Skip to content

Commit

Permalink
feat(api): add tags (#80)
Browse files Browse the repository at this point in the history
* feat: Add Statefulsets in the list of deployments
* feat(api): add tags
* migrate to vitejs
  • Loading branch information
guillaume-chervet authored Jul 11, 2023
1 parent fd53efb commit 991f3dc
Show file tree
Hide file tree
Showing 47 changed files with 12,293 additions and 61,563 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/Docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Reusable Docker Build

on:
workflow_call:
inputs:
image_name:
required: true
type: string
image_version:
required: true
type: string
image_build_args:
required: true
type: string
image_context:
required: true
type: string
image_file:
required: true
type: string
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true

jobs:
build:
runs-on: ubuntu-latest
environment: dailyclean

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v2
with:
images: ${{ inputs.image_name }}

- name: Build and push Docker image
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v3
with:
context: ${{ inputs.image_context }}
file : ${{ inputs.image_file }}
build-args: ${{ inputs.image_build_args }}
push: true
tags: ${{ inputs.image_name }}:${{ inputs.image_version }},${{ inputs.image_name }}:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image
if: github.ref != 'refs/heads/main'
uses: docker/build-push-action@v3
with:
context: ${{ inputs.image_context }}
file : ${{ inputs.image_file }}
build-args: ${{ inputs.image_build_args }}
push: true
tags: ${{ inputs.image_name }}:${{ inputs.image_version }}
labels: ${{ steps.meta.outputs.labels }}
111 changes: 31 additions & 80 deletions .github/workflows/dailyclean-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '18'

- name: npm install
run: npm install
working-directory: ./api/web

- name: npm test
run: npm test -- --runInBand --coverage --watchAll=false
run: npm test -- --run
working-directory: ./api/web

- name: SonarCloud Scan
Expand All @@ -49,6 +49,7 @@ jobs:
-Dsonar.java.libraries=.
-Dsonar.coverage.jacoco.xmlReportPaths=**/target/jacoco-report/jacoco.xml
-Dsonar.javascript.lcov.reportPaths=api/web/coverage/lcov.info
-Dsonar.javascript.file.suffixes=js,jsx
-Dsonar.python.version=3
-Dsonar.exclusions=**/*.spec.js,**/*.stories.js,**/src/coverage/**,**/*.scss,**/__snapshots__/**,**/node_modules/**,**/src/.storybook/**,**/src/storybook-static/**,**/__mocks__/**
-Dsonar.coverage.exclusions=**src/test/**/*.*
Expand All @@ -68,87 +69,37 @@ jobs:
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Add tag to output step
- name: Add tag to output step for main branch
id: tag
if: github.ref == 'refs/heads/main'
run: echo "::set-output name=new_version::${{ steps.tag_version.outputs.new_version }}"
run: |
if [ '${{ github.ref }}' = 'refs/heads/main' ]; then
echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT
else
echo "new_version=pr-${{ github.event.number }}-${{ github.run_number }}" >> $GITHUB_OUTPUT
fi
build_api:
environment: dailyclean
needs: tags
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: axaguildev/dailyclean-api

- name: Build and push Docker image
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./api
push: true
tags: axaguildev/dailyclean-api:${{ needs.tags.outputs.new_version }},axaguildev/dailyclean-api:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image
if: github.ref != 'refs/heads/main'
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./api
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

uses: ./.github/workflows/Docker.yml
with:
image_name: "axaguildev/dailyclean-api"
image_version: "${{ needs.tags.outputs.new_version }}"
image_build_args: ""
image_context: ./api
image_file: "./api/Dockerfile"
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

build_job:
environment: dailyclean
needs: tags
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: axaguildev/dailyclean-job

- name: Build and push Docker image
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./job/dailyclean
push: true
tags: axaguildev/dailyclean-job:${{ needs.tags.outputs.new_version }},axaguildev/dailyclean-job:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image
if: github.ref != 'refs/heads/main'
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./job/dailyclean
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
uses: ./.github/workflows/Docker.yml
with:
image_name: "axaguildev/dailyclean-job"
image_version: "${{ needs.tags.outputs.new_version }}"
image_build_args: ""
image_context: ./job/dailyclean
image_file: "./job/dailyclean/Dockerfile"
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Daily clean only use kubernetes native API.

To test dailyclean on your local machine by using kubernetes with Docker Desktop, please use these commands:

```
```bash
git clone https://github.com/AxaGuilDEv/dailyclean.git
cd dailyclean/demo
kubectl create namespace license-preproduction
Expand All @@ -48,6 +48,25 @@ It create cron job that start or stop your pods.
- API is in native GraalVM so it is lightweight.
- User interface is in React/Javascript.

you can use specific labels to configure DailyClean in your Kubernetes scripts:

```yaml
metadata:
name: my-api
labels:
# if false, dailyclean will not stop this pod for deployment
axa.com/dailyclean: 'false'
# WARNING: default value is true for DEPLOYMENT and false for STATEFULTSET
```

```yaml
metadata:
name: fibonacci1
labels:
# if true, dailyclean web UI will consider this pod as a function
axa.com/function: 'true'
```
## Contribute
- [How to run the solution and to contribute](./CONTRIBUTING.md)
Expand Down
6 changes: 3 additions & 3 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM node:16-buster AS web
FROM node:18-buster AS web

ENV \
APP_ROOT=/app_root \
Expand All @@ -12,7 +12,7 @@ WORKDIR ${APP_ROOT}
COPY --chown=${USER} ./web .
USER root
RUN npm ci
RUN npm test -- --runInBand --coverage --watchAll=false
RUN npm test -- --run
RUN npm run build

FROM registry.access.redhat.com/ubi9/ubi:9.1.0-1782 AS build
Expand Down Expand Up @@ -78,7 +78,7 @@ ENV PATH=${JAVA_HOME}/bin:${PATH}

COPY --chown=${USER} ./api .
RUN rm -Rf ./src/main/resources/META-INF/resources
COPY --chown=${USER} --from=web ${APP_ROOT}/build ./src/main/resources/META-INF/resources
COPY --chown=${USER} --from=web ${APP_ROOT}/dist ./src/main/resources/META-INF/resources

RUN mvn package -Pnative -B

Expand Down
20 changes: 20 additions & 0 deletions api/web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
browser: true,
es2020: true
},
extends: ["eslint:recommended", "plugin:react/recommended", "plugin:react/jsx-runtime", "plugin:react-hooks/recommended", "plugin:storybook/recommended"],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
settings: {
react: {
version: '18.2'
}
},
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn'
}
};
42 changes: 22 additions & 20 deletions api/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# 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?
/coverage/
24 changes: 15 additions & 9 deletions api/web/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
/** @type { import('@storybook/react-vite').StorybookConfig } */
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/preset-create-react-app"
]
}
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config;
20 changes: 12 additions & 8 deletions api/web/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
/** @type { import('@storybook/react').Preview } */
const preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
}
};

export default preview;
Loading

0 comments on commit 991f3dc

Please sign in to comment.