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: PRDP-122 rework with node engine #44

Merged
merged 59 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
98722c7
[PRDP-19] feat: defining helm chart tweaks for performance test
Jul 4, 2023
6f6796e
Merge remote-tracking branch 'origin/main'
Jul 4, 2023
835414b
Merge branch 'main' of https://github.com/pagopa/pagopa-pdf-engine
Jul 12, 2023
42cb3e9
Merge branch 'main' of https://github.com/pagopa/pagopa-pdf-engine
Aug 3, 2023
478e291
Merge branch 'main' of https://github.com/pagopa/pagopa-pdf-engine
Aug 29, 2023
298d5a3
[PRDP-122] Introducing rework to include a node engine
Aug 29, 2023
3b2809b
[PRDP-122] Updated java module of the engine to contact node service,…
Aug 30, 2023
0b1c6d6
[PRDP-122] feat: Removed handlebar reference from the java function
Aug 30, 2023
1b8e9ec
[PRDP-122] feat: Updated java module tests and docs, updated code_rev…
Aug 30, 2023
7ee2cfa
[PRDP-122] feat: Updated release-deploy.yml to consider java folder o…
Aug 30, 2023
50716f7
Merge remote-tracking branch 'origin/main' into PRDP-122-feat-rework-…
Aug 30, 2023
e52278c
[PRDP-122] feat: Updated release-deploy.yml and code_review.yml
Aug 30, 2023
418da45
[PRDP-122] feat: Updated Dockerfile for node and java module
Aug 30, 2023
770af74
[PRDP-122] chore: Introducing jest in package.json dependencies, move…
Aug 30, 2023
416be16
[PRDP-122] chore: Introducing jest in package.json dependencies, move…
Aug 30, 2023
18551d0
[PRDP-122] chore: Updated jest.config.js, Updated package.json
Aug 30, 2023
d110f02
[PRDP-122] feat: introducing node info endpoint jest testing
Aug 30, 2023
c90bc9c
[PRDP-122] feat: Updated node engine tests
Aug 30, 2023
6372049
try add sidecar #1
pasqualespica Aug 31, 2023
42c6b72
[PRDP-122] Introducing updated actions with customized implementations
alexyey Aug 31, 2023
576cae9
Merge remote-tracking branch 'origin/PRDP-122-feat-rework-with-node-e…
alexyey Aug 31, 2023
0dd8a92
fix
pasqualespica Aug 31, 2023
1fd0207
fix#2
pasqualespica Aug 31, 2023
4933173
fix#3
pasqualespica Aug 31, 2023
c55ac74
fix#4
pasqualespica Aug 31, 2023
d8badf7
fix#5
pasqualespica Aug 31, 2023
a5fadb7
fix#6
pasqualespica Aug 31, 2023
540c9d7
[PRDP-122] Updated HttpTriggerGeneratePDFFunction
alexyey Aug 31, 2023
27e28fa
Merge remote-tracking branch 'origin/PRDP-122-feat-rework-with-node-e…
alexyey Aug 31, 2023
21f7e0a
fix#7
pasqualespica Aug 31, 2023
c03dcdb
fix#8
pasqualespica Aug 31, 2023
4e94774
fix
pasqualespica Aug 31, 2023
df598bc
fix##2
pasqualespica Aug 31, 2023
122fb30
fix##3
pasqualespica Aug 31, 2023
619f2c3
fix##4
pasqualespica Aug 31, 2023
3969cab
fix##5
pasqualespica Aug 31, 2023
57dc5ab
fix##6
pasqualespica Aug 31, 2023
8b32130
fix##7
pasqualespica Aug 31, 2023
1e5f274
fix##8
pasqualespica Aug 31, 2023
4fcf94b
fix##9
pasqualespica Aug 31, 2023
fa6f851
[PRDP-122] Updated Updated release-deploy.yml
alexyey Aug 31, 2023
085138e
fix
pasqualespica Sep 6, 2023
a2c09fa
Merge remote-tracking branch 'refs/remotes/origin/PRDP-122-feat-rewor…
pasqualespica Sep 6, 2023
f4670e4
fix001
pasqualespica Sep 6, 2023
91a71c3
fix001
pasqualespica Sep 6, 2023
537820e
fix001
pasqualespica Sep 6, 2023
298da9b
fix001
pasqualespica Sep 6, 2023
023c699
[PRDP-122] feat: refactored app to use express, streamlined structure…
alexyey Sep 11, 2023
bb1be91
Merge remote-tracking branch 'origin/PRDP-122-feat-rework-with-node-e…
alexyey Sep 11, 2023
5acb844
[PRDP-122] feat: Updated anchore.yml
alexyey Sep 11, 2023
e51ce43
[PRDP-122] feat: Updated GeneratePDFServiceImpl
alexyey Sep 11, 2023
bdbd1a2
[PRDP-122] feat: Updated pom.xml
alexyey Sep 11, 2023
f2df432
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
cb6193f
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
33b4fd2
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
6f54a01
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
21731a0
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
5e8541a
[PRDP-122] feat: Updated Dockerfile
alexyey Sep 11, 2023
7badaca
[PRDP-122] feat: Updated int. tests
alexyey Sep 11, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/code_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ permissions:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
code-review:
code-review-java:
Copy link
Contributor

