Add node-api template
This commit is contained in:
27
templates/node-api/skeleton/.drone.yml
Normal file
27
templates/node-api/skeleton/.drone.yml
Normal file
@@ -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
|
||||
3
templates/node-api/skeleton/.gitignore
vendored
Normal file
3
templates/node-api/skeleton/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
.env
|
||||
*.log
|
||||
12
templates/node-api/skeleton/Dockerfile
Normal file
12
templates/node-api/skeleton/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM node:${{ values.nodeVersion }}-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm install --production
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm", "start"]
|
||||
12
templates/node-api/skeleton/catalog-info.yaml
Normal file
12
templates/node-api/skeleton/catalog-info.yaml
Normal file
@@ -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 }}
|
||||
14
templates/node-api/skeleton/package.json
Normal file
14
templates/node-api/skeleton/package.json
Normal file
@@ -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 }}"
|
||||
}
|
||||
}
|
||||
16
templates/node-api/skeleton/src/index.js
Normal file
16
templates/node-api/skeleton/src/index.js
Normal file
@@ -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}`);
|
||||
});
|
||||
89
templates/node-api/template.yaml
Normal file
89
templates/node-api/template.yaml
Normal file
@@ -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 }}
|
||||
Reference in New Issue
Block a user