Skip to content

Commit

Permalink
Pimp up README
Browse files Browse the repository at this point in the history
Add new workflow
  • Loading branch information
nqhoan-axonivy committed Jul 16, 2024
1 parent a9c8f26 commit 7a31c8f
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 228 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Docker build

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

jobs:
build:
runs-on: self-hosted

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build Marketplace service project
run: |
cd ./marketplace-service
mvn clean install -DskipTests
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: ./marketplace-ui/package-lock.json
- name: Build Marketplace ui project
run: |
cd ./marketplace-ui
npm i
npm run build --prod
- 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 }}
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
- name: Refresh Docker images
working-directory: ./marketplace-build
run: |
docker compose down
docker compose -f docker-compose.yml up -d
38 changes: 0 additions & 38 deletions .github/workflows/docker-compose-build.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Docker Release

on:
push:
branches: [ "master" ]
workflow_dispatch:

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=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# This strips the "v" prefix from the tag name.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# 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.

5 changes: 2 additions & 3 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 Down
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
3 changes: 3 additions & 0 deletions marketplace-build/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
MONGODB_INITDB_ROOT_USERNAME=
MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=
SERVICE_MONGODB_USER=
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=
MARKET_GITHUB_TOKEN=
10 changes: 0 additions & 10 deletions marketplace-build/Dockerfile-NGINX

This file was deleted.

19 changes: 8 additions & 11 deletions marketplace-build/Dockerfile-UI
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Stage 2: Serve the Angular application with Nginx
FROM nginx:alpine

# Copy the built Angular application from the previous stage
COPY --from=assets browser /usr/share/nginx/html

# use the latest version of the official nginx image as the base image
FROM nginx:latest
# copy the custom nginx configuration file to the container in the
# default location
COPY ./config/nginx/nginx.conf /etc/nginx/nginx.conf
# copy the built Angular app files to the default nginx html directory
#COPY /dist/browser /usr/share/nginx/html
COPY --from=assets browser /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx server
CMD ["nginx", "-g", "daemon off;"]
# the paths are relative from the Docker file
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
51 changes: 51 additions & 0 deletions marketplace-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Get starts with Marketplace build

### Set up MongoDB with authentication mode
* Navigate to ``marketplace-build/config/mongodb`` and execute the ``docker-compose up`` to start MongoDB with non-auth mode
* Create root user for authentication
```
use admin
db.createUser(
{
user: "username",
pwd: "password",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
db.grantRolesToUser('username', [{ role: 'root', db: 'admin' }])
```

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

### Docker build for DEV environment
* Navigate to ``marketplace-service`` and execute maven build for spring-boot app to get the war file:
```
mvn clean install -DskipTests
```

* Navigate to ``marketplace-ui`` and execute node install and run the angular app to get the dist folder:
```
npm instal
npm run build --prod
```

* Please run ``docker-compose up --build`` from folder ``marketplace-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.

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

0 comments on commit 7a31c8f

Please sign in to comment.