Skip to content

Commit

Permalink
Merge pull request #419 from FlowCI/develop
Browse files Browse the repository at this point in the history
v1.21.50
  • Loading branch information
gy2006 committed Dec 16, 2021
2 parents 84645d8 + 21742a1 commit ebd5f5c
Show file tree
Hide file tree
Showing 142 changed files with 4,211 additions and 1,801 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MVN_TEST := mvn test -T 4C
CURRENT_DIR := $(shell pwd)

DOCKER_VOLUME := -v $(HOME)/.m2:/root/.m2 -v $(CURRENT_DIR):/ws
DOCKER_IMG := maven:3-openjdk-8
DOCKER_IMG := maven:3-openjdk-11
DOCKER_RUN := docker run -it --rm -w /ws $(DOCKER_VOLUME) --network host $(DOCKER_IMG)

DOCKER_BUILD := ./build.sh
Expand Down
4 changes: 2 additions & 2 deletions core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8
FROM openjdk:11-jre-slim

ENV WORKER=/flow.ci
ENV JAR=flow-ci-core.jar
Expand All @@ -11,4 +11,4 @@ COPY wait_for_it.sh $WORKER
RUN mkdir -p $HOME/.ssh
RUN echo "StrictHostKeyChecking=no" >> $HOME/.ssh/config

CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap $JVM_OPS -jar $JAR
CMD java $JVM_OPS -jar $JAR
78 changes: 60 additions & 18 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<parent>
<artifactId>flow-platform-x</artifactId>
<groupId>com.flowci</groupId>
<version>1.0-SNAPSHOT</version>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
Expand Down Expand Up @@ -80,9 +79,30 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

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

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

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -98,13 +118,43 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</dependency>

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

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

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
Expand All @@ -120,16 +170,6 @@
<artifactId>org.eclipse.jgit.http.server</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>

<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
Expand All @@ -141,12 +181,6 @@
<scope>test</scope>
</dependency>

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

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
Expand Down Expand Up @@ -185,6 +219,14 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/com/flowci/core/agent/domain/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.flowci.core.common.domain.Mongoable;
import com.flowci.domain.Common.OS;
import com.flowci.domain.SimpleKeyPair;
import com.flowci.domain.StringVars;
import com.flowci.domain.Vars;
import com.flowci.tree.Selector;
import com.google.common.base.Strings;
import lombok.Getter;
Expand Down Expand Up @@ -65,6 +67,23 @@ public static Status fromBytes(byte[] bytes) {
}
}

private abstract class Variables {

private final static String NAME = "AGENT_NAME";

private final static String IS_K8S_CLUSTER = "AGENT_IS_K8S_CLUSTER";

private final static String IS_DOCKER = "AGENT_IS_DOCKER";

private final static String OS = "AGENT_OS";

private final static String STATUS = "AGENT_STATUS";

private final static String JOB_ID = "AGENT_JOB_ID";

private final static String CONTAINER_ID = "AGENT_CONTAINER_ID";
}

@Indexed(name = "index_agent_name", unique = true)
private String name;

Expand Down Expand Up @@ -179,4 +198,15 @@ public boolean match(Selector selector) {
labels.retainAll(tags);
return !labels.isEmpty();
}

