Skip to content

Commit

Permalink
Add scaffolder templates
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindnswamy committed Dec 6, 2023
1 parent 8e6c830 commit 8ff2567
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scaffolder-templates/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
9 changes: 9 additions & 0 deletions scaffolder-templates/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var app = express();
app.get('/', function (req, res) {
console.log('🔍 Serving endpoint "/"');
res.send(returnHelloMessage());
});
app.listen(3000, function () {
console.log('🚀 Server is started and is listening on port 3000!');
});
20 changes: 20 additions & 0 deletions scaffolder-templates/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "js-server",
"version": "1.0.0",
"description": "A simple REST server written in node.js",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "mocha --recursive test",
"lint": "eslint --ext=.jsx,.js,.tsx,.ts"
},
"author": "OpsVerse",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"eslint": "^8.55.0",
"mocha": "^10.2.0"
}
}
2 changes: 2 additions & 0 deletions scaffolder-templates/skeleton/${{values.artifact_id}}.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec node /usr/src/app/app.js "$@"
10 changes: 10 additions & 0 deletions scaffolder-templates/skeleton/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 2
continuation_indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
19 changes: 19 additions & 0 deletions scaffolder-templates/skeleton/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://hub.docker.com/_/node
FROM node:18

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install production dependencies.
RUN npm install --only=production

# Copy local code to the container image.
COPY . .

# Run the web service on container startup.
CMD [ "node", "app.js" ]
3 changes: 3 additions & 0 deletions scaffolder-templates/skeleton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ${{values.component_id}}

${{values.description}}
14 changes: 14 additions & 0 deletions scaffolder-templates/skeleton/catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${{values.component_id | dump}}
{%- if values.description %}
description: ${{values.description | dump}}
{%- endif %}
annotations:
github.com/project-slug: ${{values.destination.owner + "/" + values.destination.repo}}
backstage.io/techdocs-ref: dir:.
spec:
type: service
lifecycle: experimental
owner: ${{values.owner | dump}}
28 changes: 28 additions & 0 deletions scaffolder-templates/skeleton/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## ${{ values.component_id }}

${{ values.description }}

## Getting started

Start write your documentation by adding more markdown (.md) files to this folder (/docs) or replace the content in this file.

## Table of Contents

The Table of Contents on the right is generated automatically based on the hierarchy
of headings. Only use one H1 (`#` in Markdown) per file.

## Site navigation

For new pages to appear in the left hand navigation you need edit the `mkdocs.yml`
file in root of your repo. The navigation can also link out to other sites.

Alternatively, if there is no `nav` section in `mkdocs.yml`, a navigation section
will be created for you. However, you will not be able to use alternate titles for
pages, or include links to other sites.

Note that MkDocs uses `mkdocs.yml`, not `mkdocs.yaml`, although both appear to work.
See also <https://www.mkdocs.org/user-guide/configuration/>.

## Support

That's it. If you need support, reach out in [#docs-like-code](https://discord.com/channels/687207715902193673/714754240933003266) on Discord.
8 changes: 8 additions & 0 deletions scaffolder-templates/skeleton/mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
site_name: ${{values.component_id | dump}}
site_description: ${{values.description | dump}}

nav:
- Introduction: index.md

plugins:
- techdocs-core
20 changes: 20 additions & 0 deletions scaffolder-templates/skeleton/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": ${{values.artifact_id}},
"version": "1.0.0",
"description": ${{values.description}},
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "mocha --recursive test",
"lint": "eslint --ext=.jsx,.js,.tsx,.ts"
},
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"eslint": "^8.55.0",
"mocha": "^10.2.0"
}
}

5 changes: 5 additions & 0 deletions scaffolder-templates/src/hello.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const returnHelloMessage = async () => {
return "Hello World!";
}

module.exports.saveUser = returnHelloMessage;
90 changes: 90 additions & 0 deletions scaffolder-templates/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: node-js-server-template
title: Node.js REST Service
description: Create a simple RESTful microservice using Node.js (express)
tags:
- recommended
- node.js
- REST
- express
spec:
owner: [email protected]
type: service

parameters:
- title: Provide some simple information
required:
- component_id
- owner
- java_package_name
properties:
component_id:
title: Name
type: string
description: Unique name of the component
ui:field: EntityNamePicker
description:
title: Description
type: string
description: Help others understand what this website is for.
owner:
title: Owner
type: string
description: Owner of the component
ui:field: OwnerPicker
ui:options:
allowedKinds:
- Group
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
ui:field: RepoUrlPicker
ui:options:
allowedHosts:
- github.com

steps:
- id: template
name: Fetch Skeleton + Template
action: fetch:template
input:
url: ./skeleton
copyWithoutRender:
- .github/workflows/*
values:
component_id: ${{ parameters.component_id }}
description: ${{ parameters.description }}
artifact_id: ${{ parameters.component_id }}
java_package_name: ${{ parameters.java_package_name }}
owner: ${{ parameters.owner }}
destination: ${{ parameters.repoUrl | parseRepoUrl }}
http_port: 8080

- id: publish
name: Publish
action: publish:github
input:
allowedHosts: ["github.com"]
description: This is ${{ parameters.component_id }}
repoUrl: ${{ parameters.repoUrl }}

- id: register
name: Register
action: catalog:register
input:
repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
catalogInfoPath: "/catalog-info.yaml"

output:
links:
- title: Repository
url: ${{ steps.publish.output.remoteUrl }}
- title: Open in catalog
icon: catalog
entityRef: ${{ steps.register.output.entityRef }}
8 changes: 8 additions & 0 deletions scaffolder-templates/test/hello.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe("Hello world Service Unit Tests", function () {
describe("Return 'Hello World' message functionality", function () {
it("should successfully return 'Hello World'", async function () {
});
it("should throw an error message", async function () {
});
});
});

0 comments on commit 8ff2567

Please sign in to comment.