Skip to content

Commit

Permalink
chore: across the board tidy up (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
raksiv authored Dec 17, 2024
1 parent 71c32f3 commit d265478
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 26 deletions.
10 changes: 10 additions & 0 deletions v1/apollo-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ Follow the steps in the [installation guide](https://nitric.io/docs/installation
nitric start
```

Navigate to 'http://localhost:4001/' to access your Apollo server, where you can run an example GraphQL query.

```
query ExampleQuery {
books {
author
}
}
```

### Step 3:

Configure the region in nitric.aws.yaml and ensure you've got local AWS credentials to deploy your application.
Expand Down
2 changes: 1 addition & 1 deletion v1/apollo-server/nitric.aws.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The nitric provider to use
provider: nitric/aws@1.2.0
provider: nitric/aws@1.16.7
# The target aws region to deploy to
# See available regions:
# https://docs.aws.amazon.com/general/latest/gr/lambda-service.html
Expand Down
4 changes: 1 addition & 3 deletions v1/cloudflare-lb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

## Project Description

This project demonstrates how to combine the power of an auto-scaling api with an auto-scaling db.

Neon is a fully managed serverless PostgreSQL. Neon separates storage and compute and offers modern developer features such as serverless, branching, bottomless storage, and more.
This project demonstrates how to load balance the same application across multiple clouds with Nitric and Cloudflare.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion v1/cloudflare-lb/nitric.prod-aws.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
provider: nitric/aws@1.0.2
provider: nitric/aws@1.16.7
region: us-east-1
2 changes: 1 addition & 1 deletion v1/cloudflare-lb/nitric.prod-gcp.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
provider: nitric/gcp@1.0.2
provider: nitric/gcp@1.16.7
gcp-project-id:
region: us-west2
10 changes: 9 additions & 1 deletion v1/cloudflare-lb/nitric.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
name: cloudflare-lb
services:
- match: services/*.ts
- basedir: ""
match: services/*.ts
runtime: node
start: npm run dev:services $SERVICE_PATH
batch-services: []
runtimes:
node:
dockerfile: ./node.dockerfile
context: ""
args: {}
43 changes: 43 additions & 0 deletions v1/cloudflare-lb/node.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# syntax=docker/dockerfile:1
FROM node:22.4.1-alpine as build

ARG HANDLER

# Python and make are required by certain native package build processes in NPM packages.
RUN --mount=type=cache,sharing=locked,target=/etc/apk/cache \
apk --update-cache add git g++ make py3-pip

RUN yarn global add typescript @vercel/ncc

WORKDIR /usr/app

COPY package.json *.lock *-lock.json ./

RUN yarn import || echo ""

RUN --mount=type=cache,sharing=locked,target=/tmp/.yarn_cache \
set -ex && \
yarn install --production --prefer-offline --frozen-lockfile --cache-folder /tmp/.yarn_cache

RUN test -f tsconfig.json || echo "{\"compilerOptions\":{\"esModuleInterop\":true,\"target\":\"es2015\",\"moduleResolution\":\"node\"}}" > tsconfig.json

COPY . .

RUN --mount=type=cache,target=/tmp/ncc-cache \
ncc build ${HANDLER} -o lib/ -t

FROM node:22.4.1-alpine as final

RUN apk update && \
apk add --no-cache ca-certificates && \
update-ca-certificates

WORKDIR /usr/app

COPY . .

COPY --from=build /usr/app/node_modules/ ./node_modules/

COPY --from=build /usr/app/lib/ ./lib/

ENTRYPOINT ["node", "lib/index.js"]
9 changes: 9 additions & 0 deletions v1/cloudflare-lb/node.dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.nitric/
.git/
.idea/
.vscode/
.github/
*.dockerfile
*.dockerignore
node_modules/
README.md
4 changes: 3 additions & 1 deletion v1/cloudflare-lb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
},
"scripts": {
"deploy:lb": "ts-node ./infra/up.ts",
"destroy:lb": "ts-node ./infra/down.ts"
"destroy:lb": "ts-node ./infra/down.ts",
"dev:services": "nodemon -r dotenv/config"

}
}
3 changes: 2 additions & 1 deletion v1/flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ You'll also want to make sure the project's required dependencies have been inst

```bash
# install dependencies
dart pub get
flutter clean
flutter pub get

# run locally
nitric start
Expand Down
7 changes: 6 additions & 1 deletion v1/multi-language/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About Nitric

> ⚠️ Note: This repo contains features that require a minimum nitric CLI version of [1.52.0](https://github.com/nitrictech/cli/releases/tag/v1.52.0)
> ⚠️ Note: This repo contains features that requires a minimum nitric CLI version of [1.52.0](https://github.com/nitrictech/cli/releases/tag/v1.52.0)
This is a [Nitric](https://nitric.io) Golang project, but Nitric is a framework for rapid development of cloud-native and serverless applications in many languages.

Expand All @@ -29,8 +29,13 @@ To run this project you'll need the [Nitric CLI](https://nitric.io/docs/installa

```bash
# install dependencies
cd go
go mod tidy

cd..
cd ts
npm install

# run locally
nitric start
```
4 changes: 2 additions & 2 deletions v1/nitric-fastify/services/url.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Fastify from "fastify";
import { http, bucket, NodeApplication } from "@nitric/sdk";
import { http, bucket } from "@nitric/sdk";

const fastify = Fastify({
logger: true,
});

export const imgBucket = bucket("images").for("reading", "writing");
export const imgBucket = bucket("images").allow("read", "write");

interface Params {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion v1/nitric-hono/services/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function bootstrap(port: number) {
});
}

export const imgBucket = bucket("images").for("reading", "writing");
export const imgBucket = bucket("images").allow("read", "write");

app.get("/upload/:id", async (c) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion v1/nitric-koa/services/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from "koa";
import Router from "koa-router";
import { http, bucket } from "@nitric/sdk";

export const imgBucket = bucket("images").for("reading", "writing");
export const imgBucket = bucket("images").allow("read", "write");

const app = new Koa();
const router = new Router();
Expand Down
1 change: 1 addition & 0 deletions v1/nitric-monorepo/with-berry/apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@types/node": "^20.11.24",
"dotenv": "^16.4.5",
"nodemon": "^3.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
}
}
5 changes: 4 additions & 1 deletion v1/nitric-monorepo/with-berry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"workspaces": [
"apps/*",
"packages/*"
]
],
"devDependencies": {
"ts-node": "^10.9.2"
}
}
6 changes: 3 additions & 3 deletions v1/product-inventory/typescript/common/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ export const rekognition = new RekognitionClient({
});

// KV Stores
export const products = kv("products").for("setting", "getting");
export const products = kv("products").allow("get", "set");

// API
export const inventoryApi = api("inventory");

// Topics
export const inventoryPub = topic("topic").for("publishing");
export const inventoryPub = topic("topic").allow("publish");

export const inventorySub = topic("topic");

// Buckets
export const bucketName = "images";
export const imageBucket = bucket(bucketName).for("reading", "writing");
export const imageBucket = bucket(bucketName).allow("read", "write");

export const recognize = async (name: string) => {
const command = new DetectLabelsCommand({
Expand Down
2 changes: 1 addition & 1 deletion v1/python-prediction/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "python starter"

[packages]
nitric = "==1.0.2"
nitric = "==1.2.3"
numpy= "*"
num2words= "*"
keras= "2.15.1"
Expand Down
10 changes: 9 additions & 1 deletion v1/python-prediction/nitric.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
name: python-prediction
services:
- match: services/*.py
- basedir: ""
match: services/*.py
runtime: python
start: pipenv run dev $SERVICE_PATH
batch-services: []
runtimes:
python:
dockerfile: ./python.dockerfile
context: ""
args: {}
26 changes: 26 additions & 0 deletions v1/python-prediction/python.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.11-slim

# Setup the var pointing to the current nitric service being built
ARG HANDLER
ENV HANDLER=${HANDLER}

ENV PYTHONUNBUFFERED=TRUE
ENV PYTHONPATH="."

RUN apt-get update -y && \
apt-get install -y ca-certificates git && \
update-ca-certificates

RUN pip install --no-cache-dir --upgrade pip pipenv

COPY . .

# Guarantee lock file if we have a Pipfile and no Pipfile.lock
RUN (stat Pipfile && pipenv lock) || echo "No Pipfile found"

# Output a requirements.txt file for final module install if there is a Pipfile.lock found
RUN (stat Pipfile.lock && pipenv requirements > requirements.txt) || echo "No Pipfile.lock found"

RUN pip install --no-cache-dir -r requirements.txt

ENTRYPOINT python -u $HANDLER
6 changes: 6 additions & 0 deletions v1/python-prediction/python.dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.mypy_cache/
.nitric/
.venv/
nitric-spec.json
nitric.yaml
README.md
18 changes: 18 additions & 0 deletions v1/scheduled-report/python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "python starter"

[requires]
python_version = "3.12"

[packages]
nitric = "==1.2.3"
"google.auth" = "*"
google-api-python-client = "*"

[scripts]
dev = "watchmedo auto-restart -p '*.py' -R python -- -u"

[dev-packages]
watchdog = "*"
4 changes: 4 additions & 0 deletions v1/scheduled-report/python/nitric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: python-starter
services:
- match: services/*.py
start: pipenv run dev $SERVICE_PATH
2 changes: 1 addition & 1 deletion v1/scheduled-report/python/services/hello.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from nitric.resources import api, schedule
from nitric.application import Nitric
from nitric.context import HttpContext, IntervalContext, HttpMiddleware
from nitric.context import IntervalContext

from helpers.google import create_spreadsheet, generate_dummy_data, insert_data_into_spreadsheet, service_login, share_spreadsheet

Expand Down
2 changes: 1 addition & 1 deletion v1/scheduled-tasks/typescript/services/tidy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { schedule, bucket } from "@nitric/sdk";

const assets = bucket("assets").for("deleting");
const assets = bucket("assets").allow("delete");

// A schedule that cleans up files in a bucket every 3 days
schedule("tidy").every("3 days", async (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion v1/upload-secure-url/typescript/common/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { api, bucket } from "@nitric/sdk";

export const fileApi = api("main");

export const imgBucket = bucket("images").for("reading", "writing");
export const imgBucket = bucket("images").allow("read", "write");
4 changes: 2 additions & 2 deletions v1/user-onboarding/typescript/common/resources.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { api, kv, topic } from "@nitric/sdk";

// Stores
export const custStore = kv("customers").for("writing");
export const custStore = kv("customers").allow("set");
// API
export const custApi = api("public");
// Topics
export const custCreatePub = topic("created").for("publishing");
export const custCreatePub = topic("created").allow("publish");
export const custCreateSub = topic("created");
2 changes: 1 addition & 1 deletion v1/websockets/services/messaging.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { websocket, kv } from "@nitric/sdk";

// Initialize KV store for connections and a WebSocket
const kvStore = kv("connections").for("getting", "setting", "deleting");
const kvStore = kv("connections").allow("get", "set", "delete");
const socket = websocket("example-websocket");

// Handle new connections
Expand Down

0 comments on commit d265478

Please sign in to comment.