Skip to content

Commit 2643f6d

Browse files
authored
add monorepo example with yarn berry (#46)
1 parent 9e8a8e8 commit 2643f6d

File tree

23 files changed

+1200
-0
lines changed

23 files changed

+1200
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ When utilizing the `nitric new` command to initiate a new project, the available
6161
| [nitric-koa](./v1/nitric-koa/) | A secure URL upload demonstrating usage with Nitric and KOA framework | Existing API Frameworks, Storage |
6262
| [nitric-hono](./v1/nitric-hono/) | A secure URL upload demonstrating usage with Nitric and Hono | Existing API Frameworks, Storage |
6363
| [nitric-fastify](./v1/nitric-fastify/) | A secure URL upload demonstrating usage with Nitric and fastify | Existing API Frameworks, Storage |
64+
| [nitric-monorepo](./v1/nitric-monorepo/) | Several monorepo examples that contains a Next.js app, a nitric API and shared packages | APIs |
6465
| [websockets](./v1/websockets/) | A basic websockets example | APIs, Key Value Stores |
6566
| [real-time-chat](./v1/realtime-chat-app/) | A realtime chat using Websockets, Next.js, Nitric and Clerk Auth | APIs, WebSockets, Frontend, Auth |
6667
| [scheduled-report](./v1/scheduled-report/) | A scheduled report generated with Google Sheets and shared with Google Drive | APIs, Schedules |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{js,json,yml}]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.yarn/** linguist-vendored
2+
/.yarn/releases/* binary
3+
/.yarn/plugins/**/* binary
4+
/.pnp.* binary linguist-generated
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.yarn/*
2+
!.yarn/patches
3+
!.yarn/plugins
4+
!.yarn/releases
5+
!.yarn/sdks
6+
!.yarn/versions
7+
8+
# Swap the comments on the following lines if you wish to use zero-installs
9+
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
10+
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
11+
12+
#!.yarn/cache
13+
.pnp.*
14+
node_modules
15+
16+
**/dist

v1/nitric-monorepo/with-berry/.yarn/releases/yarn-berry.cjs

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarnPath: ".yarn/releases/yarn-berry.cjs"
2+
nodeLinker: node-modules
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<p align="center">
2+
<a href="https://nitric.io">
3+
<img src="https://raw.githubusercontent.com/nitrictech/nitric/main/docs/assets/nitric-logo.svg" width="120" alt="Nitric Logo"/>
4+
</a>
5+
</p>
6+
7+
<p align="center">
8+
A fast & fun way to build portable cloud-native applications
9+
</p>
10+
11+
<p align="center">
12+
<img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/nitrictech/nitric?sort=semver">
13+
<a href="https://twitter.com/nitric_io">
14+
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/nitric_io?label=Follow&style=social">
15+
</a>
16+
<a href="https://nitric.io/chat"><img alt="Discord" src="https://img.shields.io/discord/955259353043173427?label=discord"></a>
17+
</p>
18+
19+
## Project Description
20+
21+
Creates a server app that contains an API, this app utilizes [yarn Berry workspaces](https://yarnpkg.com/features/workspaces) to share packages. A custom runtime is used to build the service image, see the [Dockerfile](./apps/server/Dockerfile) for details.
22+
23+
## Usage
24+
25+
### Step 1: Install Nitric
26+
27+
Follow the steps in the [installation guide](https://nitric.io/docs/installation)
28+
29+
### Step 2: Run your Nitric project locally
30+
31+
```bash
32+
yarn install
33+
```
34+
35+
```bash
36+
cd apps/server
37+
nitric start
38+
```
39+
40+
## About Nitric
41+
42+
[Nitric](https://nitric.io) is a framework for rapid development of cloud-native and serverless applications. Define your apps in terms of the resources they need, then write the code for serverless function based APIs, event subscribers and scheduled jobs.
43+
44+
Apps built with Nitric can be deployed to AWS, Azure or Google Cloud all from the same code base so you can focus on your products, not your cloud provider.
45+
46+
Nitric makes it easy to:
47+
48+
- Create smart serverless functions and APIs
49+
- Build reliable distributed apps that use events and/or queues
50+
- Securely store and retrieve secrets
51+
- Read and write files from buckets
52+
53+
## Documentation
54+
55+
The full documentation is available at [nitric.io/docs](https://nitric.io/docs).
56+
57+
We're completely open-source and encourage [code contributions](https://nitric.io/docs/contributions).
58+
59+
## Get in touch
60+
61+
- Ask questions in [GitHub discussions](https://github.com/nitrictech/nitric/discussions)
62+
63+
- Find us on [Twitter](https://twitter.com/nitric_io)
64+
65+
- Send us an [email](mailto:[email protected])
66+
67+
- Jump into our [Discord server](https://nitric.io/chat)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.nitric/
3+
.npmrc
4+
git.store
5+
lib
6+
.env
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM node:alpine AS builder
2+
ARG PACKAGE_SCOPE
3+
ARG HANDLER
4+
5+
# Python and make are required by certain native package build processes in NPM packages.
6+
RUN --mount=type=cache,sharing=locked,target=/etc/apk/cache \
7+
apk --update-cache add git g++ make py3-pip
8+
9+
# # Set working directory
10+
WORKDIR /app
11+
12+
# node_modules is ignored in .dockerignore
13+
COPY . .
14+
15+
RUN yarn workspaces focus ${PACKAGE_SCOPE} --production
16+
17+
# Create a variable for the app path
18+
ARG APP_PATH=/app/apps/${PACKAGE_SCOPE}
19+
20+
# Build the app using ncc, and exclude the prisma client for prisma support https://github.com/prisma/prisma/issues/16901#issuecomment-1362940774
21+
RUN yarn dlx -p @vercel/ncc -p typescript ncc build ${APP_PATH}/${HANDLER} -m --v8-cache -o ${APP_PATH}/lib/ -e .prisma/client -e @prisma/client -t
22+
23+
FROM node:alpine AS runner
24+
ARG PACKAGE_SCOPE
25+
WORKDIR /app
26+
27+
RUN apk update && \
28+
apk add --no-cache ca-certificates && \
29+
update-ca-certificates
30+
31+
COPY --from=builder /app/apps/${PACKAGE_SCOPE}/lib .
32+
33+
# prisma fix for docker installs: https://github.com/prisma/docs/issues/4365
34+
RUN test -d ./prisma && yarn dlx -p prisma prisma generate || echo "";
35+
36+
ENTRYPOINT ["node", "index.js"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules/

0 commit comments

Comments
 (0)