Skip to content

Commit

Permalink
Merge pull request #459 from adessoSE/Docker-Update
Browse files Browse the repository at this point in the history
updated docker, fixed tests for docker
  • Loading branch information
i3rotlher authored Aug 28, 2023
2 parents 96a1feb + fdecd0b commit 8624e78
Show file tree
Hide file tree
Showing 14 changed files with 716 additions and 145 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/Build_and_Publish_Images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and Publish Docker Image

on:
push:
tags:
- 'Seed-Test_v*'

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get Tag Name
id: get_tag_name
run: |
version=$(echo $GITHUB_REF | sed 's/refs\/tags\///' | sed 's/.*_//')
echo "version=${version}" >> ${GITHUB_OUTPUT}
# BACKEND
- name: Build Docker Image
run: docker build -t seed-test-backend:${{ steps.get_tag_name.outputs.version }} ./backend

- name: Tag Docker Image as Latest
run: |
docker tag seed-test-backend:${{ steps.get_tag_name.outputs.version }} ${{ secrets.DOCKER_USERNAME }}/seed-test-backend:${{ steps.get_tag_name.outputs.version }}
docker tag seed-test-backend:${{ steps.get_tag_name.outputs.version }} ${{ secrets.DOCKER_USERNAME }}/seed-test-backend:latest
- name: Push Docker Image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/seed-test-backend:${{ steps.get_tag_name.outputs.version }}
docker push ${{ secrets.DOCKER_USERNAME }}/seed-test-backend:latest
# FRONTEND
- name: Build Docker Image
run: docker build -t seed-test-frontend:${{ steps.get_tag_name.outputs.version }} ./frontend

- name: Tag Docker Image as Latest
run: |
docker tag seed-test-frontend:${{ steps.get_tag_name.outputs.version }} ${{ secrets.DOCKER_USERNAME }}/seed-test-frontend:${{ steps.get_tag_name.outputs.version }}
docker tag seed-test-frontend:${{ steps.get_tag_name.outputs.version }} ${{ secrets.DOCKER_USERNAME }}/seed-test-frontend:latest
- name: Push Docker Image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/seed-test-frontend:${{ steps.get_tag_name.outputs.version }}
docker push ${{ secrets.DOCKER_USERNAME }}/seed-test-frontend:latest
14 changes: 8 additions & 6 deletions .github/workflows/CI_Tests_and_Report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
- name: Build and start Docker stack
run: |
chmod +x runDocker.sh
./runDocker.sh
docker compose -f docker-test.yml up -d
- name: Send failure notification
if: ${{ failure() }}
Expand Down Expand Up @@ -89,7 +88,8 @@ jobs:
id: passed-total-backend

- name: Upload Artifact Backend
uses: actions/upload-artifact@v2
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
with:
name: test-results-backend
path: |
Expand Down Expand Up @@ -122,7 +122,8 @@ jobs:
id: passed-total-frontend

- name: Upload Artifact Frontend
uses: actions/upload-artifact@v2
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
with:
name: test-results-frontend
path: |
Expand Down Expand Up @@ -157,7 +158,8 @@ jobs:
id: passed-total-sanity

- name: Upload Artifact Sanity
uses: actions/upload-artifact@v2
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
with:
name: sanity-report
path: |
Expand Down Expand Up @@ -191,4 +193,4 @@ jobs:
sanityStepsFailed: ${{ steps.passed-total-sanity.outputs.failedSteps }}
sanityStepsSkipped: ${{ steps.passed-total-sanity.outputs.skippedSteps }}
workflowLink: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
webhook: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
webhook: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
5 changes: 1 addition & 4 deletions .github/workflows/SonarCloud-PR.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
pull_request:
types: [opened, synchronize, reopened]
branches:
- "nie"
gollum
name: SonarCloud
jobs:
sonarcloud:
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ backend/features/reporting_html*.html
*.bat
*.sh
*.ps1
!runDocker.bat
!runDocker.sh

# Website Deployment with IIS
**/web.config
Expand All @@ -79,4 +77,6 @@ backend/features/reporting_html*.html
backend/logs/

# local testing for step-definition development
backend/features/step_definitions/testing.js
backend/features/step_definitions/testing.js

