Skip to content

Commit

Permalink
Merge pull request #113 from axonivy-market/develop
Browse files Browse the repository at this point in the history
MARP-978: Crease new sprint release S21
  • Loading branch information
nqhoan-axonivy authored Aug 26, 2024
2 parents a1e75da + 143799e commit dffb32d
Show file tree
Hide file tree
Showing 135 changed files with 2,296 additions and 1,065 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:

steps:
- name: Bring down and remove containers and images
working-directory: ./marketplace-build
continue-on-error: true
working-directory: ./marketplace-build/dev
run: |
docker compose down --rmi all
Expand All @@ -46,13 +47,12 @@ jobs:

- name: Update environment variables for .env
env:
ENV_FILE: './marketplace-build/.env'
MONGODB_HOST: ${{ secrets.MONGODB_HOST }}
ENV_FILE: './marketplace-build/dev/.env'
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_MARKET_BRANCH: ${{ secrets.MARKET_GITHUB_MARKET_BRANCH }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MARKET_JWT_SECRET_KEY: ${{ secrets.MARKET_JWT_SECRET_KEY }}
MARKET_CORS_ALLOWED_ORIGIN: ${{ secrets.MARKET_CORS_ALLOWED_ORIGIN }}
Expand All @@ -67,10 +67,9 @@ jobs:
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_MARKET_BRANCH=.*$/MARKET_GITHUB_MARKET_BRANCH=$GH_MARKET_BRANCH/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_ID=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_ID=$OAUTH_APP_CLIENT_ID/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=$OAUTH_APP_CLIENT_SECRET/" $ENV_FILE
Expand All @@ -88,13 +87,13 @@ jobs:
sed -i 's/"version": "[^"]*"/"version": "${{ inputs.release_version }}"/' $PACKAGE_FILE
- name: Build and bring up containers without cache
working-directory: ./marketplace-build
working-directory: ./marketplace-build/dev
run: |
if [ -n "${{ inputs.release_version }}" ]; then
BUILD_VERSION="${{ inputs.release_version }}"
else
BUILD_VERSION=$(xml sel -t -v "//_:project/_:version" ../marketplace-service/pom.xml)
BUILD_VERSION=$(xml sel -t -v "//_:project/_:version" ../../marketplace-service/pom.xml)
fi
docker compose build --no-cache --build-arg BUILD_ENV=${{ inputs.build_env }} --build-arg BUILD_VERSION=$BUILD_VERSION
docker compose build --build-arg BUILD_ENV=${{ inputs.build_env }} --build-arg BUILD_VERSION=$BUILD_VERSION
docker compose up --force-recreate -d
8 changes: 3 additions & 5 deletions .github/workflows/ui-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

steps:
- name: Setup chrome
uses: browser-actions/setup-chrome@v1

- name: Execute Tests
run: |
cd ./marketplace-ui
Expand All @@ -62,8 +65,3 @@ jobs:
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ env.SONAR_HOST_URL }}

- name: Clean up
working-directory: marketplace-ui
run: |
rm -rf *
8 changes: 4 additions & 4 deletions marketplace-build/.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
MONGODB_INITDB_ROOT_USERNAME=
MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=
SERVICE_MONGODB_HOST=mongodb
SERVICE_MONGODB_USER=
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=
SERVICE_MONGODB_DATABASE=marketplace
MARKET_GITHUB_MARKET_BRANCH=
MARKET_GITHUB_TOKEN=
MARKETPLACE_INSTALLATION_URL=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
MARKET_CORS_ALLOWED_ORIGIN=
MARKET_CORS_ALLOWED_ORIGIN=*
23 changes: 0 additions & 23 deletions marketplace-build/Marketplace Tomcat v10.1 Server.launch

This file was deleted.

10 changes: 9 additions & 1 deletion marketplace-build/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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.
* Navigate to ``marketplace-build/config/mongodb`` and execute the ``docker-compose -f non-authen-docker-compose.yml up -d`` to start MongoDB with non-auth mode and create a root admin user.

