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

[VL-62] Improve documentation #30

Merged
merged 7 commits into from
Sep 16, 2022
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
6 changes: 3 additions & 3 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build_image:
name: Build the container image
uses: pagopa/pn-local-emulator-poc/.github/workflows/build_push_image.yaml@features/cd-docker-image
uses: pagopa/pn-local-emulator/.github/workflows/build_push_image.yaml@features/cd-docker-image
with:
image_name: ${{ github.repository }}
secrets:
Expand All @@ -18,15 +18,15 @@ jobs:
name: Scan for vulnerabilities
needs:
- build_image
uses: pagopa/pn-local-emulator-poc/.github/workflows/trivy.yaml@features/cd-docker-image
uses: pagopa/pn-local-emulator/.github/workflows/trivy.yaml@features/cd-docker-image
with:
container_image_name: ${{ needs.build_image.outputs.full_image_name }}

push_image:
name: Push the container image to the container registry
needs:
- vulnerabilities_scan
uses: pagopa/pn-local-emulator-poc/.github/workflows/build_push_image.yaml@features/cd-docker-image
uses: pagopa/pn-local-emulator/.github/workflows/build_push_image.yaml@features/cd-docker-image
with:
image_name: ${{ github.repository }}
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: Build the container image
needs:
- build
uses: pagopa/pn-local-emulator-poc/.github/workflows/build_push_image.yaml@features/cd-docker-image
uses: pagopa/pn-local-emulator/.github/workflows/build_push_image.yaml@features/cd-docker-image
with:
image_name: ${{ github.repository }}
push: false
Expand Down
96 changes: 56 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,82 @@
# PnValidator [![CI](https://github.com/pagopa/pn-local-emulator-poc/actions/workflows/ci.yaml/badge.svg)](https://github.com/pagopa/pn-local-emulator-poc/actions/workflows/ci.yaml)
# PnValidator
[![CI](https://github.com/pagopa/pn-local-emulator/actions/workflows/ci.yaml/badge.svg)](https://github.com/pagopa/pn-local-emulator/actions/workflows/ci.yaml)

A system that emulates some features of Piattaforma Notifiche platform.
A system that emulates some features of the Piattaforma Notifiche platform.

## Generate the code
## Prerequisites
If you want to run the emulator locally, starting from the source code, you need to follow the next steps.

Some code is generated from `openapi/index.yaml` file, the first time and when the content of `openapi/index.yaml` changes you should run the following command:
The first thing to do is to clone the repository using the preferred method (the next command uses SSH):

``` sh
npm run generate
```shell
git clone git@github.com:pagopa/pn-local-emulator.git
```

This project runs using [Node.js](https://nodejs.org/en/) and it has been developed with the version specified in the [`.node_version`](.node-version) file.

You could [install nvm](https://github.com/nvm-sh/nvm) and use the next commands to install and set the same version
of Node.js specified in the `.node_version` file.

```shell
# Install the version of Node.js specified in the .node_version file
nvm install `cat .node-version`

# Set the version of Node.js specified in the .node_version file
nvm use `cat .node-version`
```
Make sure that the path of `.node_version` is correct because the example commands assume you are in the repository folder.

## How to run

To run the tool run the following command:
### Run using Node.js

Install the dependencies.

```shell
npm install
```

Generates code from the [OpenAPI](./openapi/index.yaml) specification.

``` sh
# if needed run generate
```shell
npm run generate
```

Start the application.

# start the application
```shell
npm run start
```

## Run with Docker
### Run using Docker (Dockerfile)

The repository comes with a Dockerfile that you can use to run the application with Docker.
First, build the image:

``` sh
Build the image.

```shell
docker build -t pnemulator .
```

Then, run the application:
Run the emulator.

``` sh
```shell
docker run -p 3000:3000 pnemulator
```
The [Dockerfile](./Dockerfile) exposes port `3000` of the container, so you can use the `-p` option to map it to a port of your choice.

### Run using the public container image

Another option is to run the container image available in the container registry.

Pull the image from the container registry.

```shell
docker pull ghcr.io/pagopa/pn-local-emulator:latest
```

### Example

``` sh
# Get the report, initially it shows all 'ko'
curl --location --request GET 'localhost:8080/checklistresult'

# Require an upload slot
curl --request POST 'http://localhost:8080/delivery/attachments/preload' \
--header 'x-api-key: key-value' \
--header 'Content-Type: application/json' \
--data-raw '[
{
"preloadIdx": "1",
"contentType": "application/pdf",
"sha256": "jezIVxlG1M1woCSUngM6KipUN3/a8cG5RMIPnuEanlE="
},
{
"preloadIdx": "2",
"contentType": "application/pdf",
"sha256": "jezIVxlG1M1woCSUngM6KipUN3/a8cG5RMIPnuEanlE="
}
]'

# Get the report, as you can see some result are 'ok'
curl --location --request GET 'localhost:8080/checklistresult'
Run the application.

```shell
docker run -p 3000:3000 ghcr.io/pagopa/pn-local-emulator:latest
```