public Vars<String> toContext() {
Vars<String> context = new StringVars(8);
context.put(Variables.NAME, name);
context.put(Variables.IS_DOCKER, String.valueOf(isDocker));
context.put(Variables.IS_K8S_CLUSTER, String.valueOf(isK8sCluster));
context.put(Variables.STATUS, status.name());
context.put(Variables.JOB_ID, jobId);
context.put(Variables.CONTAINER_ID, containerId);
return context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.flowci.core.config.domain.ConfigAction;
import com.flowci.core.flow.domain.FlowAction;
import com.flowci.core.job.domain.JobAction;
import com.flowci.core.trigger.domain.TriggerOperations;
import com.flowci.core.secret.domain.SecretAction;
import com.flowci.core.user.domain.User;
import com.flowci.core.user.domain.UserAction;
Expand All @@ -47,6 +48,7 @@ public PermissionMap actionMap() {
permissionMap.add(User.Role.Admin, AgentHostAction.ALL);
permissionMap.add(User.Role.Admin, UserAction.ALL);
permissionMap.add(User.Role.Admin, ConfigAction.ALL);
permissionMap.add(User.Role.Admin, TriggerOperations.ALL);
permissionMap.add(User.Role.Admin, Settings.Action.ALL);

// developer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,30 @@
"com.flowci.core.secret",
"com.flowci.core.plugin",
"com.flowci.core.config",
"com.flowci.core.trigger",
"com.flowci.core.api",
"com.flowci.core.common.controller"
})
public class ExceptionAdviser {

@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseMessage<Object> inputArgumentException(MethodArgumentNotValidException e) {
String msg = e.getMessage();

var fieldError = e.getBindingResult().getFieldError();
if (fieldError != null && fieldError.getDefaultMessage() != null) {
msg = fieldError.getDefaultMessage();
}

return new ResponseMessage<>(ErrorCode.INVALID_ARGUMENT, msg, null);
}

@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler({
MethodArgumentNotValidException.class,
MissingServletRequestParameterException.class
})
public ResponseMessage<Object> inputArgumentException(Exception e) {
@ExceptionHandler(MissingServletRequestParameterException.class)
public ResponseMessage<Object> inputArgumentException(MissingServletRequestParameterException e) {
return new ResponseMessage<>(ErrorCode.INVALID_ARGUMENT, e.getMessage(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"com.flowci.core.secret",
"com.flowci.core.plugin",
"com.flowci.core.config",
"com.flowci.core.trigger",
"com.flowci.core.api",
"com.flowci.core.common.controller"
})
Expand Down
33 changes: 25 additions & 8 deletions core/src/main/java/com/flowci/core/common/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.flowci.core.common.helper.ThreadHelper;
import com.flowci.util.FileHelper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationEvent;
Expand All @@ -38,8 +37,10 @@

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.concurrent.Executor;

/**
Expand All @@ -51,17 +52,24 @@
@EnableCaching
public class AppConfig {

@Autowired
private MultipartProperties multipartProperties;
private final MultipartProperties multipartProperties;

@Autowired
private AppProperties appProperties;
private final AppProperties appProperties;

private final Path tmpDir;

public AppConfig(MultipartProperties multipartProperties, AppProperties appProperties) {
this.multipartProperties = multipartProperties;
this.appProperties = appProperties;

this.tmpDir = Paths.get(appProperties.getWorkspace().toString(), "tmp");
}

@PostConstruct
private void initDirs() throws IOException {
Path ws = appProperties.getWorkspace();
FileHelper.createDirectory(ws);
FileHelper.createDirectory(tmpDir());
FileHelper.createDirectory(tmpDir);
FileHelper.createDirectory(appProperties.getFlowDir());
FileHelper.createDirectory(appProperties.getSiteDir());
}
Expand All @@ -74,12 +82,12 @@ public void initUploadDir() throws IOException {

@Bean("tmpDir")
public Path tmpDir() {
return Paths.get(appProperties.getWorkspace().toString(), "tmp");
return tmpDir;
}

@Bean("objectMapper")
public ObjectMapper objectMapper() {
return JacksonHelper.create();
return JacksonHelper.Default;
}

@Bean("appTaskExecutor")
Expand Down Expand Up @@ -114,4 +122,13 @@ public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
multicaster.setTaskExecutor(appTaskExecutor);
return multicaster;
}

@Bean("httpClient")
public HttpClient httpClient() {
return HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(Duration.ofSeconds(10))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.flowci.core.user.config;
package com.flowci.core.common.config;

import com.flowci.core.common.helper.CacheHelper;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserConfig {
public class CacheConfig {

@Bean("userCacheManager")
public CacheManager userCacheManager() {
@Bean("defaultCacheManager")
public CacheManager defaultCacheManager() {
return CacheHelper.createCacheManager(1800, 100);
}
}

0 comments on commit ebd5f5c

Please sign in to comment.