Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rewrite API in NestJS #168

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
387b3cf
ensure that flask server doesn't crash locally when finding .DS-Store
Lms24 Oct 8, 2024
ac8d2a2
add packages endpoint
Lms24 Oct 8, 2024
2795c77
add healthz controller
Lms24 Oct 8, 2024
2ab1ab0
add marketing-slug endpoint
Lms24 Oct 8, 2024
4d74a6e
cleanup
Lms24 Oct 8, 2024
58f76c4
add /apps/:appId/:version endpoint w/ extended functionality
Lms24 Oct 9, 2024
dadc043
improve tests
Lms24 Oct 9, 2024
3e60611
add sdks endpoints
Lms24 Oct 14, 2024
fa176a3
add /aws-lambda-layers endpoint
Lms24 Oct 15, 2024
026b78e
add last /marketing-slugs/:slug endpoint
Lms24 Oct 15, 2024
9435503
consolidate packages and sdks service to registry service
Lms24 Oct 16, 2024
fcd043d
consolidate marketing service
Lms24 Oct 16, 2024
7d600de
consolidate apps service
Lms24 Oct 16, 2024
a742ff2
move registry service to common
Lms24 Oct 16, 2024
40a92fb
cleanup utils
Lms24 Oct 16, 2024
a5f0110
cleanup, typing, linting
Lms24 Oct 16, 2024
e05bac5
add ci for node api
Lms24 Oct 16, 2024
fda682c
update yarn lock
Lms24 Oct 16, 2024
ff63baf
add unit tests for package utils
Lms24 Oct 16, 2024
e03f8c1
adjust CI e2e tests
Lms24 Oct 16, 2024
cb161d8
adjust python api build/start scripts
Lms24 Oct 16, 2024
aedcb62
working dir
Lms24 Oct 16, 2024
f9e5240
fix test
Lms24 Oct 17, 2024
011f05c
add test for js browser
Lms24 Oct 17, 2024
78c9d0f
add sentry
Lms24 Oct 17, 2024
e0e7195
cleanup
Lms24 Oct 17, 2024
a01270a
don't upload source maps in CI
Lms24 Oct 17, 2024
1f118dd
add caching
Lms24 Oct 17, 2024
65e9d4b
make caching enabled depend on set env var
Lms24 Oct 17, 2024
d6c3f1d
wip test against 20k URLs
Lms24 Oct 18, 2024
c216cca
add cors
Lms24 Oct 23, 2024
2630082
custom cache interceptor
Lms24 Oct 23, 2024
b1ea447
20k url tests, pre-test refactor,
Lms24 Oct 23, 2024
e337516
handle 404s, align headers
Lms24 Oct 24, 2024
d2a978a
consistent headers in error responses, refactor normal e2e tests
Lms24 Oct 24, 2024
9f6a114
run tests in ci again
Lms24 Oct 28, 2024
9ced552
build node API before running e2e tests in CI
Lms24 Oct 28, 2024
e33aab9
remove state in registry service, fix url test
Lms24 Nov 4, 2024
67fb56b
align error handling, strict flag, ValueError
Lms24 Nov 4, 2024
8429639
lint
Lms24 Nov 4, 2024
8cd0caa
restore json file
Lms24 Nov 4, 2024
a168742
dynamic port
Lms24 Nov 4, 2024
e06c27f
volta, node 22
Lms24 Nov 4, 2024
64f1859
docker image for NestJS API
Lms24 Nov 4, 2024
149eefc
logger, port
Lms24 Nov 4, 2024
4b8f95f
adjust tests, port, use docker image in test
Lms24 Nov 4, 2024
81995c7
test coudbuild of node api
Lms24 Nov 4, 2024
70340c5
fix dockerignore and add install dev deps
Lms24 Nov 4, 2024
9c82082
fix missing dev deps
Lms24 Nov 4, 2024
2d869a0
tmp skip source map upload for docker container for now
Lms24 Nov 6, 2024
06aeaf6
add auth token
Lms24 Nov 7, 2024
fca50e8
secretenv
Lms24 Nov 7, 2024
811efa7
maybe add version helps?
Lms24 Nov 7, 2024
bdd3e11
swap secret versionName
Lms24 Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ cloudbuild.yaml
Dockerfile
Makefile
README.md
api-node/node_modules
api-node/dist
api-node/.env
.env
122 changes: 122 additions & 0 deletions .github/workflows/node-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Node API

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
setup:
name: Install Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
working-directory: ./api-node
run: yarn install --frozen-lockfile

