Skip to content

Commit

Permalink
init next.js code base
Browse files Browse the repository at this point in the history
  • Loading branch information
Assem-Uber committed Feb 15, 2024
1 parent 7155ab0 commit ed3b2bf
Show file tree
Hide file tree
Showing 680 changed files with 4,441 additions and 69,668 deletions.
4 changes: 2 additions & 2 deletions .docker_env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NODE_ENV=development
CADENCE_TCHANNEL_PEERS="127.0.0.1:7933"
CADENCE_TCHANNEL_SERVICE=cadence-frontend
CADENCE_GRPC_PEERS="127.0.0.1:7833"
CADENCE_GRPC_SERVICE=cadence-frontend
CADENCE_WEB_PORT=8088
CADENCE_EXTERNAL_SCRIPTS=""
ENABLE_AUTH=false
Expand Down
44 changes: 38 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
node_modules/
npm-debug.log
dist/
.vscode
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
.idea
server/idl
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

#idl
src/idl
21 changes: 0 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,3 @@ You also need to run [cadence-server](https://github.com/uber/cadence) locally o
## Working with the source code

Follow [this great guide](https://gist.github.com/Chaser324/ce0505fbed06b947d962) on how to work with a GitHub fork and submit a pull request.

## Building

The standard node.js workflow is used here. Use Node version 10. Version 12 is unable to install the
[farmhash](https://www.npmjs.com/package/farmhash) package.

```
npm i
npm run dev # webpack hot reload environment
npm start # for production
```

## Testing

Start up the webserver for testing via:

```
npm run test-server
```

The open `localhost:8090` in the browser of your choice, or use `npm test` to run it with [mocha-chrome](https://www.npmjs.com/package/mocha-chrome) from the command line. This runs the tests via Chrome in headless mode and shows the results in your terminal.
86 changes: 62 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
FROM node:fermium-bullseye AS BUILD_IMAGE
FROM node:18-alpine AS base

### Build step ###
WORKDIR /usr/build
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Bundle app source
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


FROM base AS dev

WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .



# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Install app dependencies
RUN npm install --no-save --production --unsafe-perm
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi


# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Bundle the client code
RUN npm run build-production

# switch to lite version of node
FROM node:fermium-bullseye-slim
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

### Run step ###
WORKDIR /usr/app
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# copy from build image
COPY --from=BUILD_IMAGE /usr/build/server.js ./
COPY --from=BUILD_IMAGE /usr/build/webpack.config.js ./
COPY --from=BUILD_IMAGE /usr/build/dist ./dist
COPY --from=BUILD_IMAGE /usr/build/server ./server
COPY --from=BUILD_IMAGE /usr/build/node_modules ./node_modules
USER nextjs

# setup production environment variables
ENV NODE_ENV=production
ENV NPM_CONFIG_PRODUCTION=true

# run node server
EXPOSE 8088
CMD [ "node", "server.js" ]
CMD ["node", "server.js"]
94 changes: 22 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,36 @@
# Cadence Web UI

[![Build Status](https://github.com/uber/cadence-web/actions/workflows/build.yml/badge.svg)](https://github.com/uber/cadence-web/actions/workflows/build.yml) [![Docker Status](https://github.com/uber/cadence-web/actions/workflows/docker_publish.yml/badge.svg)](https://hub.docker.com/r/ubercadence/web/tags)

Cadence is a distributed, scalable, durable, and highly available orchestration engine we developed at Uber Engineering to execute asynchronous long-running business logic in a scalable and resilient way.

This web UI is used to view workflows from [Cadence][cadence], see what's running, and explore and debug workflow executions.

![Demo Usage](https://s3-us-west-2.amazonaws.com/uber-common-public/svc-cadence-web/cadence-web.demo.gif)
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

### Configuration

Set these environment variables if you need to change their defaults

| Variable | Description | Default |
| -------------------------- | -------------------------------------------- | ---------------- |
| CADENCE_TCHANNEL_PEERS | Comma-delmited list of tchannel peers | 127.0.0.1:7933 |
| CADENCE_TCHANNEL_SERVICE | Name of the cadence tchannel service to call | cadence-frontend |
| CADENCE_WEB_PORT | HTTP port to serve on | 8088 |
| CADENCE_EXTERNAL_SCRIPTS | Addtional JavaScript tags to serve in the UI | |
| ENABLE_AUTH | Enable auth feature | false |
| AUTH_TYPE | concurrently supports ADMIN_JWT | '' |
| AUTH_ADMIN_JWT_PRIVATE_KEY | JWT signing private key for ADMIN_JWT type | '' |

### Running locally

`cadence-web` requires node `v10.22.1` or greater to be able to run correctly. `cadence-web` uses all the standard [npm scripts](https://docs.npmjs.com/misc/scripts) to install dependencies, run the
server, and run tests.

To provide a consistent environment we recommend using docker in development. We provide a default configuration for remote containers using docker-compose.

#### Using VSCode Dev Containers
First, run the development server:

1. Set up the [Remote Containers plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) in VSCode.
2. Open the cadence-web directory in VSCode.
3. Use the Command Palette to select the 'Reopen folder in Container' option. `npm install` should run automatically in the container upon doing so.
4. Run the app in the container with `npm run dev`.
5. Open `localhost:8088` (or the custom Cadence Web port you have defined) to load the webapp.

#### Using docker-compose to start the dev container

To start local server with live reload on code change you can run `docker-compose up`.

For development and contributing to `cadence-web`, please see the [contributing guide](https://github.com/uber/cadence-web/blob/master/CONTRIBUTING.md).

You may also use docker by pulling [ubercadence/web](https://hub.docker.com/r/ubercadence/web/). It is also included in the Cadence server's [local docker setup](https://github.com/uber/cadence/tree/master/docker).

### API

If you need to extend `cadence-web` to add middleware to the server, you can install `cadence-web` as a dependecy, and it will export the [Koa](http://koajs.com/) web server that has not yet been started or configured. It includes an additional `init` function that will then compose the built-in middleware. This gives you an option to add middleware before or after you call `init` so it will add the middleware at the beginning or the end of the chain, respectively.

#### `init(options)`
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

All options are optional.
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

`useWebpack`: If `true`, starts webpack and adds the middleware, otherwise if `false`, it assumes the UI bundle was already built and serves it statically. Defaults to `process.env.NODE_ENV === 'production'`.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

`logErrors`: If `true`, thrown errors are logged to `console.error`. Defaults to `true`.
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

For example, here is how you would add a request count metric using `uber-statsd-client`:
## Learn More

```javascript
var app = require('cadence-web');
var createStatsd = require('uber-statsd-client');
var sdc = createStatsd({
host: 'statsd.example.com',
});
To learn more about Next.js, take a look at the following resources:

app
.use(async function(ctx, next) {
sdc.increment('http.request');
await next();
})
.init()
.listen(7000);
```
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

The [webpack](https://webpack.js.org/) configuration is also exported as `webpackConfig`, and can be modified before calling `init()`.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

### Licence
## Deploy on Vercel

MIT License, please see [LICENSE](https://github.com/uber/cadence-web/blob/master/LICENSE) for details.
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

[cadence]: https://github.com/uber/cadence
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
50 changes: 0 additions & 50 deletions babel.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions client/.eslintrc

This file was deleted.

Loading

0 comments on commit ed3b2bf

Please sign in to comment.