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

Openapi #1972

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Openapi #1972

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
16 changes: 15 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
.dockerignore
Dockerfile
Dockerfile.*
docker-compose.*
node_modules
docker-compose.yaml
docker-compose.yaml
similarity_api/
docs/
bin/
deployment_config/
terraform/
**/node_modules
**/.next
**/dist
*.md
reports
.env
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ REDIRECT_URI_HOST=http://localhost:8080
CURRENT_USER_ID=1
# NEW_RELIC_LICENSE_KEY can be omitted in local development
NEW_RELIC_LICENSE_KEY=secret_key
NEW_RELIC_ENABLED=false
# Set to false to require user to go through auth flow, never true in production envs
BYPASS_AUTH=true
HSES_DATA_FILE_URL=url
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ tests/e2e/report
/doc

# Build related
build/
build/**
dist/**
frontend/build
node_modules

Expand All @@ -32,6 +33,7 @@ newrelic_agent.log
# Secrets
.DS_Store
.env
**/.env
**/*secrets.auto.tfvars

# Temp files
Expand Down
59 changes: 59 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM node:18.18.2 as base
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init lcov chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
COPY package.json yarn.lock ./
RUN yarn global add node-gyp &&\
yarn install &&\
yarn cache clean

FROM node:18.18.2-alpine as frontend-base
WORKDIR /app
RUN apk update && apk add yarn dumb-init
COPY frontend/package.json frontend/yarn.lock ./
RUN yarn install &&\
yarn cache clean

FROM node:18.18.2 as build
ENV NODE_OPTIONS=--max_old_space_size=2048
WORKDIR /app
COPY --from=base /app/node_modules /app/node_modules
COPY --from=base /app/package.json /app/package.json
COPY src/ /app/src/
COPY tests/ /app/tests/
COPY config/ /app/config/
RUN yarn tsc --build --verbose src

FROM node:18.18.2-alpine as frontend-build
ENV NODE_OPTIONS=--max_old_space_size=2048
WORKDIR /app
ENV DISABLE_ESLINT_PLUGIN=true
COPY --from=frontend-base /app/node_modules /app/node_modules
COPY ./frontend .
RUN yarn build:local

FROM node:18.18.2-alpine as frontend
RUN apk update
# ENV CHOKIDAR_USEPOLLING=true
WORKDIR /app
COPY --chown=node:node --from=frontend-base /usr/bin/dumb-init /usr/bin/dumb-init
COPY --chown=node:node --from=frontend-build /app/build /app
COPY --chown=node:node --from=frontend-build /app/node_modules /app/node_modules
COPY --chown=node:node --from=frontend-build /app/package.json /app/package.json
USER node
# CMD ["/usr/bin/dumb-init", "node", "server.js"]

FROM node:18.18.2-slim as backend
WORKDIR /app
COPY --chown=node:node .sequelizerc /app/.sequelizerc
COPY --chown=node:node --from=base /usr/bin/dumb-init /usr/bin/dumb-init
COPY --chown=node:node --from=build /app/build /app
COPY --chown=node:node --from=build /app/node_modules/ /app/node_modules/
COPY --chown=node:node --from=build /app/package.json /app/package.json
USER node
# CMD ["dumb-init", "node", "server.js"]

FROM backend as worker

FROM backend as testingonly
54 changes: 36 additions & 18 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ services:
backend:
build:
context: .
dockerfile: ./Dockerfile.dev
cache_from:
- node:18.18.2 # Using the base image as a cache source
- node:18.18.2-slim
- node:18.18.2-alpine
- head-start-ttadp-backend:latest
target: backend
command: yarn server
user: ${CURRENT_USER:-root}
ports:
- "8080:8080"
depends_on:
- db
- redis
environment:
- POSTGRES_HOST=postgres_docker
- REDIS_HOST=redis
- SMTP_HOST=mailcatcher
- FONTAWESOME_NPM_AUTH_TOKEN
env_file: .env
# environment:
# On an M1 mac, puppeteer install fails with the message:
# "The chromium binary is not available for arm64"
#
Expand All @@ -25,13 +29,24 @@ services:
# In ~/.zshrc (in my case) add:
# export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# export PUPPETEER_EXECUTABLE_PATH=`which chromium`
- PUPPETEER_EXECUTABLE_PATH
- PUPPETEER_SKIP_CHROMIUM_DOWNLOAD

volumes:
- ".:/app:rw"
- "./src/:/app/src/:rw"
- "./tests/:/app/tests/:rw"
- "./config/:/app/config:rw"
- "./packages:/packages:ro"
- ".env:/app/.env:ro"
frontend:
build:
context: .
dockerfile: ./Dockerfile.dev
cache_from:
- node:18.18.2 # Using the base image as a cache source
- node:18.18.2-slim
- node:18.18.2-alpine
- head-start-ttadp-frontend:latest
target: frontend
env_file: .env
command: yarn start
user: ${CURRENT_USER:-root}
stdin_open: true
Expand All @@ -41,24 +56,27 @@ services:
- "./frontend:/app:rw"
- "./scripts:/app/scripts"
- "./packages:/packages:ro"
environment:
- BACKEND_PROXY=http://backend:8080
- FONTAWESOME_NPM_AUTH_TOKEN
- REACT_APP_WEBSOCKET_URL
- ".env:/app/.env:ro"
worker:
build:
context: .
dockerfile: ./Dockerfile.dev
cache_from:
- node:18.18.2 # Using the base image as a cache source
- node:18.18.2-slim
- node:18.18.2-alpine
- head-start-ttadp-worker:latest
target: backend
command: yarn worker
env_file: .env
depends_on:
- db
- redis
environment:
- POSTGRES_HOST=postgres_docker
- REDIS_HOST=redis
- SMTP_HOST=mailcatcher
volumes:
- ".:/app:rw"
- "./src/:/app/src/:rw"
- "./tests/:/app/tests/:rw"
- "./config/:/app/config:rw"
- ".env:/app/.env:ro"
owasp_zap_backend:
image: owasp/zap2docker-stable:latest
platform: linux/arm64
Expand All @@ -73,7 +91,7 @@ services:
image: owasp/zap2docker-stable:latest
platform: linux/arm64
user: zap
command: zap-api-scan.py -t http://similarity:8080/openapi.json -f openapi -I -i -r owasp_api_report.html
command: zap-api-scan.py -t http://similarity_api:8080/openapi.json -f openapi -I -i -r owasp_api_report.html
volumes:
- ./zap.conf:/zap/wrk/zap.conf:ro
- ./reports:/zap/wrk:rw
Expand Down
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
volumes:
- dbdata:/var/lib/postgresql/data
shm_size: 1g
environment:
POSTGRES_HOST: localhost
minio:
image: minio/minio:RELEASE.2024-01-01T16-36-33Z
env_file: .env
Expand All @@ -33,7 +35,7 @@ services:
depends_on:
- minio
clamav-rest:
image: ajilaag/clamav-rest
image: kcirtapfromspace/clamav-rest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is yours, but I see that no one else is maintaining a cross platform version.
I think we need to reconfigure the clamav settings. As the import system is attempting to queue all the files its placing on s3 to be scanned. But they are ~75MB each.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to build arm64 on m1 machines. open pr to clam for the to build arm ajilach/clamav-rest#37

ports:
- "9443:9443"
environment:
Expand All @@ -50,6 +52,10 @@ services:
- "./similarity_api/src:/app:rw"
redis:
image: redis:5.0.6-alpine
# https://github.com/docker-library/redis/issues/191
sysctls:
- net.core.somaxconn=511
# - vm.overcommit_memory=1
command: ['redis-server', '--requirepass', '$REDIS_PASS']
env_file: .env
ports:
Expand All @@ -76,12 +82,20 @@ services:
testingonly:
build:
context: .
dockerfile: ./Dockerfile.dev
# target: dependencies
cache_from:
- node:18.18.2 # Using the base image as a cache source
- head-start-ttadp-testingonly:latest
target: backend
ports:
- "9999:9999"
depends_on:
- db
volumes:
- ".:/app:rw"
- "./src/:/app/src/:rw"
- "./tests/:/app/tests/:rw"
- "./config/:/app/config:rw"
command: yarn start:testingonly
environment:
- POSTGRES_HOST=postgres_docker
Expand Down
10 changes: 0 additions & 10 deletions frontend/.env
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
BACKEND_PROXY=http://localhost:8080
REACT_APP_INACTIVE_MODAL_TIMEOUT=1500000
REACT_APP_SESSION_TIMEOUT=1800000
REACT_APP_TTA_SMART_HUB_URI=http://localhost:3000
REACT_APP_ENABLE_WIDGETS=true

REACT_APP_GTM_ENABLED=false
REACT_APP_GTM_ID=GTM-MKSDS7M
REACT_APP_GTM_AUTH=mET4lHjc_AMQrlW4QXiCcA
REACT_APP_GTM_PREVIEW=env-6
10 changes: 10 additions & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BACKEND_PROXY=http://localhost:8080
REACT_APP_INACTIVE_MODAL_TIMEOUT=1500000
REACT_APP_SESSION_TIMEOUT=1800000
REACT_APP_TTA_SMART_HUB_URI=http://localhost:3000
REACT_APP_ENABLE_WIDGETS=true

REACT_APP_GTM_ENABLED=false
REACT_APP_GTM_ID=GTM-MKSDS7M
REACT_APP_GTM_AUTH=mET4lHjc_AMQrlW4QXiCcA
REACT_APP_GTM_PREVIEW=env-6
5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"tar": "^4.4.18",
"d3-color": "^3.1.0",
"minimatch": "^3.0.5",
"postcss": "^8.4.31",
"decode-uri-component": "^0.2.1",
"tough-cookie": "^4.0.0",
"ua-parser-js": "^0.7.33",
Expand Down Expand Up @@ -159,6 +158,7 @@
]
},
"devDependencies": {
"postcss": "^8.4.33",
"@sheerun/mutationobserver-shim": "^0.3.3",
"@testing-library/dom": "^8.11.1",
"@testing-library/jest-dom": "^5.11.9",
Expand All @@ -183,6 +183,9 @@
"react-scripts": "^5.0.1",
"react-select-event": "^5.1.0"
},
"peerDependencies": {
"postcss": "^8.4.33"
},
"jest": {
"coveragePathIgnorePatterns": [
"<rootDir>/src/index.js",
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SiteNav from './components/SiteNav';
import Header from './components/Header';

import Admin from './pages/Admin';
import APIDocs from './pages/APIDocs';
import RegionalDashboard from './pages/RegionalDashboard';
import TrainingReports from './pages/TrainingReports';
import ResourcesDashboard from './pages/ResourcesDashboard';
Expand Down Expand Up @@ -238,6 +239,15 @@ function App() {
</AppWrapper>
)}
/>
<Route
exact
path="/api-docs"
render={() => (
<AppWrapper authenticated logout={logout} hasAlerts={!!(alert)}>
<APIDocs />
</AppWrapper>
)}
/>
<Route
path="/recipient-tta-records/:recipientId([0-9]*)/region/:regionId([0-9]*)"
render={({ match, location }) => (
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/pages/APIDocs/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Router } from 'react-router';
import { createMemoryHistory } from 'history';

import NotFound from '../index';

describe('NotFound', () => {
it('Displays without issues', async () => {
const history = createMemoryHistory();
render(
<Router history={history}>
<NotFound />
</Router>,
);

const text = await screen.findByText(/Page Not Found/);

expect(text).toBeTruthy();
});
});
18 changes: 18 additions & 0 deletions frontend/src/pages/APIDocs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import BackLink from '../../components/BackLink';

export default function APIDocs() {
const params = new URLSearchParams(window.location.search);
const referrer = params.get('referrer');

return (
<div>
{referrer && (
<BackLink to={decodeURIComponent(referrer)}>Back</BackLink>
)}
<h1 className="landing margin-top-0 margin-bottom-3">API Documentation</h1>
<APIDocs spec={jsonData} />
</div>
);
}

6 changes: 3 additions & 3 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3799,9 +3799,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001426:
version "1.0.30001441"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz#987437b266260b640a23cd18fbddb509d7f69f3e"
integrity sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==
version "1.0.30001583"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001583.tgz"
integrity sha512-acWTYaha8xfhA/Du/z4sNZjHUWjkiuoAi2LM+T/aL+kemKQgPT1xBb/YKjlQ0Qo8gvbHsGNplrEJ+9G3gL7i4Q==

canvas-fit@^1.5.0:
version "1.5.0"
Expand Down
Loading