* [Optional] Execute authentication test for the created user
```
Expand All @@ -13,10 +13,18 @@ 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
#### Start from scratch:
* Navigate to ``marketplace-build``

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

#### If you already have MongoDB on your local machine with public port `27017`
* Navigate to ``marketplace-build/dev``

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

> In case you want to set up the MongoDB as a standalone compose. Please run `docker-compose -f authen-docker-compose.yml up -d` in ``marketplace-build/config/mongodb``
### 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.
Expand Down
19 changes: 19 additions & 0 deletions marketplace-build/config/mongodb/authen-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: marketplace-db

services:
mongodb:
container_name: mongodb
build:
dockerfile: Dockerfile
restart: always
ports:
- "27017:27017"
environment:
MONGODB_INITDB_ROOT_USERNAME: ${MONGODB_INITDB_ROOT_USERNAME}
MONGODB_INITDB_ROOT_PASSWORD: ${MONGODB_INITDB_ROOT_PASSWORD}
volumes:
- mongodata:/data/db
- ./mongod.conf:/etc/mongod.conf

volumes:
mongodata:
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This docker-compose to init MongoDB as free access and create a volume as name + mongodata
# Then insert the admin user as defined at mogo-init.js
# Change the name to other if you want to create more volumes. e.g: marketplace-dev
name: marketplace
name: marketplace-db

services:
mongodb:
Expand Down
12 changes: 12 additions & 0 deletions marketplace-build/dev/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MONGODB_INITDB_ROOT_USERNAME=octopus
MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=10.193.8.78
SERVICE_MONGODB_USER=octopus
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=marketplace-dev
MARKET_GITHUB_MARKET_BRANCH=
MARKET_GITHUB_TOKEN=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
MARKET_CORS_ALLOWED_ORIGIN=*
43 changes: 43 additions & 0 deletions marketplace-build/dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: marketplace

services:
ui:
container_name: marketplace-ui
build:
context: ../../marketplace-ui
additional_contexts:
assets: ../../marketplace-build/
dockerfile: Dockerfile
args:
- BUILD_ENV=${BUILD_ENV}
restart: always
volumes:
- ../../marketplace-build/config/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- "4200:80"
depends_on:
- service

service:
container_name: marketplace-service
restart: always
volumes:
- /home/axonivy/marketplace/data/market-installations.json:/home/data/market-installation.json
environment:
- MONGODB_HOST=${SERVICE_MONGODB_HOST}
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
- MONGODB_USERNAME=${SERVICE_MONGODB_USER}
- MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD}
- MARKET_GITHUB_MARKET_BRANCH=${MARKET_GITHUB_MARKET_BRANCH}
- MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN}
- MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID}
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
- MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY}
- MARKET_CORS_ALLOWED_ORIGIN=${MARKET_CORS_ALLOWED_ORIGIN}
build:
context: ../../marketplace-service
dockerfile: Dockerfile
args:
- BUILD_VERSION=${BUILD_VERSION}
ports:
- "8080:8080"
1 change: 1 addition & 0 deletions marketplace-build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
- MONGODB_USERNAME=${SERVICE_MONGODB_USER}
- MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD}
- MARKET_GITHUB_MARKET_BRANCH=${MARKET_GITHUB_MARKET_BRANCH}
- MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN}
- MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID}
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
Expand Down
6 changes: 3 additions & 3 deletions marketplace-build/release/.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
RELEASE_VERSION=sprint
MONGODB_INITDB_ROOT_USERNAME=octopus
MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=mongodb
SERVICE_MONGODB_HOST=localhost
SERVICE_MONGODB_USER=octopus
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=
SERVICE_MONGODB_DATABASE=marketplace
MARKET_GITHUB_MARKET_BRANCH=master
MARKET_GITHUB_TOKEN=
MARKETPLACE_INSTALLATION_URL=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
Expand Down
5 changes: 3 additions & 2 deletions marketplace-build/release/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
context: ../config/mongodb
dockerfile: Dockerfile
restart: always
ports:
- "27017:27017"
expose:
- 27017
environment:
MONGODB_INITDB_ROOT_USERNAME: ${MONGODB_INITDB_ROOT_USERNAME}
MONGODB_INITDB_ROOT_PASSWORD: ${MONGODB_INITDB_ROOT_PASSWORD}
Expand All @@ -33,6 +33,7 @@ services:
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
- MONGODB_USERNAME=${SERVICE_MONGODB_USER}
- MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD}
- MARKET_GITHUB_MARKET_BRANCH=${MARKET_GITHUB_MARKET_BRANCH}
- MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN}
- MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID}
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.axonivy.market.assembler;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.constants.RequestMappingConstants;
import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.enums.NonStandardProduct;
import com.axonivy.market.model.ProductDetailModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Optional;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
Expand All @@ -30,29 +27,36 @@ public ProductDetailModelAssembler(ProductModelAssembler productModelAssembler)

@Override
public ProductDetailModel toModel(Product product) {
return createModel(product, StringUtils.EMPTY);
return createModel(product, StringUtils.EMPTY, StringUtils.EMPTY);
}

public ProductDetailModel toModel(Product product, String version) {
String productId = Optional.ofNullable(product).map(Product::getId).orElse(StringUtils.EMPTY);
return createModel(product, convertVersionToTag(productId, version));
public ProductDetailModel toModel(Product product, String requestPath) {
return createModel(product, StringUtils.EMPTY, requestPath);
}

private ProductDetailModel createModel(Product product, String tag) {
public ProductDetailModel toModel(Product product, String version, String requestPath) {
return createModel(product, version, requestPath);
}

private ProductDetailModel createModel(Product product, String version, String requestPath) {
ResponseEntity<ProductDetailModel> selfLinkWithTag;
ProductDetailModel model = instantiateModel(product);
productModelAssembler.createResource(model, product);
if (StringUtils.isBlank(tag)) {
selfLinkWithTag = methodOn(ProductDetailsController.class).findProductDetails(product.getId());
} else {
selfLinkWithTag = methodOn(ProductDetailsController.class).findProductDetailsByVersion(product.getId(), tag);
}
String productId = Optional.of(product).map(Product::getId).orElse(StringUtils.EMPTY);
selfLinkWithTag = switch (requestPath) {
case RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION ->
methodOn(ProductDetailsController.class).findBestMatchProductDetailsByVersion(productId, version);
case RequestMappingConstants.BY_ID_AND_VERSION ->
methodOn(ProductDetailsController.class).findProductDetailsByVersion(productId, version);
default ->
methodOn(ProductDetailsController.class).findProductDetails(productId);
};
model.add(linkTo(selfLinkWithTag).withSelfRel());
createDetailResource(model, product, tag);
createDetailResource(model, product);
return model;
}

private void createDetailResource(ProductDetailModel model, Product product, String tag) {
private void createDetailResource(ProductDetailModel model, Product product) {
model.setVendor(product.getVendor());
model.setNewestReleaseVersion(product.getNewestReleaseVersion());
model.setPlatformReview(product.getPlatformReview());
Expand All @@ -64,28 +68,6 @@ private void createDetailResource(ProductDetailModel model, Product product, Str
model.setContactUs(product.getContactUs());
model.setCost(product.getCost());
model.setInstallationCount(product.getInstallationCount());

if (StringUtils.isBlank(tag) && StringUtils.isNotBlank(product.getNewestReleaseVersion())) {
tag = product.getNewestReleaseVersion();
}
ProductModuleContent content = getProductModuleContentByTag(product.getProductModuleContents(), tag);
model.setProductModuleContent(content);
}

private ProductModuleContent getProductModuleContentByTag(List<ProductModuleContent> contents, String tag) {
return contents.stream().filter(content -> StringUtils.equals(content.getTag(), tag)).findAny().orElse(null);
}

public String convertVersionToTag(String productId, String version) {
if (StringUtils.isBlank(version)) {
return version;
}
String[] versionParts = version.split(CommonConstants.SPACE_SEPARATOR);
String versionNumber = versionParts[versionParts.length - 1];
NonStandardProduct product = NonStandardProduct.findById(productId);
if (product.isVersionTagNumberOnly()) {
return versionNumber;
}
return GitHubConstants.STANDARD_TAG_PREFIX.concat(versionNumber);
model.setProductModuleContent(CollectionUtils.firstElement(product.getProductModuleContents()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class WebConfig implements WebMvcConfigurer {
private static final String ALL_MAPPINGS = "/**";
private static final String[] EXCLUDE_PATHS = { "/", "/swagger-ui/**", "/api-docs/**" };
private static final String[] ALLOWED_HEADERS = { "Accept-Language", "Content-Type", "Authorization",
"X-Requested-By", "x-requested-with", "X-Forwarded-Host", "x-xsrf-token" };
"X-Requested-By", "x-requested-with", "X-Forwarded-Host", "x-xsrf-token", "x-authorization" };
private static final String[] ALLOWED_METHODS = { "GET", "POST", "PUT", "DELETE", "OPTIONS" };

private final MarketHeaderInterceptor headerInterceptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CommonConstants {
public static final int INITIAL_PAGE = 1;
public static final int INITIAL_PAGE_SIZE = 10;
public static final String REQUESTED_BY = "X-Requested-By";
public static final String LOGO_FILE = "logo.png";
public static final String SLASH = "/";
Expand Down
Loading

0 comments on commit dffb32d

Please sign in to comment.