From 5e312e5ec321a0313e32fbe745e6d5f1ebe72483 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 25 Oct 2022 13:30:19 +0200 Subject: [PATCH] feat(sourcemaps-reader): stadalone feat(chalice): use sourcempas reader stadalone --- api/Dockerfile | 10 ++------ api/build.sh | 2 -- api/entrypoint.sh | 4 +--- api/env.default | 2 +- ee/api/Dockerfile | 10 ++------ ee/api/entrypoint.sh | 4 +--- ee/api/env.default | 2 +- sourcemap-reader/Dockerfile | 23 ++++++++++++++++++ sourcemap-reader/build.sh | 44 ++++++++++++++++++++++++++++++++++ sourcemap-reader/entrypoint.sh | 2 ++ 10 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 sourcemap-reader/Dockerfile create mode 100644 sourcemap-reader/build.sh create mode 100755 sourcemap-reader/entrypoint.sh diff --git a/api/Dockerfile b/api/Dockerfile index d02dda8ba..637293c3a 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,28 +1,22 @@ FROM python:3.10-alpine LABEL Maintainer="Rajesh Rajendran" LABEL Maintainer="KRAIEM Taha Yassine" -RUN apk add --no-cache build-base nodejs npm tini +RUN apk add --no-cache build-base tini ARG envarg # Add Tini # Startup daemon ENV SOURCE_MAP_VERSION=0.7.4 \ APP_NAME=chalice \ LISTEN_PORT=8000 \ - MAPPING_WASM=/work/sourcemap-reader/mappings.wasm \ ENTERPRISE_BUILD=${envarg} -ADD https://unpkg.com/source-map@${SOURCE_MAP_VERSION}/lib/mappings.wasm /mappings.wasm - WORKDIR /work_tmp COPY requirements.txt /work_tmp/requirements.txt RUN pip install --no-cache-dir --upgrade -r /work_tmp/requirements.txt -COPY sourcemap-reader/*.json /work_tmp/ -RUN cd /work_tmp && npm install WORKDIR /work COPY . . -RUN mv env.default .env && mv /work_tmp/node_modules sourcemap-reader/. \ - && mv /mappings.wasm ${MAPPING_WASM} && chmod 644 ${MAPPING_WASM} +RUN mv env.default .env RUN adduser -u 1001 openreplay -D USER 1001 diff --git a/api/build.sh b/api/build.sh index 46c54ab2e..58689f85d 100644 --- a/api/build.sh +++ b/api/build.sh @@ -20,8 +20,6 @@ check_prereq() { function build_api(){ cp -R ../api ../_api cd ../_api - cp -R ../utilities/utils ../sourcemap-reader/. - cp -R ../sourcemap-reader . tag="" # Copy enterprise code [[ $1 == "ee" ]] && { diff --git a/api/entrypoint.sh b/api/entrypoint.sh index 7342426c2..e140268ef 100755 --- a/api/entrypoint.sh +++ b/api/entrypoint.sh @@ -1,5 +1,3 @@ #!/bin/sh -cd sourcemap-reader -nohup npm start & -cd .. + uvicorn app:app --host 0.0.0.0 --port $LISTEN_PORT --reload --proxy-headers diff --git a/api/env.default b/api/env.default index 2dcafbc8a..64243ed0b 100644 --- a/api/env.default +++ b/api/env.default @@ -38,7 +38,7 @@ PG_POOL=true sessions_bucket=mobs sessions_region=us-east-1 sourcemaps_bucket=sourcemaps -sourcemaps_reader=http://127.0.0.1:9000/sourcemaps/%s/sourcemaps +sourcemaps_reader=http://sourcemaps-reader-openreplay.app.svc.cluster.local:9000/sourcemaps/%s/sourcemaps STAGE=default-foss version_number=1.4.0 FS_DIR=/mnt/efs diff --git a/ee/api/Dockerfile b/ee/api/Dockerfile index 1b23fc6d4..4f6b739ba 100644 --- a/ee/api/Dockerfile +++ b/ee/api/Dockerfile @@ -1,26 +1,20 @@ FROM python:3.10-alpine LABEL Maintainer="Rajesh Rajendran" LABEL Maintainer="KRAIEM Taha Yassine" -RUN apk add --no-cache build-base libressl libffi-dev libressl-dev libxslt-dev libxml2-dev xmlsec-dev xmlsec nodejs npm tini +RUN apk add --no-cache build-base libressl libffi-dev libressl-dev libxslt-dev libxml2-dev xmlsec-dev xmlsec tini ARG envarg ENV SOURCE_MAP_VERSION=0.7.4 \ APP_NAME=chalice \ LISTEN_PORT=8000 \ - MAPPING_WASM=/work/sourcemap-reader/mappings.wasm \ ENTERPRISE_BUILD=${envarg} -ADD https://unpkg.com/source-map@${SOURCE_MAP_VERSION}/lib/mappings.wasm /mappings.wasm - WORKDIR /work_tmp COPY requirements.txt /work_tmp/requirements.txt RUN pip install --no-cache-dir --upgrade -r /work_tmp/requirements.txt -COPY sourcemap-reader/*.json /work_tmp/ -RUN cd /work_tmp && npm install WORKDIR /work COPY . . -RUN mv env.default .env && mv /work_tmp/node_modules sourcemap-reader/. \ - && mv /mappings.wasm ${MAPPING_WASM} && chmod 644 ${MAPPING_WASM} +RUN mv env.default .env RUN adduser -u 1001 openreplay -D USER 1001 diff --git a/ee/api/entrypoint.sh b/ee/api/entrypoint.sh index b5997ee3b..ebd646a7d 100755 --- a/ee/api/entrypoint.sh +++ b/ee/api/entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/sh sh env_vars.sh source /tmp/.env.override -cd sourcemap-reader -nohup npm start & -cd .. + uvicorn app:app --host 0.0.0.0 --port $LISTEN_PORT --reload --proxy-headers diff --git a/ee/api/env.default b/ee/api/env.default index 673454853..68cbafdce 100644 --- a/ee/api/env.default +++ b/ee/api/env.default @@ -48,7 +48,7 @@ PG_POOL=true sessions_bucket=mobs sessions_region=us-east-1 sourcemaps_bucket=sourcemaps -sourcemaps_reader=http://127.0.0.1:9000/sourcemaps/%s/sourcemaps +sourcemaps_reader=http://sourcemaps-reader-openreplay.app.svc.cluster.local:9000/sourcemaps/%s/sourcemaps stage=default-ee version_number=1.0.0 FS_DIR=/mnt/efs diff --git a/sourcemap-reader/Dockerfile b/sourcemap-reader/Dockerfile new file mode 100644 index 000000000..6b31970d6 --- /dev/null +++ b/sourcemap-reader/Dockerfile @@ -0,0 +1,23 @@ +FROM node:18-alpine +LABEL Maintainer="KRAIEM Taha Yassine" +RUN apk add --no-cache tini + +ARG envarg +ENV SOURCE_MAP_VERSION=0.7.4 \ + APP_NAME=sourcemaps-reader \ + LISTEN_PORT=9000 \ + MAPPING_WASM=/work/mappings.wasm \ + ENTERPRISE_BUILD=${envarg} + +ADD https://unpkg.com/source-map@${SOURCE_MAP_VERSION}/lib/mappings.wasm ${MAPPING_WASM} +WORKDIR /work +COPY *.json ./ +RUN npm install && chmod 644 ${MAPPING_WASM} + +COPY . . + +RUN adduser -u 1001 openreplay -D +USER 1001 + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ./entrypoint.sh diff --git a/sourcemap-reader/build.sh b/sourcemap-reader/build.sh new file mode 100644 index 000000000..8d679622e --- /dev/null +++ b/sourcemap-reader/build.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Script to build api module +# flags to accept: +# envarg: build for enterprise edition. +# Default will be OSS build. + +# Usage: IMAGE_TAG=latest DOCKER_REPO=myDockerHubID bash build.sh + +git_sha1=${IMAGE_TAG:-$(git rev-parse HEAD)} +envarg="default-foss" +check_prereq() { + which docker || { + echo "Docker not installed, please install docker." + exit 1 + } + return +} + +function build_api(){ + cp -R ../sourcemap-reader ../_smr + cd ../_smr + cp -R ../utilities/utils . + tag="" + # Copy enterprise code + [[ $1 == "ee" ]] && { + cp -rf ../ee/sourcemap-reader/* ./ + envarg="default-ee" + tag="ee-" + } + docker build -f ./Dockerfile --build-arg envarg=$envarg -t ${DOCKER_REPO:-'local'}/souremaps-reader:${git_sha1} . + cd ../sourcemap-reader + rm -rf ../_smr + [[ $PUSH_IMAGE -eq 1 ]] && { + docker push ${DOCKER_REPO:-'local'}/souremaps-reader:${git_sha1} + docker tag ${DOCKER_REPO:-'local'}/souremaps-reader:${git_sha1} ${DOCKER_REPO:-'local'}/souremaps-reader:${tag}latest + docker push ${DOCKER_REPO:-'local'}/souremaps-reader:${tag}latest + } + echo "sourcemaps-reader docker build completed" +} + +check_prereq +build_api $1 +echo buil_complete \ No newline at end of file diff --git a/sourcemap-reader/entrypoint.sh b/sourcemap-reader/entrypoint.sh new file mode 100755 index 000000000..d1bcb4adf --- /dev/null +++ b/sourcemap-reader/entrypoint.sh @@ -0,0 +1,2 @@ +#!/bin/sh +npm start \ No newline at end of file