Initialize Spring Boot docker branch with Drone pipeline
This commit is contained in:
32
.drone.yml
Normal file
32
.drone.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: backend-docker
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- docker
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build-image
|
||||||
|
image: docker:27-cli
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- docker build -t cdchen-backend:docker .
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: docker:27-cli
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- docker rm -f cdchen-backend || true
|
||||||
|
- docker run -d --name cdchen-backend --restart unless-stopped -p 8089:8080 cdchen-backend:docker
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
target
|
||||||
|
.DS_Store
|
||||||
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip
|
||||||
|
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
|
||||||
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FROM maven:3.9.8-eclipse-temurin-17 AS build
|
||||||
|
WORKDIR /workspace
|
||||||
|
COPY pom.xml .
|
||||||
|
COPY src ./src
|
||||||
|
RUN mvn -B clean package -DskipTests
|
||||||
|
|
||||||
|
FROM eclipse-temurin:17-jre-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /workspace/target/backend-0.0.1-SNAPSHOT.jar app.jar
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
|
||||||
15
mvnw
vendored
Executable file
15
mvnw
vendored
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BASE_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
|
WRAPPER_DIR="$BASE_DIR/.mvn/wrapper"
|
||||||
|
WRAPPER_JAR="$WRAPPER_DIR/maven-wrapper.jar"
|
||||||
|
PROPERTIES_FILE="$WRAPPER_DIR/maven-wrapper.properties"
|
||||||
|
|
||||||
|
if [ ! -f "$WRAPPER_JAR" ]; then
|
||||||
|
URL=$(sed -n 's/^wrapperUrl=//p' "$PROPERTIES_FILE")
|
||||||
|
mkdir -p "$WRAPPER_DIR"
|
||||||
|
curl -fsSL "$URL" -o "$WRAPPER_JAR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec java -classpath "$WRAPPER_JAR" org.apache.maven.wrapper.MavenWrapperMain "$@"
|
||||||
7
mvnw.cmd
vendored
Normal file
7
mvnw.cmd
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
SETLOCAL
|
||||||
|
set WRAPPER_JAR=%~dp0\.mvn\wrapper\maven-wrapper.jar
|
||||||
|
if not exist "%WRAPPER_JAR%" (
|
||||||
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar','%WRAPPER_JAR%')"
|
||||||
|
)
|
||||||
|
java -classpath "%WRAPPER_JAR%" org.apache.maven.wrapper.MavenWrapperMain %*
|
||||||
45
pom.xml
Normal file
45
pom.xml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
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>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
<relativePath/>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>cloud.cdchen</groupId>
|
||||||
|
<artifactId>backend</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>backend</name>
|
||||||
|
<description>Minimal Spring Boot service for Docker deployment</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
22
src/main/java/cloud/cdchen/backend/BackendApplication.java
Normal file
22
src/main/java/cloud/cdchen/backend/BackendApplication.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package cloud.cdchen.backend;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class BackendApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(BackendApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
static class HealthController {
|
||||||
|
@GetMapping("/")
|
||||||
|
public String index() {
|
||||||
|
return "backend docker branch deployed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/main/resources/application.yml
Normal file
6
src/main/resources/application.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: backend
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package cloud.cdchen.backend;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class BackendApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user