commit e5234d0b3d6c4b341efcfeb5521c458fcdf5881c Author: RBER Admin Date: Tue Dec 9 11:22:07 2025 +0000 Add node-api template diff --git a/templates/node-api/skeleton/.drone.yml b/templates/node-api/skeleton/.drone.yml new file mode 100644 index 0000000..4c47f2e --- /dev/null +++ b/templates/node-api/skeleton/.drone.yml @@ -0,0 +1,27 @@ +kind: pipeline +type: kubernetes +name: build-${{ values.name }} + +steps: + - name: test + image: node:${{ values.nodeVersion }} + commands: + - npm install + - npm test + + - name: build-push + image: gcr.io/kaniko-project/executor:debug + environment: + HARBOR_USERNAME: + from_secret: harbor_username + HARBOR_PASSWORD: + from_secret: harbor_password + commands: + - echo "{\"auths\":{\"registre.rber.bj\":{\"username\":\"$HARBOR_USERNAME\",\"password\":\"$HARBOR_PASSWORD\"}}}" > /kaniko/.docker/config.json + - /kaniko/executor --context=/drone/src --dockerfile=/drone/src/Dockerfile --destination=registre.rber.bj/${{ values.university }}/${{ values.name }}:${DRONE_COMMIT_SHA:0:8} --destination=registre.rber.bj/${{ values.university }}/${{ values.name }}:latest + +trigger: + branch: + - main + event: + - push diff --git a/templates/node-api/skeleton/.gitignore b/templates/node-api/skeleton/.gitignore new file mode 100644 index 0000000..2e8157a --- /dev/null +++ b/templates/node-api/skeleton/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.env +*.log diff --git a/templates/node-api/skeleton/Dockerfile b/templates/node-api/skeleton/Dockerfile new file mode 100644 index 0000000..b439deb --- /dev/null +++ b/templates/node-api/skeleton/Dockerfile @@ -0,0 +1,12 @@ +FROM node:${{ values.nodeVersion }}-alpine + +WORKDIR /app + +COPY package*.json ./ +RUN npm install --production + +COPY . . + +EXPOSE 3000 + +CMD ["npm", "start"] diff --git a/templates/node-api/skeleton/catalog-info.yaml b/templates/node-api/skeleton/catalog-info.yaml new file mode 100644 index 0000000..02aaf10 --- /dev/null +++ b/templates/node-api/skeleton/catalog-info.yaml @@ -0,0 +1,12 @@ +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: ${{ values.name }} + description: ${{ values.description }} + annotations: + github.com/project-slug: ${{ values.university }}/${{ values.name }} + backstage.io/techdocs-ref: dir:. +spec: + type: service + lifecycle: experimental + owner: ${{ values.university }} diff --git a/templates/node-api/skeleton/package.json b/templates/node-api/skeleton/package.json new file mode 100644 index 0000000..4dcdbb6 --- /dev/null +++ b/templates/node-api/skeleton/package.json @@ -0,0 +1,14 @@ +{ + "name": "${{ values.name }}", + "version": "1.0.0", + "description": "${{ values.description }}", + "main": "src/index.js", + "scripts": { + "start": "node src/index.js", + "dev": "node --watch src/index.js", + "test": "echo \"No tests yet\" && exit 0" + }, + "engines": { + "node": ">=${{ values.nodeVersion }}" + } +} diff --git a/templates/node-api/skeleton/src/index.js b/templates/node-api/skeleton/src/index.js new file mode 100644 index 0000000..f87d1e5 --- /dev/null +++ b/templates/node-api/skeleton/src/index.js @@ -0,0 +1,16 @@ +const http = require('http'); + +const PORT = process.env.PORT || 3000; + +const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ + service: '${{ values.name }}', + university: '${{ values.university }}', + status: 'running' + })); +}); + +server.listen(PORT, () => { + console.log(`${{ values.name }} running on port ${PORT}`); +}); diff --git a/templates/node-api/template.yaml b/templates/node-api/template.yaml new file mode 100644 index 0000000..3017b74 --- /dev/null +++ b/templates/node-api/template.yaml @@ -0,0 +1,89 @@ +apiVersion: scaffolder.backstage.io/v1beta3 +kind: Template +metadata: + name: node-api-template + title: API Node.js + description: Créer une API Node.js avec pipeline CI/CD complet + tags: + - nodejs + - api + - recommended +spec: + owner: rber + type: service + + parameters: + - title: Informations du projet + required: + - name + - description + - university + properties: + name: + title: Nom du projet + type: string + description: Nom unique du projet (minuscules, tirets autorisés) + pattern: '^[a-z0-9-]+$' + description: + title: Description + type: string + description: Brève description du projet + university: + title: Université + type: string + description: Sélectionne ton université + enum: + - unstim + - uac + - una + - up + enumNames: + - UNSTIM + - UAC + - UNA + - UP + + - title: Configuration technique + properties: + nodeVersion: + title: Version Node.js + type: string + default: "18" + enum: + - "18" + - "20" + + steps: + - id: fetch + name: Générer le code + action: fetch:template + input: + url: ./skeleton + values: + name: ${{ parameters.name }} + description: ${{ parameters.description }} + university: ${{ parameters.university }} + nodeVersion: ${{ parameters.nodeVersion }} + + - id: publish + name: Publier sur Gitea + action: publish:gitea + input: + repoUrl: git.rber.bj?owner=${{ parameters.university }}&repo=${{ parameters.name }} + description: ${{ parameters.description }} + defaultBranch: main + repoVisibility: internal + + - id: register + name: Enregistrer dans le catalogue + action: catalog:register + input: + repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }} + catalogInfoPath: /catalog-info.yaml + + output: + links: + - title: Ouvrir le repository + url: ${{ steps['publish'].output.remoteUrl }} + - title: Voir dans le catalogue + entityRef: ${{ steps['register'].output.entityRef }}