-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Gepardec/feature/44WorkFlow
PR: Workflow for building, testing, pushing and scanning Image
- Loading branch information
Showing
13 changed files
with
237 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,4 @@ build/ | |
.DS_Store | ||
|
||
### WILDFLY PROVISIONED | ||
/wildfly | ||
/application.properties | ||
/*.properties | ||
/wildfly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jboss.home=${basedir}${file.separator}..${file.separator}wildfly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tegrationTest/src/test/java/com/gepardec/rest/impl/request/UserRestControllerRequest.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
gamertrack-application/src/main/java/com/gepardec/rest/api/HealthResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
gamertrack-application/src/main/java/com/gepardec/rest/config/CorsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
gamertrack-application/src/main/java/com/gepardec/rest/config/RequestLoggingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
gamertrack-application/src/main/java/com/gepardec/rest/impl/HealthResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters