Compare commits
No commits in common. "main" and "v1.1.9" have entirely different histories.
71
.github/workflows/base-build-image-gcp.yml
vendored
71
.github/workflows/base-build-image-gcp.yml
vendored
@ -1,71 +0,0 @@
|
|||||||
name: Build base images (Generally from basin repo)
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
inputs:
|
|
||||||
image_tag:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
fail_on_scan:
|
|
||||||
default: true
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docker-build-and-push:
|
|
||||||
|
|
||||||
runs-on: ubuntu-22.04 #ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- id: get-id
|
|
||||||
name: Get a unique tag for this build
|
|
||||||
run: |
|
|
||||||
echo "DOCKER_IMAGE=${{ vars.GCP_DOCKER_REGISTRY }}/${{ github.repository }}:${{ inputs.image_tag }}" >> "$GITHUB_OUTPUT";
|
|
||||||
|
|
||||||
- name: Print image name
|
|
||||||
run: |
|
|
||||||
echo "${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# ✅ 1) Auth to GCP (this is where your SA key is used)
|
|
||||||
- name: Auth to GCP
|
|
||||||
uses: google-github-actions/auth@v2
|
|
||||||
with:
|
|
||||||
# using your existing secret that contains the SA JSON
|
|
||||||
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
|
||||||
|
|
||||||
# ✅ 2) Install gcloud (no creds here)
|
|
||||||
- name: Set up gcloud
|
|
||||||
uses: google-github-actions/setup-gcloud@v2
|
|
||||||
with:
|
|
||||||
project_id: ${{ vars.GCP_PROJECT_ID }}
|
|
||||||
export_default_credentials: true
|
|
||||||
|
|
||||||
- name: Configure Docker for GAR
|
|
||||||
run: |
|
|
||||||
gcloud auth configure-docker ${{vars.GCP_REGION}}-docker.pkg.dev
|
|
||||||
|
|
||||||
- name: Build and push the Docker image
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
--file context/Dockerfile \
|
|
||||||
--tag ${{ steps.get-id.outputs.DOCKER_IMAGE }} \
|
|
||||||
./context;
|
|
||||||
|
|
||||||
- name: Container details
|
|
||||||
run: |
|
|
||||||
IMAGE_SIZE=`docker inspect -f "{{ .Size }}" ${{ steps.get-id.outputs.DOCKER_IMAGE }} | numfmt --to=si`;
|
|
||||||
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
# - name: Scan Docker Image for vulnerabilities with Grype
|
|
||||||
# uses: anchore/scan-action@v6
|
|
||||||
# with:
|
|
||||||
# image: ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
|
||||||
# cache-db: true #Cache Grype DB in Github Actions
|
|
||||||
# output-format: table
|
|
||||||
# only-fixed: true
|
|
||||||
# severity-cutoff: critical
|
|
||||||
# fail-build: ${{ inputs.fail_on_scan }}
|
|
||||||
|
|
||||||
- name: Push the container image
|
|
||||||
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
|
||||||
63
.github/workflows/push-container-gcp.yml
vendored
63
.github/workflows/push-container-gcp.yml
vendored
@ -1,63 +0,0 @@
|
|||||||
name: Reusable container push workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
env:
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
push-container:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- id: get-id
|
|
||||||
name: Get a unique tag for this build
|
|
||||||
run: |
|
|
||||||
SHA=${{ github.sha }}; BRANCH_NAME=${{ github.base_ref || github.ref_name }};
|
|
||||||
BUILD_ID=$BRANCH_NAME-${SHA:0:8};
|
|
||||||
DOCKER_IMAGE="${{vars.GCP_DOCKER_REGISTRY}}/$REPO:$BUILD_ID"
|
|
||||||
echo "BUILD_ID=$BUILD_ID" >> "$GITHUB_OUTPUT";
|
|
||||||
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> "$GITHUB_OUTPUT";
|
|
||||||
|
|
||||||
- name: Print build id and image name
|
|
||||||
run: |
|
|
||||||
echo "BUILD_ID: ${{ steps.get-id.outputs.BUILD_ID }}";
|
|
||||||
echo "DOCKER_IMAGE: ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# ✅ 1) Auth to GCP (this is where your SA key is used)
|
|
||||||
- name: Auth to GCP
|
|
||||||
uses: google-github-actions/auth@v2
|
|
||||||
with:
|
|
||||||
# using your existing secret that contains the SA JSON
|
|
||||||
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
|
||||||
|
|
||||||
# ✅ 2) Install gcloud (no creds here)
|
|
||||||
- name: Set up gcloud
|
|
||||||
uses: google-github-actions/setup-gcloud@v2
|
|
||||||
with:
|
|
||||||
project_id: ${{ vars.GCP_PROJECT_ID }}
|
|
||||||
export_default_credentials: true
|
|
||||||
|
|
||||||
- name: Configure Docker for GAR
|
|
||||||
run: |
|
|
||||||
gcloud auth configure-docker ${{vars.GCP_REGION}}-docker.pkg.dev
|
|
||||||
|
|
||||||
- name: Build the container image
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
--build-arg BUILD_STEP=container \
|
|
||||||
--build-arg PUBLIC_BUILD_VERSION=${{ steps.get-id.outputs.BUILD_ID }} \
|
|
||||||
--file fab/d/actions-build.Dockerfile \
|
|
||||||
--tag ${{ steps.get-id.outputs.DOCKER_IMAGE }} \
|
|
||||||
.;
|
|
||||||
|
|
||||||
- name: Container details
|
|
||||||
run: |
|
|
||||||
IMAGE_SIZE=`docker inspect -f "{{ .Size }}" ${{ steps.get-id.outputs.DOCKER_IMAGE }} | numfmt --to=si`;
|
|
||||||
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- name: Push the container image
|
|
||||||
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
|
||||||
2
.github/workflows/push-container.yml
vendored
2
.github/workflows/push-container.yml
vendored
@ -49,4 +49,4 @@ jobs:
|
|||||||
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
||||||
|
|
||||||
- name: Push the container image
|
- name: Push the container image
|
||||||
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
||||||
|
|||||||
86
.github/workflows/push-s3-gcp.yml
vendored
86
.github/workflows/push-s3-gcp.yml
vendored
@ -1,86 +0,0 @@
|
|||||||
name: Docker Image CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
# Org Secrets are available on push event. Not pull_request event.
|
|
||||||
|
|
||||||
env:
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
REPO_SHORT_NAME: ${{ github.event.repository.name }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
push-s3:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- id: get-id
|
|
||||||
name: Get a unique tag for this build
|
|
||||||
run: |
|
|
||||||
SHA=${{ github.sha }}; BRANCH_NAME=${{ github.base_ref || github.ref_name }};
|
|
||||||
BUILD_ID=$BRANCH_NAME-${SHA:0:8};
|
|
||||||
DOCKER_IMAGE=${{ vars.GCP_DOCKER_REGISTRY }}/$REPO:$BUILD_ID;
|
|
||||||
echo "BUILD_ID=$BUILD_ID" >> "$GITHUB_OUTPUT";
|
|
||||||
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> "$GITHUB_OUTPUT";
|
|
||||||
|
|
||||||
- name: Print build id and image name
|
|
||||||
run: |
|
|
||||||
echo "BUILD_ID: ${{ steps.get-id.outputs.BUILD_ID }}";
|
|
||||||
echo "DOCKER_IMAGE: ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# ✅ 1) Auth to GCP (this is where your SA key is used)
|
|
||||||
- name: Auth to GCP
|
|
||||||
uses: google-github-actions/auth@v2
|
|
||||||
with:
|
|
||||||
# using your existing secret that contains the SA JSON
|
|
||||||
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
|
||||||
|
|
||||||
# ✅ 2) Install gcloud (no creds here)
|
|
||||||
- name: Set up gcloud
|
|
||||||
uses: google-github-actions/setup-gcloud@v2
|
|
||||||
with:
|
|
||||||
project_id: ${{ vars.GCP_PROJECT_ID }}
|
|
||||||
export_default_credentials: true
|
|
||||||
|
|
||||||
- name: Configure Docker for GAR
|
|
||||||
run: |
|
|
||||||
gcloud auth configure-docker ${{vars.GCP_REGION}}-docker.pkg.dev
|
|
||||||
|
|
||||||
|
|
||||||
- name: Build the container image for bundle step
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
--build-arg BUILD_STEP=bundle \
|
|
||||||
--build-arg PUBLIC_BUILD_VERSION=${{ steps.get-id.outputs.BUILD_ID }} \
|
|
||||||
--file fab/d/actions-build.Dockerfile \
|
|
||||||
--tag ${{ steps.get-id.outputs.DOCKER_IMAGE }} \
|
|
||||||
.;
|
|
||||||
|
|
||||||
- name: Extract cloud files
|
|
||||||
run: |
|
|
||||||
image=${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
|
||||||
source_path=/cloud
|
|
||||||
destination_path=cloud
|
|
||||||
|
|
||||||
container_id=$(docker create "$image")
|
|
||||||
docker cp "$container_id:$source_path" "$destination_path"
|
|
||||||
docker rm "$container_id"
|
|
||||||
|
|
||||||
echo "Running: ls $destination_path"
|
|
||||||
ls $destination_path
|
|
||||||
|
|
||||||
- name: Upload cloud files
|
|
||||||
uses: https://git.gmetri.io/gmetribin/aws-cli-action@v1.0.0
|
|
||||||
env:
|
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}
|
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}
|
|
||||||
AWS_DEFAULT_REGION: ${{ vars.aws_default_region }}
|
|
||||||
with:
|
|
||||||
args: >
|
|
||||||
s3 cp \
|
|
||||||
--recursive \
|
|
||||||
--cache-control max-age=31536000\
|
|
||||||
--storage-class 'STANDARD_IA' \
|
|
||||||
cloud/ s3://${{ vars.aws_upload_bucket }}/${{ env.REPO_SHORT_NAME }}/${{ steps.get-id.outputs.BUILD_ID }}
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -129,4 +129,4 @@ dist
|
|||||||
.yarn/build-state.yml
|
.yarn/build-state.yml
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
.idea/
|
|
||||||
|
|||||||
20
README-vulnerability-scans.md
Normal file
20
README-vulnerability-scans.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Grype
|
||||||
|
|
||||||
|
https://anchorecommunity.discourse.group/t/how-to-act-on-go-module-vulnerabilities/186/2
|
||||||
|
|
||||||
|
## Fixing issues within the image
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sudo sh -s -- -b /usr/local/bin/
|
||||||
|
|
||||||
|
#To check vulnerabilities
|
||||||
|
grype .
|
||||||
|
#To save detailed output
|
||||||
|
grype $MY_IMAGE -o json > vuln.json
|
||||||
|
#OR
|
||||||
|
grype . -o json > vuln.json
|
||||||
|
|
||||||
|
#To explain the issue:
|
||||||
|
cat vuln.json | grype explain --id CVE-2023-24537
|
||||||
|
cat vuln2.json | grype explain --id CVE-2023-45853
|
||||||
|
```
|
||||||
19
repo-template/baseimage-repo/base-build-image.yml
Normal file
19
repo-template/baseimage-repo/base-build-image.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#For use in base images repos like basin/baseimages
|
||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push: # Build on all pushes
|
||||||
|
schedule: # Also build on all Fridays
|
||||||
|
- cron: "30 6 * * 5" #Every Friday@12 NOON IST (6:30 GMT)
|
||||||
|
# Cron: Minute(0-59) Hour(0-23) DayOfMonth(1-31) MonthOfYear(1-12) DayOfWeek(0-6)
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
#Assumes the dockerfile to be at ./context/Dockerfile and context ./context
|
||||||
|
reuse-base-build-image:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/base-build-image.yml@v1.1.2
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
image_tag: ${{ github.ref_name }}-v1 #Generally becomes basin:node-22-dev-v1
|
||||||
|
fail_on_scan: true
|
||||||
|
#To be updated in the code repo as per requirement
|
||||||
24
repo-template/node-based-repo/.dockerignore
Normal file
24
repo-template/node-based-repo/.dockerignore
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
node_modules/
|
||||||
|
.pnpm-store/
|
||||||
|
|
||||||
|
.npm/
|
||||||
|
# Can't include git in docker ignore - needs to be present in publisher image
|
||||||
|
# .git/
|
||||||
|
# #short_ref needed in BUILD_VERSION
|
||||||
|
# !.git/short_ref
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
data/
|
||||||
|
build/
|
||||||
|
cloud/
|
||||||
|
snowpack/
|
||||||
|
|
||||||
|
# ESlint coverage files
|
||||||
|
.coverage.eslint.codeframe
|
||||||
|
coverage/
|
||||||
|
.nyc_output/
|
||||||
|
# test/ -- test folder needs to be a part of the docker context so that it's present in the publisher image (in which tests are run)
|
||||||
|
|
||||||
|
dev/pgadmin4/.pgpass
|
||||||
15
repo-template/node-based-repo/.editorconfig
Normal file
15
repo-template/node-based-repo/.editorconfig
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# EditorConfig is awesome: http://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Matches multiple files with brace expansion notation
|
||||||
|
# Set default charset
|
||||||
|
[*.{js,jsx,ts,tsx,py,sh,md,njk,json}]
|
||||||
|
charset = utf-8
|
||||||
|
indent_size = 2
|
||||||
0
repo-template/node-based-repo/.github/archive/.gitkeep
vendored
Normal file
0
repo-template/node-based-repo/.github/archive/.gitkeep
vendored
Normal file
17
repo-template/node-based-repo/.github/workflows/base-workflow.yml
vendored
Normal file
17
repo-template/node-based-repo/.github/workflows/base-workflow.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
name: Base Push Workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule: # Also build on all Fridays
|
||||||
|
- cron: "30 7 * * 5" #Every Friday@1PM IST (7:30 GMT)
|
||||||
|
# Cron: Minute(0-59) Hour(0-23) DayOfMonth(1-31) MonthOfYear(1-12) DayOfWeek(0-6)
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
#Builds ./fab/d/actions-base.Dockerfile
|
||||||
|
dispatch-container-base:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/dispatch-container-base.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
image_tag: base-v1 #To be updated in the code repo as per requirement
|
||||||
|
#Update the build image to use the same base tag
|
||||||
13
repo-template/node-based-repo/.github/workflows/pr-workflow.yml
vendored
Normal file
13
repo-template/node-based-repo/.github/workflows/pr-workflow.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: Pull Request Workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
#Runs pnpm lint and pnpm check
|
||||||
|
lint-and-check:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/pr-lint-and-check.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
49
repo-template/node-based-repo/.github/workflows/push-workflow.yml
vendored
Normal file
49
repo-template/node-based-repo/.github/workflows/push-workflow.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
name: Push Workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
#Runs code vulnerability scan after `pnpm install`
|
||||||
|
code-scan:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-code-scan.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
#Runs `pnpm install; pnpm test`
|
||||||
|
code-test:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-code-test.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
#Runs `pnpm build_npm`
|
||||||
|
push-npm:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-npm.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
needs: [code-test]
|
||||||
|
|
||||||
|
#Builds ./fab/d/actions-build.Dockerfile, with build-args PUBLIC_BUILD_VERSION and BUILD_STEP=container
|
||||||
|
#And then pushes the image to the registry
|
||||||
|
push-container:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-container.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
#Builds ./fab/d/actions-build.Dockerfile, with build-args PUBLIC_BUILD_VERSION and BUILD_STEP=container
|
||||||
|
#And then runs code vulnerability scan on the built image
|
||||||
|
push-container-scan:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-container-scan.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
#Builds ./fab/d/actions-build.Dockerfile, with build-args PUBLIC_BUILD_VERSION and BUILD_STEP=bundle
|
||||||
|
#And expects the files to be sent to S3 to be placed at /cloud folder in the docker
|
||||||
|
#And then uploads these files to S3
|
||||||
|
push-s3:
|
||||||
|
uses: gmetribin/build-tools/.github/workflows/push-s3.yml@v1.1.6
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
cs-update-trigger:
|
||||||
|
uses: gmetribin/deploy-tools/.github/workflows/cs-update-trigger.yml@v1.1.22
|
||||||
|
secrets: inherit
|
||||||
|
needs: [push-container]
|
||||||
|
with:
|
||||||
|
deploy_repo: gmetrivr/cs-dt #Update as per the repo group
|
||||||
79
repo-template/node-based-repo/.gitignore
vendored
Normal file
79
repo-template/node-based-repo/.gitignore
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
stats.json
|
||||||
|
statsProd.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
.pnpm-store/
|
||||||
|
|
||||||
|
# Typescript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Build folders
|
||||||
|
data/
|
||||||
|
build/
|
||||||
|
cloud/
|
||||||
|
lib
|
||||||
|
|
||||||
|
# ESlint coverage files
|
||||||
|
coverage.eslint
|
||||||
|
|
||||||
|
# IDE Specific
|
||||||
|
.idea/
|
||||||
|
.cache/
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/launch.json
|
||||||
|
|
||||||
|
#Because we use pnpm lock
|
||||||
|
package-lock.json
|
||||||
1
repo-template/node-based-repo/README.md
Normal file
1
repo-template/node-based-repo/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
[](https://git.gmetri.io/gmetrivr/dt-dbz/actions?workflow=push-workflow.yml)
|
||||||
28
repo-template/node-based-repo/eslint.config.mjs
Normal file
28
repo-template/node-based-repo/eslint.config.mjs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import eslint from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
eslint.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
{
|
||||||
|
files: ["src/**/*.{js,ts,jsx,tsx}"]
|
||||||
|
}, {
|
||||||
|
ignores: ["*.min.js", "src/models/", "src/static/", "src/public/"],
|
||||||
|
}, {
|
||||||
|
rules: {
|
||||||
|
"no-undef": "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/triple-slash-reference": "warn",
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"ignoreRestSiblings": true,
|
||||||
|
"argsIgnorePattern": "(^_|^req$|^request$|^res$|^next$|^h$)",
|
||||||
|
"varsIgnorePattern": "(^_|^req$|^request$|^res$|^next$|^h$)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/ban-ts-comment": "warn",
|
||||||
|
"no-async-promise-executor": "off"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
19
repo-template/node-based-repo/fab/d/actions-base.Dockerfile
Normal file
19
repo-template/node-based-repo/fab/d/actions-base.Dockerfile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
FROM repo2.hub.gmetri.io/gmetrivr/basin:node-22-slim-v3
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y wget gnupg2 lsb-release \
|
||||||
|
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
|
||||||
|
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
|
||||||
|
&& apt-get -y update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-client-14 \
|
||||||
|
&& apt-get clean all \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
# No need to install dependencies in this step
|
||||||
|
# COPY --chown=1000 ./package.json ./pnpm-lock.yaml .npmrc /src/
|
||||||
|
# RUN pnpm install;
|
||||||
36
repo-template/node-based-repo/fab/d/actions-build.Dockerfile
Normal file
36
repo-template/node-based-repo/fab/d/actions-build.Dockerfile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
FROM repo2.hub.gmetri.io/gmetrivr/basin:node-22-slim-v3
|
||||||
|
|
||||||
|
#Remove old code
|
||||||
|
# RUN find . -maxdepth 1 ! \( -name node_modules -o -name .pnpm-store \) -exec rm -rf "{}" \;
|
||||||
|
|
||||||
|
#Replace with new code (node_modules and .pnpm_store are in dockerignore)
|
||||||
|
COPY --chown=1000:1000 . /src
|
||||||
|
|
||||||
|
#PUBLIC_BUILD_VERSION contains the unique build id for this image
|
||||||
|
ARG PUBLIC_BUILD_VERSION
|
||||||
|
ENV PUBLIC_BUILD_VERSION=$PUBLIC_BUILD_VERSION
|
||||||
|
|
||||||
|
#BUILD_STEP is bundle or container. bundle for pushing to s3, container for docker image.
|
||||||
|
ARG BUILD_STEP
|
||||||
|
ENV BUILD_STEP=$BUILD_STEP
|
||||||
|
|
||||||
|
RUN if [ "$BUILD_STEP" = "bundle" ]; then \
|
||||||
|
echo "BUNDLE version $PUBLIC_BUILD_VERSION"; \
|
||||||
|
pnpm install && \
|
||||||
|
pnpm build; \
|
||||||
|
elif [ "$BUILD_STEP" = "container" ]; then \
|
||||||
|
echo "CONTAINER version $PUBLIC_BUILD_VERSION"; \
|
||||||
|
pnpm install --production && \
|
||||||
|
pnpm prune && \
|
||||||
|
pnpm store prune; \
|
||||||
|
fi;
|
||||||
|
|
||||||
|
#For single step:
|
||||||
|
# RUN if [ "$BUILD_STEP" = "container" ] || [ "$BUILD_STEP" = "bundle" ]; then \
|
||||||
|
# echo "BUILD version $PUBLIC_BUILD_VERSION"; \
|
||||||
|
# pnpm install && \
|
||||||
|
# pnpm build-storybook; \
|
||||||
|
# fi
|
||||||
|
|
||||||
|
EXPOSE 4225
|
||||||
|
CMD ["pnpm", "start-server"]
|
||||||
24
repo-template/node-based-repo/fab/d/docker-compose.yaml
Normal file
24
repo-template/node-based-repo/fab/d/docker-compose.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
services:
|
||||||
|
dt-api:
|
||||||
|
image: repo2.hub.gmetri.io/gmetrivr/basin:node-22-dev-v3
|
||||||
|
container_name: dt_dt-api
|
||||||
|
ports:
|
||||||
|
- "4205:4205"
|
||||||
|
volumes:
|
||||||
|
- .:/src
|
||||||
|
command: ["sleep", "inf"]
|
||||||
|
privileged: true
|
||||||
|
environment:
|
||||||
|
#Common Env Vars, PUBLIC_ vars may be exposed to the window also
|
||||||
|
- PUBLIC_IS_LOCAL=true #Used to check if running in developer machine
|
||||||
|
- PUBLIC_BUILD_VERSION=local #Used for unique CDN paths on evey build
|
||||||
|
- PUBLIC_NAMESPACE=local #Used to check environment (is "prod" in production)
|
||||||
|
- PUBLIC_REPO=dt-api #Repo name
|
||||||
|
#Repo Specific Env Vars
|
||||||
|
#If using dev environment
|
||||||
|
- PORT=4205
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: dt
|
||||||
|
external: true
|
||||||
6
repo-template/node-based-repo/fab/entryPoint.sh
Executable file
6
repo-template/node-based-repo/fab/entryPoint.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Image ENTRYPOINT executing as user `whoami` in directory `pwd`"
|
||||||
|
|
||||||
|
set -x
|
||||||
|
#Run command passed by docker exec/run as arguments (else the default CMD gets executed)
|
||||||
|
sh -c "$*"
|
||||||
9
repo-template/node-based-repo/fab/sh/compose_down.sh
Executable file
9
repo-template/node-based-repo/fab/sh/compose_down.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. ./fab/sh/constants.sh
|
||||||
|
|
||||||
|
set -x
|
||||||
|
docker compose \
|
||||||
|
-f fab/d/docker-compose.yaml \
|
||||||
|
--project-name ${REPO_NAME} \
|
||||||
|
--project-directory ${REPO_FOLDER} \
|
||||||
|
down
|
||||||
41
repo-template/node-based-repo/fab/sh/compose_up.sh
Executable file
41
repo-template/node-based-repo/fab/sh/compose_up.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -z $1 ]
|
||||||
|
then
|
||||||
|
COMMAND="bash"
|
||||||
|
else
|
||||||
|
COMMAND="${@}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
. ./fab/sh/constants.sh
|
||||||
|
. ./fab/sh/docker_network_create.sh
|
||||||
|
|
||||||
|
#Make more verbose now
|
||||||
|
set -x
|
||||||
|
docker compose \
|
||||||
|
-f fab/d/docker-compose.yaml \
|
||||||
|
-p ${REPO_NAME} \
|
||||||
|
--project-directory ${REPO_FOLDER} \
|
||||||
|
ps --services --filter status=running | grep $REPO_NAME > /dev/null
|
||||||
|
#$? is 0 if already running, 1 if not (0=no error)
|
||||||
|
ALREADY_RUNNING=$?
|
||||||
|
#Make less verbose now
|
||||||
|
set +x
|
||||||
|
|
||||||
|
if [ "$ALREADY_RUNNING" -eq 0 ];
|
||||||
|
then
|
||||||
|
echo "Service already running, only opening shell"
|
||||||
|
else
|
||||||
|
docker compose \
|
||||||
|
-f fab/d/docker-compose.yaml \
|
||||||
|
--project-name ${REPO_NAME} \
|
||||||
|
--project-directory ${REPO_FOLDER} \
|
||||||
|
up -d
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Connecting to docker shell and running command $COMMAND..."
|
||||||
|
docker compose \
|
||||||
|
-f fab/d/docker-compose.yaml \
|
||||||
|
--project-name ${REPO_NAME} \
|
||||||
|
--project-directory ${REPO_FOLDER} \
|
||||||
|
exec $REPO_NAME $COMMAND
|
||||||
6
repo-template/node-based-repo/fab/sh/constants.sh
Normal file
6
repo-template/node-based-repo/fab/sh/constants.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
export PARENT_PROJECT=dt #Controls which projects close together
|
||||||
|
export REPO_FOLDER=`git rev-parse --show-toplevel`
|
||||||
|
export REPO_NAME=$(basename $REPO_FOLDER)
|
||||||
|
export SHORT_REF=`git rev-parse --short HEAD`
|
||||||
|
export TAG_BASE=base-v2
|
||||||
11
repo-template/node-based-repo/fab/sh/docker_build_base.sh
Executable file
11
repo-template/node-based-repo/fab/sh/docker_build_base.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#Build and push the dev (or build) image for the project use both for local development
|
||||||
|
# and to build the project remotely
|
||||||
|
#The prod image (alpine based) is usually different from the dev/build image (ubuntu based).
|
||||||
|
. ./fab/sh/constants.sh
|
||||||
|
|
||||||
|
cd ${REPO_FOLDER}
|
||||||
|
docker build --tag ${GMETRI_DREPO}/${REPO_BASE}/${REPO_NAME}:${TAG_BASE} \
|
||||||
|
-f fab/d/actions-base.Dockerfile ./fab/context/
|
||||||
|
|
||||||
|
docker push ${GMETRI_DREPO}/${REPO_BASE}/${REPO_NAME}:${TAG_BASE}
|
||||||
18
repo-template/node-based-repo/fab/sh/docker_network_create.sh
Executable file
18
repo-template/node-based-repo/fab/sh/docker_network_create.sh
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#Externalizing the network creation step allows multiple docker composes to independently connect
|
||||||
|
#to the same network without worrying about start order
|
||||||
|
|
||||||
|
. ./fab/sh/constants.sh
|
||||||
|
|
||||||
|
NETWORK_EXISTS=0
|
||||||
|
#This is necessary instead of using $? (previous command exit code) as we are set -e mode,
|
||||||
|
#which exists the script on any error
|
||||||
|
docker network ls | grep ${PARENT_PROJECT} || NETWORK_EXISTS=1
|
||||||
|
#0 if already exists, 1 if doesn't exist (0=no error)
|
||||||
|
|
||||||
|
if [ "$NETWORK_EXISTS" -eq 0 ];
|
||||||
|
then
|
||||||
|
echo "Network exists"
|
||||||
|
else
|
||||||
|
docker network create --attachable ${PARENT_PROJECT} || true
|
||||||
|
fi
|
||||||
178
repo-template/node-based-repo/fab/sh/wait-for-it.sh
Executable file
178
repo-template/node-based-repo/fab/sh/wait-for-it.sh
Executable file
@ -0,0 +1,178 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Use this script to test if a given TCP host/port are available
|
||||||
|
|
||||||
|
WAITFORIT_cmdname=${0##*/}
|
||||||
|
|
||||||
|
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
cat << USAGE >&2
|
||||||
|
Usage:
|
||||||
|
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
|
||||||
|
-h HOST | --host=HOST Host or IP under test
|
||||||
|
-p PORT | --port=PORT TCP port under test
|
||||||
|
Alternatively, you specify the host and port as host:port
|
||||||
|
-s | --strict Only execute subcommand if the test succeeds
|
||||||
|
-q | --quiet Don't output any status messages
|
||||||
|
-t TIMEOUT | --timeout=TIMEOUT
|
||||||
|
Timeout in seconds, zero for no timeout
|
||||||
|
-- COMMAND ARGS Execute command with args after the test finishes
|
||||||
|
USAGE
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for()
|
||||||
|
{
|
||||||
|
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||||
|
else
|
||||||
|
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
|
||||||
|
fi
|
||||||
|
WAITFORIT_start_ts=$(date +%s)
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
|
||||||
|
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||||
|
WAITFORIT_result=$?
|
||||||
|
else
|
||||||
|
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||||
|
WAITFORIT_result=$?
|
||||||
|
fi
|
||||||
|
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||||
|
WAITFORIT_end_ts=$(date +%s)
|
||||||
|
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
return $WAITFORIT_result
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_wrapper()
|
||||||
|
{
|
||||||
|
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||||
|
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||||
|
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||||
|
else
|
||||||
|
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
|
||||||
|
fi
|
||||||
|
WAITFORIT_PID=$!
|
||||||
|
trap "kill -INT -$WAITFORIT_PID" INT
|
||||||
|
wait $WAITFORIT_PID
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||||
|
fi
|
||||||
|
return $WAITFORIT_RESULT
|
||||||
|
}
|
||||||
|
|
||||||
|
# process arguments
|
||||||
|
while [[ $# -gt 0 ]]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
*:* )
|
||||||
|
WAITFORIT_hostport=(${1//:/ })
|
||||||
|
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
|
||||||
|
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--child)
|
||||||
|
WAITFORIT_CHILD=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-q | --quiet)
|
||||||
|
WAITFORIT_QUIET=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-s | --strict)
|
||||||
|
WAITFORIT_STRICT=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
WAITFORIT_HOST="$2"
|
||||||
|
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--host=*)
|
||||||
|
WAITFORIT_HOST="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-p)
|
||||||
|
WAITFORIT_PORT="$2"
|
||||||
|
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--port=*)
|
||||||
|
WAITFORIT_PORT="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-t)
|
||||||
|
WAITFORIT_TIMEOUT="$2"
|
||||||
|
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--timeout=*)
|
||||||
|
WAITFORIT_TIMEOUT="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
WAITFORIT_CLI=("$@")
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echoerr "Unknown argument: $1"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
|
||||||
|
echoerr "Error: you need to provide a host and port to test."
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
|
||||||
|
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||||
|
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||||
|
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||||
|
|
||||||
|
# check to see if timeout is from busybox?
|
||||||
|
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||||
|
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||||
|
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||||
|
WAITFORIT_ISBUSY=1
|
||||||
|
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||||
|
|
||||||
|
else
|
||||||
|
WAITFORIT_ISBUSY=0
|
||||||
|
WAITFORIT_BUSYTIMEFLAG=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||||
|
wait_for
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
else
|
||||||
|
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||||
|
wait_for_wrapper
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
else
|
||||||
|
wait_for
|
||||||
|
WAITFORIT_RESULT=$?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $WAITFORIT_CLI != "" ]]; then
|
||||||
|
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
|
||||||
|
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
fi
|
||||||
|
exec "${WAITFORIT_CLI[@]}"
|
||||||
|
else
|
||||||
|
exit $WAITFORIT_RESULT
|
||||||
|
fi
|
||||||
9
repo-template/node-based-repo/fab/tsconfig-cjs.json
Normal file
9
repo-template/node-based-repo/fab/tsconfig-cjs.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig-esm.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "CommonJS",
|
||||||
|
"moduleResolution": "Node10",
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "../lib/cjs"
|
||||||
|
},
|
||||||
|
}
|
||||||
12
repo-template/node-based-repo/fab/tsconfig-esm.json
Normal file
12
repo-template/node-based-repo/fab/tsconfig-esm.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig",
|
||||||
|
//include needed so the whole src and dev folder doesn't get built
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
//files needed because includes doesn't work without files when using "p build"
|
||||||
|
"files": ["../src/index.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "node16",
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "../lib/esm"
|
||||||
|
},
|
||||||
|
}
|
||||||
59
repo-template/node-based-repo/package.json
Normal file
59
repo-template/node-based-repo/package.json
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"name": "@gmetrivr/definitions",
|
||||||
|
"version": "1.0.163",
|
||||||
|
"description": "GMetri Definitions",
|
||||||
|
"@comment main": "This key is still kept around until older version of node that don't understand exports key are used",
|
||||||
|
"types": "./lib/esm/index.d.ts",
|
||||||
|
"main": "./lib/cjs/index.js",
|
||||||
|
"exports": {
|
||||||
|
"require": "./lib/cjs/index.js",
|
||||||
|
"import": "./lib/esm/index.js"
|
||||||
|
},
|
||||||
|
"repository": "https://git.gmetri.io/gmetrivr/definitions",
|
||||||
|
"author": "GMetri <admin@gmetri.com>",
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"sideEffects": false,
|
||||||
|
"type": "module",
|
||||||
|
"@comment files": "Files dictate what goes to npm",
|
||||||
|
"files": [
|
||||||
|
"lib/*"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"@comment RUN": "Running this repo after running this once - pnpm install",
|
||||||
|
"start": "tsx src/index.ts",
|
||||||
|
"watch": "tsx watch src/index.ts",
|
||||||
|
"@comment TEST": "Useful for testing",
|
||||||
|
"check": "$(pnpm bin)/tsc --noEmit",
|
||||||
|
"lint": "$(pnpm bin)/eslint ./src",
|
||||||
|
"circular": "npx madge --circular --extensions ts src/index.ts",
|
||||||
|
"test": "vitest run",
|
||||||
|
"watch-test": "vitest",
|
||||||
|
"@comment PUBLISH": "Used for publishing this repo",
|
||||||
|
"build_npm": "rm -rf lib; pnpm buildpackagejson && pnpm buildesm && pnpm buildcjs",
|
||||||
|
"buildpackagejson": "tsconfig-to-dual-package ./fab/tsconfig-esm.json ./fab/tsconfig-cjs.json",
|
||||||
|
"buildesm": "tsc --project src/ -p ./fab/tsconfig-esm.json;",
|
||||||
|
"buildcjs": "tsc --project src/ -p ./fab/tsconfig-cjs.json;",
|
||||||
|
"@maintenance": "For maintenance",
|
||||||
|
"cleanup": "pnpm prune; pnpm store prune; pnpm outdated; pnpx depcheck; exit 0;"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@gmetrixr/gdash": "1.*.*"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/superagent": "^8.1.9",
|
||||||
|
"@types/superagent-prefix": "^0.0.6",
|
||||||
|
"superagent": "^10.1.1",
|
||||||
|
"superagent-prefix": "^0.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.20.0",
|
||||||
|
"@gmetrixr/gdash": "^1.3.87",
|
||||||
|
"@tsconfig/node22": "^22.0.0",
|
||||||
|
"eslint": "^9.20.1",
|
||||||
|
"tsconfig-to-dual-package": "^1.2.0",
|
||||||
|
"tsx": "^4.19.2",
|
||||||
|
"typescript": "^5.7.3",
|
||||||
|
"typescript-eslint": "^8.21.0",
|
||||||
|
"vitest": "3.0.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
2
repo-template/node-based-repo/sd
Executable file
2
repo-template/node-based-repo/sd
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
./fab/sh/compose_up.sh $@
|
||||||
105
repo-template/node-based-repo/src/exports/callerUtils.ts
Normal file
105
repo-template/node-based-repo/src/exports/callerUtils.ts
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import request, { Agent } from "superagent";
|
||||||
|
import prefix from "superagent-prefix";
|
||||||
|
|
||||||
|
export function customErrorHandler(err: Error): request.Response {
|
||||||
|
// optional chaining doesn't work in repos that don't use node-ts yet.
|
||||||
|
const errMsg = (err as any) && (err as any).response && (err as any).response.text? (err as any).response.text: err.message;
|
||||||
|
throw new Error(errMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class BaseCaller {
|
||||||
|
/**
|
||||||
|
* Makes the request after prefixing the apiUrl to the request path
|
||||||
|
* https://visionmedia.github.io/superagent/#get-requests
|
||||||
|
*/
|
||||||
|
protected agent: Agent;
|
||||||
|
/**
|
||||||
|
* base API url
|
||||||
|
*/
|
||||||
|
protected apiUrl: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in case we use the default token used at the time this class was initialized
|
||||||
|
*/
|
||||||
|
private authTokenString: string | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case the caller decides to pass a function to use to get the authToken
|
||||||
|
*/
|
||||||
|
private authTokenFunction: (() => string) | undefined;
|
||||||
|
|
||||||
|
protected useBearerToken = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in case we pass a function to resolve the authToken at realTime
|
||||||
|
* By default, this simply returns the passed authToken
|
||||||
|
*/
|
||||||
|
protected getAuthToken = (): string => {
|
||||||
|
if (this.authTokenString !== undefined) {
|
||||||
|
if(this.useBearerToken) {
|
||||||
|
if(!this.authTokenString.startsWith("Bearer ")){
|
||||||
|
return `Bearer ${this.authTokenString}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `${this.authTokenString}`;
|
||||||
|
} else if (this.authTokenFunction !== undefined) {
|
||||||
|
return this.authTokenFunction();
|
||||||
|
} else {
|
||||||
|
console.log(`Error from BaseCaller: no auth token set`);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for callers where the only option is to use API token
|
||||||
|
* Can be used in the Caller code instead of calling callerInstance.setUseBearerToken(false) in the implementation file
|
||||||
|
* which would set the Bearer option globally for this callerInstance
|
||||||
|
*/
|
||||||
|
protected getApiToken = (): string => {
|
||||||
|
if (this.authTokenString !== undefined) {
|
||||||
|
return `${this.authTokenString}`;
|
||||||
|
} else {
|
||||||
|
console.log(`Error from BaseCaller: no auth token set`);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private setAuthToken(authToken: string | (() => string)) {
|
||||||
|
if(typeof authToken === "string") {
|
||||||
|
this.authTokenString = authToken;
|
||||||
|
} else {
|
||||||
|
this.authTokenFunction = authToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authToken accepts either a string or a function.
|
||||||
|
*/
|
||||||
|
constructor(apiUrl: string, authToken?: string | (() => string), useBearerToken?: boolean) {
|
||||||
|
this.apiUrl = apiUrl;
|
||||||
|
if(authToken !== undefined) {
|
||||||
|
this.setAuthToken(authToken);
|
||||||
|
}
|
||||||
|
if(useBearerToken !== undefined) {
|
||||||
|
this.setUseBearerToken(useBearerToken);
|
||||||
|
}
|
||||||
|
this.agent = request.agent().use(prefix(apiUrl));
|
||||||
|
/**
|
||||||
|
* !IMPORTANT: DO NOT ADD ERROR HANDLING. API ALWAYS RETURNS RESPONSES AND ERRORS.
|
||||||
|
*/
|
||||||
|
/*.on("error", (err) => {
|
||||||
|
console.log(`Error while making request. Status: ${err.status}, Text: ${err.response?.text}`);
|
||||||
|
throw err;
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public setUseBearerToken(value = true): void {
|
||||||
|
this.useBearerToken = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @example
|
||||||
|
* return new ExampleCaller(this.apiUrl, token);
|
||||||
|
*/
|
||||||
|
abstract withToken(token: string): BaseCaller
|
||||||
|
}
|
||||||
3
repo-template/node-based-repo/src/exports/index.ts
Normal file
3
repo-template/node-based-repo/src/exports/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { BaseCaller } from "./callerUtils.js";
|
||||||
|
|
||||||
|
export { BaseCaller };
|
||||||
0
repo-template/node-based-repo/src/index.ts
Normal file
0
repo-template/node-based-repo/src/index.ts
Normal file
2
repo-template/node-based-repo/std
Executable file
2
repo-template/node-based-repo/std
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
./fab/sh/compose_down.sh
|
||||||
21
repo-template/node-based-repo/tsconfig.json
Normal file
21
repo-template/node-based-repo/tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/node22/tsconfig.json",
|
||||||
|
//https://www.typescriptlang.org/tsconfig/#module
|
||||||
|
"files": ["src/index.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "Node16",
|
||||||
|
"moduleResolution": "node16",
|
||||||
|
"outDir": "./out",
|
||||||
|
// default set of type definitions for built-in JS APIs. Which this a lot of default JS objects become available
|
||||||
|
"lib": ["es2023", "DOM"],
|
||||||
|
// allow jsx syntax
|
||||||
|
"jsx": "preserve",
|
||||||
|
// Generate .d.ts files
|
||||||
|
"declaration": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"noImplicitAny": true
|
||||||
|
// Using isolatedModules. So no longer exporting const enums. Just enums.
|
||||||
|
// "preserveConstEnums": true,
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user