Add node-api template

This commit is contained in:
2025-12-09 11:22:07 +00:00
commit e5234d0b3d
7 changed files with 173 additions and 0 deletions

View 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

View File

@@ -0,0 +1,3 @@
node_modules/
.env
*.log

View 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"]

View 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 }}

View 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 }}"
}
}

View 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}`);
});