Skip to content

Commit

Permalink
Merge pull request #48 from Gepardec/feature/44WorkFlow
Browse files Browse the repository at this point in the history
PR: Workflow for building, testing, pushing and scanning Image
  • Loading branch information
Jaroslav380 authored Feb 3, 2025
2 parents eba7a6d + ce4273f commit 0d52968
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 42 deletions.
78 changes: 76 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,85 @@
name: Release Containerimage

on:
push:
branches:
- dev
- feature/44WorkFlow

workflow_dispatch:

jobs:
build-test-push:
runs-on: ubuntu-latest

steps:
- name: Howdy
run: echo "Howdy from main"
- uses: actions/checkout@v3
name: checkout

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn clean install

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

- name: Create Image
run: |
docker build -t gamertrack-war .
- name: Run integrationTests
run: |
docker run -d --name gamertrack-test-container -p 8080:8080 gamertrack-war:latest
until curl -s http://localhost:8080/gepardec-gamertrack/api/v1/health | grep -q "running"; do
echo "Waiting for the Application..."
sleep 2
done
mvn verify -Prun-integrationtests
docker stop gamertrack-test-container
docker rm gamertrack-test-container
- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository }}
password: ${{ secrets.GITHUB_TOKEN }}


- name: Build Docker Image and Push to GHCR
run: |
docker tag gamertrack-war:latest ghcr.io/gepardec/gepardec-gamertrack:dev
docker push ghcr.io/gepardec/gepardec-gamertrack:dev
scan:
name: scanning
runs-on: ubuntu-latest
needs: build-test-push

steps:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.29.0
with:
image-ref: 'ghcr.io/gepardec/gepardec-gamertrack:dev'
format: 'sarif'
ignore-unfixed: true
scanners: 'vuln,secret,misconfig'
severity: 'CRITICAL,HIGH'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: 'code'
wait-for-processing: true
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ build/
.DS_Store

### WILDFLY PROVISIONED
/wildfly
/application.properties
/*.properties
/wildfly
17 changes: 17 additions & 0 deletions ChangeDataSource.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

/opt/jboss/wildfly/bin/standalone.sh &

echo "=> Waiting for WildFly to start"
until curl -s http://localhost:8080 > /dev/null; do
echo "Waiting for WildFly..."
sleep 5
done

echo "=> WildFly started. Now configuring datasource."

/opt/jboss/wildfly/bin/jboss-cli.sh --connect <<EOF
/subsystem=datasources/data-source=ExampleDS:write-attribute(name=connection-url, value="jdbc:h2:file:/opt/jboss/wildfly/gamertrackDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=\${wildfly.h2.compatibility.mode:REGULAR}")
exit
EOF

19 changes: 18 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
FROM quay.io/wildfly/wildfly:latest
FROM quay.io/wildfly/wildfly:latest-jdk21

ADD gamertrack-war/target/gepardec-gamertrack.war /opt/jboss/wildfly/standalone/deployments/

COPY ChangeDataSource.sh /opt/jboss/wildfly/ChangeDataSource.sh

USER root

RUN chmod +x /opt/jboss/wildfly/ChangeDataSource.sh
RUN chmod -R 777 /opt/jboss/

USER jboss

RUN /opt/jboss/wildfly/ChangeDataSource.sh

USER root
RUN chmod -R 777 /opt/jboss/wildfly
USER jboss


ENTRYPOINT ["/bin/bash", "-c", "/opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0"]
1 change: 1 addition & 0 deletions application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jboss.home=${basedir}${file.separator}..${file.separator}wildfly
4 changes: 2 additions & 2 deletions gamertrack-IntegrationTest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>gamertrack-IntegrationTest</artifactId>

<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET http://localhost:8080/gepardec-gamertrack/api/v1/users/
GET http://localhost:8080/gepardec-gamertrack/api/v1/users/
###

###
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.gepardec.rest.api;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import static com.gepardec.rest.api.HealthResource.BASE_HEALTH_PATH;


@Path(BASE_HEALTH_PATH)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface HealthResource {
public static final String BASE_HEALTH_PATH = "health";


@Operation(summary = "Get the App health status", description = "Returns App Health")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "App is running!"),
})
@GET
public Response healthCheck();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gepardec.rest.config;

import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerResponseContext;
import jakarta.ws.rs.container.ContainerResponseFilter;
import jakarta.ws.rs.ext.Provider;

import java.io.IOException;

@Provider
public class CorsFilter implements ContainerResponseFilter {

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

String origin = requestContext.getHeaders().getFirst("Origin");

if (origin != null && origin.matches("^(http|https)://gamertrack-frontend.apps.cloudscale-lpg-2.appuio.cloud")) {
responseContext.getHeaders().add("Access-Control-Allow-Origin", origin);
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "Content-Type");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.gepardec.rest.config;

import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

@Provider
public class RequestLoggingFilter implements ContainerRequestFilter {

private final Logger logger = LoggerFactory.getLogger(RequestLoggingFilter.class);


@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
StringBuilder sb = new StringBuilder();
sb
.append("\n\t\t%s".formatted(requestContext.getMethod()))
.append(" ")
.append(requestContext.getUriInfo().getPath());

AtomicReference<String> tmp = new AtomicReference<>("");


// PREPARE VERB AND PATH
if (!requestContext.getUriInfo().getQueryParameters().isEmpty()) {
requestContext.getUriInfo()
.getQueryParameters()
.forEach((key, value) ->
{
value.forEach(v -> tmp.set("&" + tmp + v));
tmp.set(tmp.get().replaceFirst("&", ""));
sb.append("?%s=%s".formatted(key, tmp.get()));
tmp.set("");
});
}
sb.append("\n");

// PREPARE HEADERS

requestContext
.getHeaders()
.forEach((k, v) ->
{
v.forEach(value -> tmp.set(tmp + value));
sb.append("\t\t%s:\t%s\n".formatted(k, tmp.get()));
tmp.set("");
});

logger.info("Request logged: {}", sb);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gepardec.rest.impl;

import com.gepardec.rest.api.HealthResource;
import jakarta.ws.rs.core.Response;

public class HealthResourceImpl implements HealthResource {

@Override
public Response healthCheck() {
return Response.ok("Application is running").build();
}
}
3 changes: 1 addition & 2 deletions gamertrack-db/src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<!--JTA -> container does everything EntityManager related, EM can only be accessed when a transaction is in progress-->
<persistence-unit name="gamertrack" transaction-type="JTA">
<properties>
<property name="jakarta.persistence.schema-generation.database.action"
value="drop-and-create"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
31 changes: 0 additions & 31 deletions gamertrack-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@
<build>
<finalName>gepardec-gamertrack</finalName>

<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>5.1.1.Final</version>
<configuration>
<feature-packs>
<feature-pack>
<!-- Latest released version -->
<location>wildfly@maven(org.jboss.universe:community-universe)</location>
</feature-pack>
<feature-pack>
<location>org.wildfly:wildfly-datasources-galleon-pack:8.0.1.Final</location>
</feature-pack>
</feature-packs>
<layers>
<layer>jaxrs-server</layer>
<layer>ejb</layer>
<layer>bean-validation</layer>
<layer>postgresql-default-datasource</layer>
</layers>
</configuration>
<executions>
<execution>
<goals>
<goal>image</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
Expand Down

0 comments on commit 0d52968

Please sign in to comment.