Skip to content

Commit

Permalink
add release build
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhoan-axonivy committed Jul 16, 2024
1 parent 588cd40 commit 388e3f4
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 90 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Docker compose up
name: Docker build for DEV

on:
push:
Expand All @@ -17,21 +17,21 @@ jobs:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build APIs
- name: Build Service project
run: |
cd ./marketplace-service
mvn clean install -DskipTests
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'
cache: 'npm'
cache-dependency-path: ./marketplace-ui/package-lock.json
- name: Build UI
- name: Build UI project
run: |
cd ./marketplace-ui
npm i
npm run build --prod
- name: Update configuration
- name: Update configuration for ENV
env:
ENV_FILE: './marketplace-build/.env'
MONGODB_HOST: ${{ secrets.MONGODB_HOST }}
Expand All @@ -40,15 +40,17 @@ jobs:
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: Build and push Docker images
- name: Refresh Docker images
working-directory: ./marketplace-build
run: |
docker compose down
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Docker build and release

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

env:
UI-IMAGE_NAME: marketplace-ui
SERVICE-IMAGE_NAME: marketplace-ui

jobs:

build:
uses: ./docker-compose-build.yml

publish:
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: Push UI image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$UI-IMAGE_NAME
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# 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 IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $UI-IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Push Service image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$SERVICE-IMAGE_NAME
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# 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 IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $SERVICE-IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
42 changes: 0 additions & 42 deletions .github/workflows/service-dev-build.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/ui-dev-build.yml

This file was deleted.

3 changes: 2 additions & 1 deletion marketplace-build/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ MONGODB_INITDB_ROOT_PASSWORD=
SERVICE_MONGODB_HOST=
SERVICE_MONGODB_USER=
SERVICE_MONGODB_PASSWORD=
SERVICE_MONGODB_DATABASE=
SERVICE_MONGODB_DATABASE=
MARKET_GITHUB_TOKEN=
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
28 changes: 27 additions & 1 deletion marketplace-build/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# Get start
# Get start 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 authen
```
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 test authen for created user
```
use admin
db.auth('username','password')
```
This command should return ``OK``

### Docker compose for DEV environment
* Navigate to ``marketplace-service`` and execute maven build for springboot app to get the war file:
Expand Down
3 changes: 3 additions & 0 deletions marketplace-build/config/mongodb/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This docker compose to init mongo for setup auth
name: marketplace

services:
mongodb:
image: mongodb/mongodb-community-server:7.0.0-ubi8
Expand Down
9 changes: 7 additions & 2 deletions marketplace-build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- ./config/mongodb/mongod.conf:/etc/mongod.conf
command: ["mongod", "--config", "/etc/mongod.conf"]

marketplace-ui:
ui:
build:
context: .
additional_contexts:
Expand All @@ -26,8 +26,10 @@ services:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- "90:80"
depends_on:
- service

marketplace-service:
service:
image: marketplace-service
container_name: marketplace-service
restart: always
Expand All @@ -36,6 +38,7 @@ services:
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
- MONGODB_USERNAME=${SERVICE_MONGODB_USER}
- MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD}
- MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN}
build:
context: .
additional_contexts:
Expand All @@ -45,6 +48,8 @@ services:
- ../marketplace-service/target/marketplace-service-0.0.1-SNAPSHOT.war:/usr/local/tomcat/webapps/marketplace-service.war
ports:
- "8080:8080"
depends_on:
- mongodb

volumes:
mongodata:
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.axonivy.market.github.model;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "market.github")
public class GitHubProperty {

private String token;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.axonivy.market.github.service.impl;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

import org.kohsuke.github.GHContent;
Expand All @@ -12,20 +10,22 @@
import org.kohsuke.github.GitHubBuilder;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;

import com.axonivy.market.github.model.GitHubProperty;
import com.axonivy.market.github.service.GitHubService;

@Service
public class GitHubServiceImpl implements GitHubService {

private static final String GITHUB_TOKEN_FILE = "classpath:github.token";
private GitHubProperty gitHubProperty;

public GitHubServiceImpl(GitHubProperty gitHubProperty) {
this.gitHubProperty = gitHubProperty;
}

@Override
public GitHub getGitHub() throws IOException {
File gitHubToken = ResourceUtils.getFile(GITHUB_TOKEN_FILE);
var token = Files.readString(gitHubToken.toPath());
return new GitHubBuilder().withOAuthToken(token.trim().strip()).build();
return new GitHubBuilder().withOAuthToken(gitHubProperty.getToken().trim().strip()).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ server.forward-headers-strategy=framework
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
market.cors.allowed.origin.maxAge=3600
market.github.token=${MARKET_GITHUB_TOKEN}
logging.level.org.springframework.security=DEBUG
1 change: 0 additions & 1 deletion marketplace-service/src/main/resources/github.token

This file was deleted.

0 comments on commit 388e3f4

Please sign in to comment.