diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..78e6411 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Deploy App + +on: + push: + branches: ["master"] + paths-ignore: + - .gitignore + - README.md + - LICENSE + - docker-compose.yml + +jobs: + docker: + strategy: + matrix: + arch: ["ubuntu-latest"] + git-version: ["2.44.0"] + java-version: ["17"] + maven-version: ["3.8.5"] + runs-on: ${{ matrix.arch }} + + # Steps to run + steps: + # Checkout the repo + - name: Checkout + uses: actions/checkout@v4 + + # Setup Java and Maven + - name: Set up JDK and Maven + uses: s4u/setup-maven-action@v1.12.0 + with: + java-version: ${{ matrix.java-version }} + distribution: "zulu" + maven-version: ${{ matrix.maven-version }} + + # Run JUnit Tests + - name: Run Tests + run: mvn --batch-mode test -q + + # Re-checkout to reset the FS before deploying to Dokku + - name: Checkout - Reset FS + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Deploy to Dokku + - name: Push to dokku + uses: dokku/github-action@master + with: + git_remote_url: "ssh://dokku@10.0.50.137:22/minecraft-helper" + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..985229a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM maven:3.9.6-eclipse-temurin-17-alpine + +# Set the working directory +WORKDIR /home/container + +# Copy the current directory contents into the container at /home/container +COPY . . + +# Build the jar +RUN mvn package -q -Dmaven.test.skip -DskipTests -T2C + +# Make port 80 available to the world outside this container +EXPOSE 80 +ENV PORT=80 + +# Run the jar file +CMD java -jar target/Paste-Backend.jar -Djava.awt.headless=true \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f5f41e..a46c7f2 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,25 @@ 3.14.0 compile + + com.google.code.gson + gson + 2.10.1 + compile + + + + + org.springframework.boot + spring-boot-starter-test + test + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo.spring3x + 4.12.6 + test + \ No newline at end of file diff --git a/src/main/java/cc/fascinated/Main.java b/src/main/java/cc/fascinated/Main.java index e364fbe..191db4a 100644 --- a/src/main/java/cc/fascinated/Main.java +++ b/src/main/java/cc/fascinated/Main.java @@ -1,5 +1,7 @@ package cc.fascinated; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import org.springframework.boot.SpringApplication; @@ -13,6 +15,10 @@ import java.util.Objects; @Log4j2(topic = "Main") @SpringBootApplication public class Main { + public static final Gson GSON = new GsonBuilder() + .setDateFormat("MM-dd-yyyy HH:mm:ss") + .create(); + @SneakyThrows public static void main(String[] args) { File config = new File("application.yml"); diff --git a/src/main/java/cc/fascinated/log/TransactionLogger.java b/src/main/java/cc/fascinated/log/TransactionLogger.java index 39f9141..35765b2 100644 --- a/src/main/java/cc/fascinated/log/TransactionLogger.java +++ b/src/main/java/cc/fascinated/log/TransactionLogger.java @@ -4,7 +4,6 @@ import cc.fascinated.common.IPUtils; import jakarta.servlet.http.HttpServletRequest; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 14f00fa..70c2492 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,4 +20,11 @@ spring: # Paste Configuration paste: # The length of the ID for the paste - id-length: 6 \ No newline at end of file + id-length: 12 + +# Set the embedded MongoDB version +de: + flapdoodle: + mongodb: + embedded: + version: 7.0.8 \ No newline at end of file diff --git a/src/test/java/cc/fascinated/PasteControllerTests.java b/src/test/java/cc/fascinated/PasteControllerTests.java new file mode 100644 index 0000000..a65a1eb --- /dev/null +++ b/src/test/java/cc/fascinated/PasteControllerTests.java @@ -0,0 +1,29 @@ +package cc.fascinated; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@AutoConfigureMockMvc +class MojangControllerTests { + + @Autowired + private MockMvc mockMvc; + + @Test + public void ensureUploadSuccess() throws Exception { + ResultActions result = mockMvc.perform(post("/upload") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content("joe")) + .andExpect(status().isOk()); + } +}