build:
name: Build
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
working-directory: ./api-node
run: yarn install --frozen-lockfile
- name: Build
working-directory: ./api-node
run: yarn build:ci

lint:
name: Lint
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
working-directory: ./api-node
run: yarn install --frozen-lockfile
- name: Lint
working-directory: ./api-node
run: yarn lint

test:
name: Unit Tests
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
working-directory: ./api-node
run: yarn install --frozen-lockfile
- name: Run unit tests
working-directory: ./api-node
run: yarn test

e2e-test:
name: E2E Tests
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.cache/yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
working-directory: ./api-node
run: yarn install --frozen-lockfile
- name: Build Python API
working-directory: ./api-node
run: yarn python-api:build
- name: Build Node API
working-directory: ./api-node
run: yarn docker:build
- name: Run E2E tests
working-directory: ./api-node
run: yarn test:e2e:ci
10 changes: 10 additions & 0 deletions Dockerfile → Dockerfile.flask
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ EXPOSE 5030
ENTRYPOINT ["/docker-entrypoint.sh"]

CMD [ "mywsgi", "apiserver:app", "0.0.0.0:5030" ]
# To start this Docker container, use the following commands:

# Build the Docker image:
# docker build -t registry-api-server .

# Run the Docker container:
# docker run -p 5030:5030 registry-api-server

# These commands should be run from the directory containing this Dockerfile.
# The -p 5030:5030 flag maps the container's port 5030 to the host's port 5030.
54 changes: 54 additions & 0 deletions Dockerfile.nestjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM node:22-alpine

ENV \
REGISTRY_UID=10011 \
REGISTRY_GID=10011

# Create a new user and group with fixed uid/gid
RUN addgroup -S registry -g $REGISTRY_GID \
&& adduser -S registry -G registry -u $REGISTRY_UID

WORKDIR /work

# Copy package files
COPY api-node/package.json api-node/yarn.lock api-node/

# Remove dev dependencies
RUN cd api-node && yarn install --frozen-lockfile

COPY . .

# Set to production environment
# Importantly, after installing deps, otherwise dev deps aren't installed
ENV \
NODE_ENV=production \
PORT=5030

WORKDIR /work/api-node

# Build the application
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \
export SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) && \
yarn build

# Set ownership
RUN chown -R registry:registry ./

# Smoke test
RUN node -v && node dist/main.js --smoke

EXPOSE 5030

USER registry

CMD ["node", "dist/main.js"]
# To start this Docker container, use the following commands:

# Build the Docker image:
# docker build -t registry-api-nestjs-server -f Dockerfile.nestjs .

# Run the Docker container:
# docker run -p 503x:5030 registry-api-nestjs-server

# These commands should be run from the directory containing this Dockerfile.
# The -p 5030:5030 flag maps the container's port 5030 to the host's port 5030.
25 changes: 25 additions & 0 deletions api-node/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
},
};
58 changes: 58 additions & 0 deletions api-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

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

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

.urls.json
4 changes: 4 additions & 0 deletions api-node/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
85 changes: 85 additions & 0 deletions api-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Project setup

```bash
$ yarn install
```

## Compile and run the project

```bash
# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod
```

## Run tests

```bash
# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov
```

## Resources

Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
8 changes: 8 additions & 0 deletions api-node/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading
Loading