/act
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ It will download NodeJs and the browsers with their correct driver on it's own.

For this [docker](https://www.docker.com/products/docker-desktop/) needs to be installed.

#### Installing Seed
#### Installation of Seed

After installing docker you just simply need to clone the repository and launch the runDocker script matching your OS:
Once you have Docker installed, the process of setting up Seed is straightforward. Follow these steps:

Windows:
1. **Download the Release:**

```
runDocker.bat
```
- Go to the [releases page](https://github.com/adessoSE/Seed-Test/releases) of Seed on GitHub.
- Download the `docker-compose.yml` file from the assets for the specific release you want.
2. **Navigate and Execute:**

Linux:
- Open a terminal.
- Navigate to the directory where you placed the `docker-compose.yml` file using the `cd` command. For instance:
```
cd C:/seed-test
```
- Execute the following command to start the Seed application in the background:
```
docker compose up -d
```

```
runDocker.sh
```

And that's it!
With these steps, you'll have Seed up and running using Docker with the downloaded `docker-compose.yml` file. This will initiate the necessary services, volumes and configurations for the application (mongoDB, seed-test-frontend, seed-test-backend).

Seed-Test can now be accessed via `http://localhost:4200/login`

Expand All @@ -56,25 +60,51 @@ Seed-Test now runs within docker with default values which means the following:
- GitHub functionalities don't work:
To get GitHub functionalities to work you need to create and link a [GitHub OAuth App](https://docs.github.com/de/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app).
- Salt and secrets are defaults:They should be changed for generating secure passwords!
- The mongoDB used has a default username and password. This should be changed for a secure database:To change this change the values in the docker-compose.yml
- The mongoDB used has a default username and password:
This should be changed for a secure database.

To know how to change this look at the configure section below.

#### ⚙️ Configuration:

Seed-Test's front- and backend can be configured sepreratly.
To configure anything when running seed via docker, you can simply adjust the environment variables for each container in the docker-compose.yml file and rerun the command:

##### Backend:
##### Backend

To configure the backend create a file with the name ".env" in the /backend directory.
Now you can configure the backend by adding parameters shown in the .env.example file.
| Variable | Description |
| :----------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DATABASE_URI* | The mongoDB Connection String URI. This can be replaced with your own mongoDB.<br />If you are using the MongoDB provided by docker-compose, this needs to match the values set for the mongoDB in the docker compose. |
| REPORT_DELETION_TIME | Time (in minutes) after which the report is deleted. |
| SESSION_SECRET | Session secret to establish a secure connection and prevent session hijacking (used in /backend/src/server.js).<br />See https://www.npmjs.com/package/express-session |
| JIRA_SECRET | Jira Integration : values used for the encryption of sensible data.<br />Choose a strong Secret like for example generated by RandomKeygen. |
| JIRA_SALT | The salt should be a random string of at least 16 bytes length. |
| EMAIL_AUTH | Mail adress to send password reset mails (used in /backend/src/nodemailer.js) |
| EMAIL_PW | Mail password credentials to send password reset mails (used in /backend/src/nodemailer.js) |
| EMAIL_PORT | Mail server port to send password reset mails (used in /backend/src/nodemailer.js) |
| EMAIL_HOST | Mail server adress to send password reset mails (used in /backend/src/nodemailer.js) |
| GITHUB_CLIENT_SECRET | GitHub integration. Check out GitHub´s Guide on Autorizing OAuth Apps. |
| GITHUB_CLIENT_ID | GitHub integration. Check out GitHub´s Guide on Autorizing OAuth Apps. |
| PASSPORT_GITHUB_LOCAL_PW_FIELD | GitHub integration. Check out GitHub´s Guide on Autorizing OAuth Apps. |
| MAX_SAVED_REPORTS | The amount of maximum saved reports. |

##### Frontend:
*If you are not using the mongoDB provided by this docker-compose you can completely delete the seedmongodb section from the docker-compose.yml and remove the depends on part of the backend service.

To configure the frontend create a file with the name ".env" in the /frontend directory.
Now you can configure the frontend by adding parameters shown in the .env.example file.
##### Frontend

The dockerRun script needs to be run after any changes to the ".env" files.
| Variable | Meaning |
| :--------------- | :--------------------------------------------------------------------------------- |
| GITHUB_CLIENT_ID | GitHub integration. Check out GitHub´s Guide on Autorizing OAuth Apps. |
| VERSION | This controls if the demo warning is shown. Set this to "set" to make it disapear. |

##### Database

| Variable | Meaning |
| :-------------------------- | :-------------------------------------------------- |
| MONGO_INITDB_ROOT_USERNAME* | The username which should be used for the database. |
| MONGO_INITDB_ROOT_PASSWORD* | The password which should be used for the database. |
| MONGO_INITDB_DATABASE* | The name which should be used for the database. |

*By modifying any of these variables, remember to adjust the corresponding database URI in the backend configuration as well.

### 🤙 By hand:

Expand Down Expand Up @@ -165,7 +195,7 @@ Now you can configure the backend by adding parameters shown in the .env.example
##### Frontend:

To configure the frontend create a file with the name ".env" in the /frontend directory.
Now you can configure the frontendby adding parameters shown in the .env.example file.
Now you can configure the frontend by adding parameters shown in the .env.example file.

## Database

Expand All @@ -190,4 +220,4 @@ Copyright (c) 2018 adesso SE Permission is hereby granted, free of charge, to an

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71 changes: 36 additions & 35 deletions actions/fullReport/indexReport.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
// Helper function to parse environment variables or fallback to "-"
const parseValueOrDefault = (value) => {
return value ? parseInt(value) : 0;
};

function calculatePercentage(num1, num2) {
if (isNaN(num1) || isNaN(num2)) {
return "-";
}

// Check if either number is zero to avoid division by zero error
if (num2 === 0) {
return "-";
}

// Calculate the percentage with two decimal places
const percentage = (num1 / num2) * 100;
const formattedPercentage = percentage.toFixed(0);

return formattedPercentage + "%";
}

function getStatus(passed, total) {
if (passed === 0) return "⚠️";
return passed === total ? "✅" : "⚠️";
}

function calcTotal(dockerStatus, num1, num2) {
if (!dockerStatus) return "-";
if (isNaN(num1)) num1 = 0;
if (isNaN(num2)) num1 = 0;
return num1+num2;
}

async function postMessage() {
const fetch = await import('node-fetch').then((module) => module.default);
const webhook = process.env.INPUT_WEBHOOK;
Expand All @@ -10,39 +44,6 @@ async function postMessage() {
const description = process.env.INPUT_DESCRIPTION || "- No Description";
const dockerStatus = (process.env.INPUT_DOCKERSTATUS === "success");
const workflowLink = process.env.INPUT_WORKFLOWLINK || "";

// Helper function to parse environment variables or fallback to "-"
const parseValueOrDefault = (value) => {
return value ? parseInt(value) : "-";
};

function calculatePercentage(num1, num2) {
if (isNaN(num1) || isNaN(num2)) {
return "-";
}

// Check if either number is zero to avoid division by zero error
if (num2 === 0) {
return "-";
}

// Calculate the percentage with two decimal places
const percentage = (num1 / num2) * 100;
const formattedPercentage = percentage.toFixed(0);

return formattedPercentage + "%";
}

function getStatus(passed, total) {
return passed === total ? "✅" : "⚠️";
}

function calcTotal(dockerStatus, num1, num2) {
if (!dockerStatus) return "-";
if (isNaN(num1) || isNaN(num2)) return "-";
return num1+num2;
}


// Frontend block
const frontendSuitsPassed = parseValueOrDefault(process.env.INPUT_FRONTENDSUITSPASSED);
Expand Down Expand Up @@ -244,6 +245,6 @@ async function postMessage() {
console.error('Error occurred:', error);
process.exit(-1);
}
}
}

postMessage();
postMessage();
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"<rootDir>/spec/server.spec.js",
"<rootDir>/spec/serverHelper.spec.js",
"<rootDir>/node_modules/"
]
],
"setupFiles": ["./spec/setupTest.js"]
}
}
1 change: 1 addition & 0 deletions backend/spec/setupTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('dotenv').config();
Loading

0 comments on commit 8624e78

Please sign in to comment.