Skip to content

Commit

Permalink
Add new node-express sample (#551)
Browse files Browse the repository at this point in the history
Add new node-express sample


* Add node-express to accelerator resource definition files
  • Loading branch information
trisberg authored Jan 24, 2025
1 parent 0952d5a commit 6146539
Show file tree
Hide file tree
Showing 16 changed files with 1,270 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/tests/node-express-1/assertions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euxo pipefail
pushd $1

# Check that TP files exist
test -f .tanzu/config/node-express.yml
test -f tanzu.yml

npm install

popd
3 changes: 3 additions & 0 deletions .github/tests/node-express-1/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deploymentType": "tpfork8s"
}
9 changes: 9 additions & 0 deletions .github/tests/node-express-1/scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -euxo pipefail

pushd $1
grype=$2

$grype dir:. --fail-on high --config ${GITHUB_WORKSPACE}/.github/tests/.grype.yaml

popd
104 changes: 104 additions & 0 deletions node-express/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
16 changes: 16 additions & 0 deletions node-express/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MIT No Attribution

Copyright 2022-2024 VMware, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 changes: 81 additions & 0 deletions node-express/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# node-express

This is a starter ExpressJs project.
The server will be listening to request on port `3000`,
so you can test the server in a browser accessing `http://localhost:3000` or via `cURL`.

## Running the application locally

### Building locally
Before running the app, you need to install the dependencies by running this command:

```shell
npm install
```

### Running the application locally

Once the dependencies are installed, you can run it as a standalone app by running the following command from the root of the project:

```shell
npm run server
```

### Access the local application

Access the local application by opening your browser using the URL [http://localhost:3000](http://localhost:300) or use `cURL`.

<!--- #IF(#deploymentType == 'tpfork8s') -->
## Tanzu Platform deployment

### Prerequisites

1. Access to [Tanzu Platform](https://docs.vmware.com/en/VMware-Tanzu-Platform/index.html) configured for platform builds.
1. The latest Tanzu CLI and plugins from `vmware-tanzu/app-developer` group installed. Installation instructions can be found in the Tanzu Platform documentation: [Before you begin](https://docs.vmware.com/en/VMware-Tanzu-Platform/SaaS/create-manage-apps-tanzu-platform-k8s/getting-started-deploy-app-to-space.html#before-you-begin-0).
1. You have access to a space for your project and you have used `tanzu login` to authenticate and configure your current Tanzu context and set your project and space using `tanzu project use` and `tanzu space use` respectively.

### About the ContainerApp

Change to the root directory of your generated app.

The project contains a `ContainerApp` manifest file that can be used when building and deploying the app. To review the content of this file run:

```sh
cat .tanzu/config/node-express.yml
```

### Configure HTTP Ingress Routing

If you want to expose your application with a domain name and route traffic from the domain name to the deployed application, see [Adding HTTP Routing to an Application](https://docs.vmware.com/en/VMware-Tanzu-Platform/SaaS/create-manage-apps-tanzu-platform-k8s/how-to-ingress-to-app.html).

### Build and deploy the app

Change to the root directory of your generated app.

You can build and deploy the app with a single command.
Just run:

```sh
tanzu deploy
```

### Check the status of the app deployment

You can run this command to see the status of the app deployment:

```shell
tanzu apps get node-express
```

### Use port-forward to access an app instance

You can use the `app port-forward` command to access your app instance's endpoint.
Just select the instance you want when prompted.
Use the following command to start the port-forward:

```shell
tanzu app port-forward node-express --port 3000
```

Then you can access the app using http://localhost:3000.
<!--- #ENDIF -->
35 changes: 35 additions & 0 deletions node-express/accelerator.axl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
engine {

applyTo("README.md") {
TextPreprocessor()
}

// Add deployment artifacts
if (#deploymentType == 'tpfork8s') {
let uuid = T(java.util.UUID).randomUUID() in {
applyTo("deploy/tpfork8s/tanzu.yml") {
ReplaceSnippet(text: "node-express", with: #artifactId.toLowerCase())
OpenRewriteRecipe('org.openrewrite.yaml.ChangeValue', { oldKeyPath: "$.configuration.id", value: 'config-' + #uuid.toString() })
RewritePath(rewriteTo: #filename)
}
}
applyTo("deploy/tpfork8s/.tanzu/config/node-express.yml") {
ReplaceText({{text: "node-express", with: #artifactId.toLowerCase()}})
RewritePath(rewriteTo: '.tanzu/config/' + #artifactId.toLowerCase() + '.yml')
}
applyTo("deploy/tpfork8s/.tanzu/config/httproute-node-express.yml") {
ReplaceText({{text: "node-express", with: #artifactId.toLowerCase()}})
RewritePath(rewriteTo: '.tanzu/config/httproute-' + #artifactId.toLowerCase() + '.yml')
}
}
select(!"deploy/**")

// Update the artifact name as needed
applyTo("README.md" || "package.json") {
ReplaceText({{text: "node-express", with: #artifactId.toLowerCase()}})
}

// Create the provenance file
Provenance()

}
11 changes: 11 additions & 0 deletions node-express/accelerator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
accelerator:
options:
- name: deploymentType
inputType: select
label: Deployment type
choices:
- value: tpfork8s
text: Tanzu Platform for Kubernetes ContainerApp
- value: none
text: Skip deployment artifacts
defaultValue: tpfork8s
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
annotations:
apps.tanzu.vmware.com/promotable: ""
apps.tanzu.vmware.com/promote-group: ContainerApp/node-express
name: node-express-http-route
spec:
parentRefs:
- group: networking.tanzu.vmware.com
kind: Entrypoint
name: node-express
rules:
- backendRefs:
- kind: Service
name: node-express
port: 3000
12 changes: 12 additions & 0 deletions node-express/deploy/tpfork8s/.tanzu/config/node-express.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: apps.tanzu.vmware.com/v1
kind: ContainerApp
metadata:
name: node-express
spec:
build:
buildpacks: {}
path: ../..
ports:
- name: main
port: 3000
replicas: 1
7 changes: 7 additions & 0 deletions node-express/deploy/tpfork8s/tanzu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: config.tanzu.vmware.com/v1
configuration:
dev:
paths:
- .tanzu/config/
id: config-00000000-0000-0000-0000-000000000000
kind: TanzuConfig
Loading

0 comments on commit 6146539

Please sign in to comment.