Skip to content

Commit

Permalink
MARP-224 Create dockerfiles for deployment of marketplace (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Hoan Nguyen <[email protected]>
Co-authored-by: ivyTeam <[email protected]>
Co-authored-by: tutn <[email protected]>
Co-authored-by: Dinh Nguyen <[email protected]>
  • Loading branch information
5 people authored Jul 22, 2024
1 parent b92ce87 commit 2bb6a99
Show file tree
Hide file tree
Showing 36 changed files with 550 additions and 155 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Build

on:
push:
branches: [ "develop" ]
workflow_dispatch:
workflow_call:

jobs:
build:
runs-on: self-hosted

steps:
- uses: actions/checkout@v4
- name: Update environment variables for .env
env:
ENV_FILE: './marketplace-build/.env'
MONGODB_HOST: ${{ secrets.MONGODB_HOST }}
ROOT_USERNAME: ${{ secrets.MONGODB_ROOT_USERNAME }}
ROOT_PASSWORD: ${{ secrets.MONGODB_ROOT_PASSWORD }}
SERVICE_USERNAME: ${{ secrets.SERVICE_USERNAME }}
SERVICE_PASSWORD: ${{ secrets.SERVICE_PASSWORD }}
MONGODB_DATABASE: ${{ secrets.MONGODB_DATABASE }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MARKETPLACE_INSTALLATION_URL: ${{ secrets.MARKETPLACE_INSTALLATION_URL }}
run: |
sed -i "s/^MONGODB_INITDB_ROOT_USERNAME=.*$/MONGODB_INITDB_ROOT_USERNAME=$ROOT_USERNAME/" $ENV_FILE
sed -i "s/^MONGODB_INITDB_ROOT_PASSWORD=.*$/MONGODB_INITDB_ROOT_PASSWORD=$ROOT_PASSWORD/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_HOST=.*$/SERVICE_MONGODB_HOST=$MONGODB_HOST/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_DATABASE=.*$/SERVICE_MONGODB_DATABASE=$MONGODB_DATABASE/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_USER=.*$/SERVICE_MONGODB_USER=$SERVICE_USERNAME/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_PASSWORD=.*$/SERVICE_MONGODB_PASSWORD=$SERVICE_PASSWORD/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE
sed -i "s/^MARKETPLACE_INSTALLATION_URL=.*$/MARKETPLACE_INSTALLATION_URL=$MARKETPLACE_INSTALLATION_URL/" $ENV_FILE
- name: Refresh Docker images
working-directory: ./marketplace-build
run: |
docker compose down
docker compose up -d
49 changes: 49 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Docker Release

on:
push:
branches: [ "master" ]
workflow_dispatch:
inputs:
image_version:
description: 'Marketplace Docker image version'
required: true
default: 'latest'

env:
UI_IMAGE_NAME: marketplace-ui
SERVICE_IMAGE_NAME: marketplace-service

jobs:

build:
uses: ./.github/workflows/docker-build.yml

release:
needs: build
runs-on: self-hosted
permissions:
packages: write
contents: read

steps:
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Refine release version
run: |
# This strips the git ref prefix from the version.
VERSION=${{ github.event.inputs.image_version }}
# This uses the Docker `latest` tag convention.
[ "$VERSION" == "main" ] && VERSION=latest
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Release Marketplace UI image
run: |
UI_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$UI_IMAGE_NAME
docker tag $UI_IMAGE_NAME $UI_IMAGE_ID:$VERSION
docker push $UI_IMAGE_ID:$VERSION
- name: Release Marketplace Service image
run: |
SERVICE_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$SERVICE_IMAGE_NAME
docker tag $SERVICE_IMAGE_NAME $SERVICE_IMAGE_ID:$VERSION
docker push $SERVICE_IMAGE_ID:$VERSION
2 changes: 2 additions & 0 deletions .github/workflows/service-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ run-name: Build Service on branch ${{github.ref_name}} triggered by ${{github.ac

on:
push:
paths:
- 'marketplace-service/**'
workflow_dispatch:

jobs:
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/service-dev-build.yml

This file was deleted.

24 changes: 18 additions & 6 deletions .github/workflows/ui-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ run-name: Build on branch ${{github.ref_name}} triggered by ${{github.actor}}

on:
push:
branches-ignore:
- develop
- master
paths:
- 'marketplace-ui/**'
workflow_dispatch:

jobs:
Expand All @@ -20,10 +19,15 @@ jobs:
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: ./marketplace-ui/package-lock.json
- name: Install Dependencies
run: npm install
run: |
cd ./marketplace-ui
npm install
- name: Build project
run: npm run build
run: |
cd ./marketplace-ui
npm run build
analysis:
name: Sonarqube
Expand All @@ -36,22 +40,30 @@ jobs:

steps:
- name: Execute Tests
run: npm run test
run: |
cd ./marketplace-ui
npm run test
- uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ env.SONAR_HOST_URL }}
with:
projectBaseDir: ./marketplace-ui
args:
-Dsonar.projectKey=${{ env.SONAR_PROJECT_KEY }}
-Dsonar.javascript.lcov.reportPaths=${{ github.workspace }}/marketplace-ui/coverage/lcov.info

- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
with:
scanMetadataReportFile: ${{ github.workspace }}/marketplace-ui/.scannerwork/report-task.txt
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ env.SONAR_HOST_URL }}

- name: Clean up
working-directory: marketplace-ui
run: |
rm -rf *
28 changes: 0 additions & 28 deletions .github/workflows/ui-dev-build.yml

This file was deleted.