Choose a reason for hiding this comment

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

missing only node codereview

name: Code Review
# The type of runner that the job will run on
runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ hs_err_pid*
.DS_Store

# Azure Functions
local.settings.json
java/local.settings.json
bin/
obj/

.vscode/
**/.terraform
**/*.lock.hcl
**/node_modules
yarn.lock
**/coverage
yarn.lock
**/docker/.env
164 changes: 154 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,85 @@ ARG JAVA_VERSION=11
# This image additionally contains function core tools – useful when using custom extensions
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env

ENV NODE_VERSION 20.6.0

RUN apt-get -qq update \
&& apt-get -qqy install gpg \
&& apt-get -qqy install xz-utils

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& case "${dpkgArch##*-}" in \
amd64) ARCH='x64';; \
ppc64el) ARCH='ppc64le';; \
s390x) ARCH='s390x';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armv7l';; \
i386) ARCH='x86';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
# gpg keys listed at https://github.com/nodejs/node#release-keys
&& set -ex \
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
61FC681DFB92A079F1685E77973F295594EC4689 \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
A363A499291CBBC940DD62E41F10027AF002F8B0 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
# smoke tests
&& node --version \
&& npm --version

ENV YARN_VERSION 1.22.19

RUN set -ex \
&& for key in \
6A010C5166006599AA17F08146C2130DFD2497F5 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& mkdir -p /opt \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
# smoke test
&& yarn --version

COPY . /src/java-function-app
RUN echo $(ls -1 /src/java-function-app)
RUN yarn add node
RUN chmod 777 /src/java-function-app/agent/config.yaml
RUN cd /src/java-function-app && \
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.19.0/jmx_prometheus_javaagent-0.19.0.jar && \
curl -o 'opentelemetry-javaagent.jar' -L 'https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.25.1/opentelemetry-javaagent.jar' && \
mkdir -p /home/site/wwwroot && \
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install chromium" && \
mvn clean package -Dmaven.test.skip=true && \
cd ./target/azure-functions/ && \
cd $(ls -d */|head -n 1) && \
cp -a . /home/site/wwwroot && \
cp /src/java-function-app/agent/config.yaml /home/site/wwwroot/config.yaml
cp /src/java-function-app/agent/config.yaml /home/site/wwwroot/config.yaml && \
cp -r /src/java-function-app/node /home/site/wwwroot/node

RUN chmod 777 /src/java-function-app/jmx_prometheus_javaagent-0.19.0.jar && \
cp /src/java-function-app/jmx_prometheus_javaagent-0.19.0.jar /home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar
Expand All @@ -24,6 +89,8 @@ RUN chmod 777 /src/java-function-app/jmx_prometheus_javaagent-0.19.0.jar && \
RUN chmod 777 /src/java-function-app/opentelemetry-javaagent.jar && \
cp /src/java-function-app/opentelemetry-javaagent.jar /home/site/wwwroot/opentelemetry-javaagent.jar

RUN cp /src/java-function-app/start.sh /home/site/wwwroot/start.sh

# This image is ssh enabled
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
# This image isn't ssh enabled
Expand All @@ -32,14 +99,91 @@ FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

RUN apt-get update
RUN apt-get install -y libglib2.0 libatk1.0-0 libnss3 libxcomposite-dev libasound2 libcairo2
RUN apt-get install -y libatk-bridge2.0-0 libcups2-dev libdrm-dev libpango-1.0-0
RUN apt-get install -y libxkbcommon-x11-0 libxdamage1 libxrandr2 libgbm-dev

ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true

EXPOSE 80
EXPOSE 12345
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
COPY --from=installer-env ["/root/.cache/ms-playwright", "/home/.cache/ms-playwright"]

RUN apt-get -qq update \
&& apt-get -qqy install gpg \
&& apt-get -qqy install curl \
&& apt-get -qqy install xz-utils

