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: add untp test playground poc #169

Merged
merged 12 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ __tests__
scripts
jest.config.*
jest.*.config.*
integration
integration
node_modules
.next
packages/untp-playground/infra
28 changes: 20 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"root": true,
// TODO: Enable linting for documentation folder
"ignorePatterns": ["documentation"],
"plugins": ["@typescript-eslint", "prettier"],
"ignorePatterns": [
"documentation"
],
"plugins": [
"@typescript-eslint",
"prettier"
],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
Expand All @@ -11,9 +16,8 @@
],
"parserOptions": {
"project": [
"./packages/tsconfig.settings.json",
"./packages/*/tsconfig.json"
]
"./packages/*/tsconfig.json"
]
},
"rules": {
"no-console": "warn",
Expand All @@ -27,14 +31,22 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-unused-vars": "off",
"prefer-const": "off"
},
"overrides": [
{
"files": ["*.js"],
"files": [
"*.js"
],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
}
111 changes: 111 additions & 0 deletions .github/workflows/ci_cd-untp-playground.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: 'CI/CD UNTP Playgroud'

on:
workflow_dispatch:
push:
branches:
- next
- 'cd/**'
paths:
- 'packages/untp-playground/**'
- '.github/workflows/ci_cd-untp-playground.yml'

jobs:
#todo: add running tests job
deploy_test:
if: github.repository_owner == 'uncefact' && ( github.ref == 'refs/heads/next' || startsWith(github.ref, 'refs/heads/cd/') )
concurrency:
group: untp-plaground-${{github.ref}}

permissions:
id-token: write
contents: read

name: Deploy to Test
environment:
name: test
url: https://test.uncefact.org/test-untp-playground

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: aws_login_uncefact
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{env.AWS_ROLE_TO_ASSUME}}
aws-region: us-east-1
env:
AWS_ROLE_TO_ASSUME: ${{ secrets.UNCEFACT_AWS_ROLE_TO_ASSUME}}


- name: Setup Node LTS ✨
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn

- name: Installing dependencies πŸ“¦οΈ
run: yarn install
working-directory: ./packages/untp-playground/infra

- name: Deploy Stack
uses: pulumi/actions@v5
with:
command: up
stack-name: ${{ env.STACK_NAME}}
work-dir: ./packages/untp-playground/infra
env:
NEXT_PUBLIC_BASE_PATH: /test-untp-playground
NEXT_PUBLIC_ASSET_PREFIX: /test-untp-playground
NEXT_PUBLIC_IMAGE_PATH: /test-untp-playground/_next/image
STACK_NAME: test

deploy_prod:
if: github.repository_owner == 'uncefact' && github.ref_type == 'tag' && github.event_name == 'workflow_dispatch'
concurrency:
group: untp-plaground-${{github.ref}}

permissions:
id-token: write
contents: read

name: Deploy to Prod
environment:
name: production
url: https://test.uncefact.org/untp-playground

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: aws_login_uncefact
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{env.AWS_ROLE_TO_ASSUME}}
aws-region: us-east-1
env:
AWS_ROLE_TO_ASSUME: ${{ secrets.UNCEFACT_AWS_ROLE_TO_ASSUME}}


- name: Setup Node LTS ✨
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn

- name: Installing dependencies πŸ“¦οΈ
run: yarn install
working-directory: ./packages/untp-playground/infra

- name: Deploy Stack
uses: pulumi/actions@v5
with:
command: up
stack-name: ${{ env.STACK_NAME}}
work-dir: ./packages/untp-playground/infra
env:
NEXT_PUBLIC_BASE_PATH: /untp-playground
NEXT_PUBLIC_ASSET_PREFIX: /untp-playground
NEXT_PUBLIC_IMAGE_PATH: /untp-playground/_next/image
STACK_NAME: prod
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
yarn lint
42 changes: 24 additions & 18 deletions app-config.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ services:
- ./documentation:/app
- /app/node_modules

untp-playground:
build: packages/untp-playground
ports:
- '4000:3000'
volumes:
- ./packages/untp-playground:/untp-playground
- /untp-playground/node_modules
environment:
- NODE_ENV=development

vckit-api:
image: ghcr.io/uncefact/project-vckit:sha-8a1a7ea@sha256:21414e4cdfd6b045f57667408256d4951c1d14d0648151ededf3107716b67b5f
env_file:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"copy-config": "cp app-config.json packages/mock-app/src/constants/app-config.json && cp app-config.json packages/components/src/constants/app-config.json",
"start": "yarn copy-config && cd packages/mock-app && yarn start",
"start:untp-playground": "cd packages/untp-playground && PORT=4001 yarn dev",
"build": "yarn copy-config && yarn build:services && yarn build:components && yarn build:untp-test-suite",
"build:services": "cd packages/services && yarn run build",
"build:components": "cd packages/components && yarn run build",
Expand All @@ -27,7 +28,7 @@
"upgrade:packages": "yarn -r --stream upgrade --latest",
"version": "lerna version",
"prepare": "husky install",
"lint": " yarn eslint packages"
"lint": "cross-env NODE_OPTIONS=--max-old-space-size=8192 yarn eslint packages"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
42 changes: 24 additions & 18 deletions packages/components/src/constants/app-config.json

Large diffs are not rendered by default.

42 changes: 24 additions & 18 deletions packages/mock-app/src/constants/app-config.json

Large diffs are not rendered by default.

28 changes: 0 additions & 28 deletions packages/tsconfig.settings.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/untp-playground/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
infra
40 changes: 40 additions & 0 deletions packages/untp-playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

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

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
73 changes: 73 additions & 0 deletions packages/untp-playground/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# syntax=docker.io/docker/dockerfile:1

FROM node:20.12.2-alpine AS base

# 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

ENV NEXT_PUBLIC_BASE_PATH=/
ENV NEXT_PUBLIC_ASSET_PREFIX=/

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
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


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

# Add build args without defaults
ARG NEXT_PUBLIC_BASE_PATH
ARG NEXT_PUBLIC_ASSET_PREFIX
ARG NEXT_PUBLIC_IMAGE_PATH

ENV NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH}
ENV NEXT_PUBLIC_ASSET_PREFIX=${NEXT_PUBLIC_ASSET_PREFIX}
ENV NEXT_PUBLIC_IMAGE_PATH=${NEXT_PUBLIC_IMAGE_PATH}

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

# 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

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
32 changes: 32 additions & 0 deletions packages/untp-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## untp-playground

## Getting Started

```bash
yarn dev
```

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

## Deployment

We use Pulumi and GitHub actions to deploy the app. The following env variables needs to be set to define basePath in order to it work with the existing CloudFront Distribution:
```
NEXT_PUBLIC_BASE_PATH: /untp-playground
NEXT_PUBLIC_ASSET_PREFIX: /untp-playground
NEXT_PUBLIC_IMAGE_PATH: /untp-playground/_next/image
```

GitHub OIDC is configured in AWS account for GitHub Actions workflow to assume and run the deployment using Pulumi. The role to assume is set as a repository secret `UNCEFACT_AWS_ROLE_TO_ASSUME`.
Pulume security prodiver for config is set to awskms.
The same backend state bucket and kms key are used for both test and prod Pulumi stacks.

End-points:

1. test - https://test.uncefact.org/test-untp-playground
1. production - https://test.uncefact.org/untp-playground

`next` branch is getting automatically deployed to test, tag is manually deployed to production.
In future production enddpoint will be replaced with a production url, and current endpoint will become test.

The production build is configured using Docker image https://nextjs.org/docs/pages/building-your-application/deploying#docker-image
Loading
Loading