37 changes: 10 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.5/maven-plugin/reference/html/)
* [Spring Data MongoDB](https://docs.spring.io/spring-boot/docs/3.2.5/reference/htmlsingle/index.html#data.nosql.mongodb)
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.2.5/reference/htmlsingle/index.html#web)
For AxonIvy Marketplace, we have 3 parts: marketplace-ui, marketplace-service, and marketplace-build:
* ``marketplace-ui``: is an Angular project, built on v18 and contains the frontend code for the website.
* ``marketplace-service``: is a SpringBoot project, built on v3.2.5 and includes the apis code for the website.
* ``marketplace-build``: is a folder to keep everything related to build and dockers.

### Guides
The following guides illustrate how to use some features concretely:

* Installing mongodb, and access it as Url mongodb://localhost:27017/, and you can create and name whatever you want ,then you should put them to application.properties
* You can change the MongoDB configuration in file `application.properties`
```
spring.data.mongodb.host=
spring.data.mongodb.database=
```
* Update GitHub token in file `github.token`
* Run mvn clean install to build project
* Run mvn test to test all tests
* How to start the Marketplace UI refer to the [marketplace-ui guide][1]

* How to start the Marketplace Service refer to the [marketplace-service guide][2]

### Access Swagger URL: http://{your-host}/swagger-ui/index.html
* How to start the Marketplace Build refer to the [marketplace-build guide][3]

### Install Lombok for Eclipse IDE
* Download lombok here https://projectlombok.org/download
* run command "java -jar lombok.jar" then you can access file “eclipse.ini“ in eclipse folder where you install → there is a text like this: -javaagent:C:\Users\tvtphuc\eclipse\jee-2024-032\eclipse\lombok.jar → it means you are successful
* Start eclipse
* Import the project then in the eclipse , you should run the command “mvn clean install“
* After that you go to class MarketplaceServiceApplication → right click to main method → click run as → choose Java Application
* Then you can send a request in postman
* If you want to run single test in class UserServiceImplTest. You can right-click to method testFindAllUser and right click → select Run as → choose JUnit Test
[1]: marketplace-ui/README.md
[2]: marketplace-service/README.md
[3]: marketplace-build/README.md
2 changes: 2 additions & 0 deletions marketplace-build/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Node
**/node_modules
8 changes: 8 additions & 0 deletions marketplace-build/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MONGODB_INITDB_ROOT_USERNAME=
MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=
SERVICE_MONGODB_USER=
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=
MARKET_GITHUB_TOKEN=
MARKETPLACE_INSTALLATION_URL=
1 change: 0 additions & 1 deletion marketplace-build/Dockerfile

This file was deleted.

5 changes: 3 additions & 2 deletions marketplace-build/Marketplace Tomcat v10.1 Server.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<launchConfiguration type="org.eclipse.jst.server.tomcat.core.launchConfigurationType">
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
<mapEntry key="MONGODB_DATABASE" value="marketplace"/>
<mapEntry key="MONGODB_HOST" value="localhost:27017"/>
<mapEntry key="MARKET_GITHUB_TOKEN" value=""/>
<mapEntry key="MONGODB_DATABASE" value=""/>
<mapEntry key="MONGODB_HOST" value=""/>
<mapEntry key="MONGODB_PASSWORD" value=""/>
<mapEntry key="MONGODB_USERNAME" value=""/>
</mapAttribute>
Expand Down
33 changes: 33 additions & 0 deletions marketplace-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Get starts with Marketplace build

### Set up MongoDB with authentication mode
* Navigate to ``marketplace-build/config/mongodb`` and execute the ``docker-compose up -d`` to start MongoDB with non-auth mode and create a root admin user.

* [Optional] Execute authentication test for the created user
```
use admin
db.auth('username','password')
```
This command should return the ``OK`` code

* Down the non-authen instance to start the main docker compose file by run ``docker-compose down``

### Docker build for DEV environment
* Navigate to ``marketplace-build``

* Run ``docker-compose up -d --build`` to start a Marketplace DEV at the local

### Docker release
To release a new version for marketplace images, please trigger the ``Docker Release`` actions.
* This GH Actions will trigger the ``Docker build`` on the master branch.
* Login to GitHub Registry Hub.
* Deploy new image to packages.
Please verify the result in the ``Package`` after the build is completed.

### Start Docker compose for PROD deployment
* Navigate to ``marketplace-build/release`` run ``docker-compose up -d`` to clone the docker images from GitHub packages and start the website

### Start Docker compose using SPRINT release version
* Navigate to ``marketplace-build/release`` run ``docker-compose -f sprint-compose.yml up`` to clone the docker images from GitHub packages and start the website


11 changes: 11 additions & 0 deletions marketplace-build/config/mongodb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use the base image for MongoDB
FROM mongodb/mongodb-community-server:7.0.0-ubi8

# Copy the custom MongoDB configuration file into the container
COPY mongod.conf /etc/mongod.conf

# Expose MongoDB port
EXPOSE 27017

# Define the default command to run MongoDB with the custom configuration
CMD ["mongod", "--config", "/etc/mongod.conf"]
18 changes: 18 additions & 0 deletions marketplace-build/config/mongodb/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This docker compose to init mongo for setup auth
name: marketplace

services:
mongodb:
container_name: marketplace-mongodb-non-authen
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "27017:27017"
volumes:
- mongodata:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

volumes:
mongodata:
12 changes: 12 additions & 0 deletions marketplace-build/config/mongodb/mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
db = db.getSiblingDB('admin');
db.createUser(
{
user: "username",
pwd: "password",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" },
{ role: 'root', db: 'admin' }
]
}
)
5 changes: 5 additions & 0 deletions marketplace-build/config/mongodb/mongod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
security:
authorization: enabled
net:
bindIpAll: true
port: 27017
Loading

0 comments on commit 2bb6a99

Please sign in to comment.