ENV NODE_VERSION 20.6.0

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& case "${dpkgArch##*-}" in \
amd64) ARCH='x64';; \
ppc64el) ARCH='ppc64le';; \
s390x) ARCH='s390x';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armv7l';; \
i386) ARCH='x86';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
# gpg keys listed at https://github.com/nodejs/node#release-keys
&& set -ex \
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
61FC681DFB92A079F1685E77973F295594EC4689 \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
A363A499291CBBC940DD62E41F10027AF002F8B0 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
# smoke tests
&& node --version \
&& npm --version \
&& cd /home/site/wwwroot/node \
&& npm install \
&& cd /home/site/wwwroot/node/node_modules/puppeteer \
&& npm install \
&& cd /

ENV YARN_VERSION 1.22.19

RUN set -ex \
&& for key in \
6A010C5166006599AA17F08146C2130DFD2497F5 \
; do \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
done \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& mkdir -p /opt \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
# smoke test
&& yarn --version

# Chrome headless dependencies
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
RUN apt-get install -y xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

USER root

RUN chmod 777 /home/site/wwwroot/start.sh

CMD ["/home/site/wwwroot/start.sh"]
12 changes: 0 additions & 12 deletions docker/docker-compose.yml

This file was deleted.

8 changes: 1 addition & 7 deletions integration-test/src/features/generate_pdf.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@ Feature: Generate a PDF document
Given a Map of key-values
When an Http POST request is sent to the PDF Engine with key-values and without a zip file
Then response has a 400 Http status
And application error code is "PDFE_897"

Scenario: Execute a GeneratePDF request with Playwright
Given a zip file, that contains a valid HTML template to use in Playwright
And a Map of key-values
When an Http POST request is sent to the PDF Engine with a zip file and the key-values and with Playwright Engine
Then response has a 200 Http status
And application error code is "PDFE_897"
5 changes: 1 addition & 4 deletions integration-test/src/step_definitions/pdf_engine_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ const FormData = require('form-data');

const pdf_engine_uri = process.env.PDF_ENGINE_URI;

function generatePDF(zipFile, inputData, engineType) {
function generatePDF(zipFile, inputData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

const form = new FormData();
if (zipFile !== null) {
form.append('template', zipFile);
}
if (inputData !== null) {
form.append('data', inputData);
}
if (engineType !== null) {
form.append("generatorType", engineType);
}

return postForm(pdf_engine_uri, form);
}
Expand Down
14 changes: 3 additions & 11 deletions integration-test/src/step_definitions/pdf_engine_step.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const {generatePDF} = require('./pdf_engine_client');
});

When('an Http POST request is sent to the PDF Engine with a zip file and the key-values', async function () {
this.response = await generatePDF(this.zipFile, this.inputData, "ITEXT");
this.response = await generatePDF(this.zipFile, this.inputData);
});

When('an Http POST request is sent to the PDF Engine with a zip file and without key-values', async function () {
this.response = await generatePDF(this.zipFile, null, "ITEXT");
this.response = await generatePDF(this.zipFile, null);
});

When('an Http POST request is sent to the PDF Engine with key-values and without a zip file', async function () {
this.response = await generatePDF(null, this.inputData, "ITEXT");
this.response = await generatePDF(null, this.inputData);
});

Then('response has a {int} Http status', function (expectedStatus) {
Expand All @@ -29,12 +29,4 @@ Then('response has a {int} Http status', function (expectedStatus) {

Then('application error code is {string}', function (expectedAppErrorCode) {
assert.strictEqual(this.response.data.appErrorCode, expectedAppErrorCode);
});

Given('a zip file, that contains a valid HTML template to use in Playwright', function () {
this.zipFile = readZipFile("template.zip");
});

When('an Http POST request is sent to the PDF Engine with a zip file and the key-values and with Playwright Engine', async function () {
this.response = await generatePDF(this.zipFile, this.inputData, "PLAYWRIGHT");
});
7 changes: 0 additions & 7 deletions local.settings.json

This file was deleted.

48 changes: 48 additions & 0 deletions node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
bin
obj
csx
.vs
edge
Publish

*.user
*.suo
*.cscfg
*.Cache
project.lock.json

/packages
/TestResults

/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json
local.settings.json

node_modules
dist

# Local python packages
.python_packages/

# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
177 changes: 177 additions & 0 deletions node/__mocks__/@anzp/azure-function-multipart.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions node/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: "node",
testPathIgnorePatterns: ["dist", "/node_modules", "__integrations__"],
testRegex: "(/__tests__/.*\\.(test|spec))\\.(jsx?|tsx?)$",
};
Loading