Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Opensergo to access SCA #2523

Open
wants to merge 7 commits into
base: 2021.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Docker Image

on:
release:
types:
- published
workflow_dispatch:

env:
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=30 -DskipTests

jobs:
deploy-docker-iamge:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v2

# setup docker
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# build target with maven
- name: Cache Maven Repos
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: set environment
run: export MAVEN_OPTS=' -Dmaven.javadoc.skip=true -Drat.skip=true -Djacoco.skip=true $MAVEN_OPTS'
- name: Build Project
run: |
./mvnw -B -Prelease,docker -DskipTests clean install
docker image ls --format "{{.ID}} {{.Repository}} {{.Tag}}" | grep apache| sed 's/apache\//${{ secrets.DOCKERHUB_USERNAME }}\//' |tr A-Z a-z |awk '{system("docker tag "$1" "$2":latest;docker tag "$1" "$2":"$3";")}'
- name: Push Docker Image
run: |
echo Docker Images:
echo `docker image ls|grep -i ${{ secrets.DOCKERHUB_USERNAME }}|awk '{print $1":"$2}'`
docker image ls|grep -i ${{ secrets.DOCKERHUB_USERNAME }}|awk '{print $1":"$2}'|xargs -i docker push {}
26 changes: 26 additions & 0 deletions spring-cloud-alibaba-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<properties>
<revision>2021.0.1.1-SNAPSHOT</revision>
<sentinel.version>1.8.3</sentinel.version>
<opensergo.version>0.0.1</opensergo.version>
<seata.version>1.4.2</seata.version>
<nacos.client.version>1.4.2</nacos.client.version>
<nacos.config.version>0.8.0</nacos.config.version>
Expand Down Expand Up @@ -120,6 +121,18 @@
<version>${sentinel.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-dubbo-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-reactor-adapter</artifactId>
Expand Down Expand Up @@ -155,6 +168,12 @@
<version>${sentinel.version}</version>
</dependency>

<dependency>
<groupId>io.opensergo</groupId>
<artifactId>opensergo-java</artifactId>
<version>${opensergo.version}</version>
</dependency>

<!--Alibaba Seata-->
<dependency>
<groupId>io.seata</groupId>
Expand Down Expand Up @@ -234,6 +253,13 @@
<version>${revision}</version>
</dependency>

<!-- Dubbo -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion spring-cloud-alibaba-starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
<packaging>pom</packaging>
<name>Spring Cloud Alibaba Starters</name>
<description>Spring Cloud Alibaba Starters</description>

<modules>
<module>spring-cloud-starter-alibaba-nacos-config</module>
<module>spring-cloud-starter-alibaba-nacos-config-server</module>
<module>spring-cloud-starter-alibaba-nacos-discovery</module>
<module>spring-cloud-starter-alibaba-opensergo</module>
<module>spring-cloud-starter-alibaba-seata</module>
<module>spring-cloud-starter-stream-rocketmq</module>
<module>spring-cloud-starter-bus-rocketmq</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-starters</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>spring-cloud-starter-alibaba-opensergo</artifactId>
<name>Spring Cloud Starter Alibaba OpenSergo</name>

<dependencies>

<!--spring boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>

<dependency>
<groupId>io.opensergo</groupId>
<artifactId>opensergo-java</artifactId>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.44.1</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.opensergo;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.alibaba.cloud.opensergo.condition.OnEnvCondition;
import com.alibaba.cloud.opensergo.reportor.ServiceContractReporter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

/**
* @author complone
*/
@Configuration(proxyBeanMethods = false)
@Conditional(OnEnvCondition.class)
public class OpenSergoAutoConfiguration {
private static final Logger log = LoggerFactory
.getLogger(OpenSergoAutoConfiguration.class);

@Autowired(required = false)
private ServiceInstance serviceInstance;

@Bean
public ServiceContractReporter serviceContractReporter(ApplicationContext context)
throws IOException {
String bootstrap = context.getEnvironment()
.getProperty(OpenSergoConstants.OPENSERGO_BOOTSTRAP);
String bootstrapConfig = context.getEnvironment()
.getProperty(OpenSergoConstants.OPENSERGO_BOOTSTRAP_CONFIG);

if (!StringUtils.hasLength(bootstrapConfig) && StringUtils.hasLength(bootstrap)) {
byte[] encoded = Files.readAllBytes(Paths.get(bootstrap));
bootstrapConfig = new String(encoded, StandardCharsets.UTF_8);
}

ObjectMapper objectMapper = new ObjectMapper();
OpenSergoProperties properties = objectMapper.readValue(bootstrapConfig,
OpenSergoProperties.class);

ServiceContractReporter reporter = new ServiceContractReporter(context,
serviceInstance, properties.getEndpoint());
reporter.reportMetadata();
return reporter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.opensergo;

/**
* @author complone
*/
public final class OpenSergoConstants {

/**
* Prefix of {@link OpenSergoProperties}.
*/
public static final String OPENSERGO_BOOTSTRAP = "OPENSERGO_BOOTSTRAP";

/**
* Prefix of {@link OpenSergoProperties}.
*/
public static final String OPENSERGO_BOOTSTRAP_CONFIG = "OPENSERGO_BOOTSTRAP_CONFIG";

private OpenSergoConstants() {
throw new AssertionError("Must not instantiate constant utility class");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.opensergo;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

/**
* {@link ConfigurationProperties} for OpenSergo.
*
* @author complone
*/
@Validated
public class OpenSergoProperties {

/**
* Earlier initialize heart-beat when the spring container starts when the transport
* dependency is on classpath, the configuration is effective.
*/
private String endpoint = "";

public String getEndpoint() {
return endpoint;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
}
Loading