diff --git a/.dockerignore b/.dockerignore index 4361d2f..0922a42 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,5 @@ !build/*-runner !build/*-runner.jar !build/lib/* -!build/quarkus-app/* \ No newline at end of file +!build/quarkus-app/* +!*.pem diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7fa66f9..12b9f91 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,11 @@ jobs: timeout-minutes: 15 permissions: contents: write + env: + QUARKUS_JACOCO_REPORT_LOCATION: 'coverage' + QUARKUS_JACOCO_FOOTER: 'httpbucket' + QUARKUS_JACOCO_TITLE: 'httpbucket' + QUARKUS_JACOCO_EXCLUDES: '**/SimpleHealthCheck.class' steps: - name: Code Checkout uses: actions/checkout@v3 @@ -31,18 +36,30 @@ jobs: echo "REPO=$GITHUB_REPOSITORY" >> $GITHUB_ENV echo "OWNER=$GITHUB_REPOSITORY_OWNER" >> $GITHUB_ENV - # - name: Check version is used. - # run: | - # URL=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest - # LATEST=$(curl --silent "$URL" | jq -r .name) - # if [ "$LATEST" == "$VERSION" ]; then - # echo "Version is used." - # exit 1 - # fi + - name: Check version is used. + run: | + URL=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest + LATEST=$(curl --silent "$URL" | jq -r .name) + if [ "$LATEST" == "$VERSION" ]; then + echo "Version is used." + exit 1 + fi - name: Build run: ./gradlew build --no-daemon -Dquarkus.package.type=native -Dquarkus.native.container-build=true + - name: Generating self-signed certificate + run: | + openssl req \ + -newkey rsa:2048 \ + -new \ + -nodes \ + -x509 \ + -days 3650 \ + -keyout key.pem \ + -out cert.pem \ + -subj "/C=US/ST=SC/L=Hometown/O=IT/emailAddress=root@localhost/CN=localhost" + - name: Login to DockerHub uses: docker/login-action@v2 with: diff --git a/.gitignore b/.gitignore index 216783d..d276e03 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ nb-configuration.xml # Plugin directory /.quarkus/cli/plugins/ + +# Certificates +*.pem diff --git a/README.md b/README.md index 8f0b898..833d23c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,64 @@ será apreciada. Obrigado pelo seu apoio contínuo! [![PIX](helpers/pix.png)](https://nubank.com.br/pagar/2bt2q/RBr4Szfuwr) +## Environment variables + +| Variable | Description | Default | +|---------------------|-------------|----------| +| HTTPBUCKET_SSL_CERT | _*TODO*_ | cert.pem | +| HTTPBUCKET_SSL_KEY | _*TODO*_ | key.pem | + ## How to use + +```shell +docker run -d --rm --name httpbucket -p 8080:8080 -p 8443:8443 testainers/httpbucket:latest +``` + +## How to test + ```shell -docker run -d --rm --name httpbucket -p 8080:8080 testainers/httpbucket:latest +curl http://localhost:8080/methods ``` + +```shell +curl -k https://localhost:8443/methods +``` + +---- + +## Build + +```shell +docker build . -f src/main/docker/Dockerfile.native-micro --no-cache -t httpbucket +``` + +## Run + +```shell +docker run --rm --name httpbucket -p 8080:8080 -p 8443:8443 -d httpbucket +``` + +---- + +## Self-signed certificate + +```shell +openssl req \ + -newkey rsa:2048 \ + -new \ + -nodes \ + -x509 \ + -days 3650 \ + -keyout key.pem \ + -out cert.pem \ + -subj "/C=US/ST=SC/L=Hometown/O=IT/emailAddress=root@localhost/CN=localhost" +``` + +---- + +## Extra endpoints + +- /openapi +- /swagger-ui +- /health +- /metrics diff --git a/build.gradle b/build.gradle index 97197f4..42f7eb0 100644 --- a/build.gradle +++ b/build.gradle @@ -16,13 +16,14 @@ dependencies { implementation 'io.quarkus:quarkus-resteasy' implementation 'io.quarkus:quarkus-resteasy-jackson' implementation 'io.quarkus:quarkus-arc' + implementation 'io.smallrye.config:smallrye-config-source-file-system' testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' testImplementation 'io.quarkus:quarkus-jacoco' } group 'com.testainers' -version '0.0.1' +version '0.0.2' java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/coverage.sh b/coverage.sh new file mode 100755 index 0000000..cd2b14d --- /dev/null +++ b/coverage.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +export QUARKUS_JACOCO_REPORT_LOCATION='coverage' +export QUARKUS_JACOCO_FOOTER='httpbucket' +export QUARKUS_JACOCO_TITLE='httpbucket' +export QUARKUS_JACOCO_EXCLUDES='**/SimpleHealthCheck.class' + +./gradlew cleanTest test + +/bin/cp -rf helpers/coverage/* build/coverage/. + +/opt/google/chrome/google-chrome build/coverage/index.html diff --git a/src/main/docker/Dockerfile.native-micro b/src/main/docker/Dockerfile.native-micro index 2dfa288..b7fca3b 100644 --- a/src/main/docker/Dockerfile.native-micro +++ b/src/main/docker/Dockerfile.native-micro @@ -22,9 +22,14 @@ WORKDIR /work/ RUN chown 1001 /work \ && chmod "g+rwX" /work \ && chown 1001:root /work + COPY --chown=1001:root build/*-runner /work/application +COPY --chown=1001:root cert.pem /work/cert.pem +COPY --chown=1001:root key.pem /work/key.pem EXPOSE 8080 +EXPOSE 8443 + USER 1001 CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/src/main/java/com/testainers/ResponseBody.java b/src/main/java/com/testainers/ResponseBody.java index 0baf532..dfc581d 100644 --- a/src/main/java/com/testainers/ResponseBody.java +++ b/src/main/java/com/testainers/ResponseBody.java @@ -2,12 +2,10 @@ import io.quarkus.runtime.annotations.RegisterForReflection; import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.core.PathSegment; import jakarta.ws.rs.core.UriInfo; import org.jboss.resteasy.spi.HttpRequest; import java.net.URI; -import java.util.List; /** * @author Eduardo Folly @@ -21,7 +19,6 @@ public class ResponseBody { public String remoteHost; public MultivaluedMap headers; public MultivaluedMap pathParameters; - public List pathSegments; public MultivaluedMap queryParameters; public Object body; @@ -35,7 +32,6 @@ public ResponseBody(HttpRequest request, Object body) { UriInfo uriInfo = request.getUri(); this.uri = uriInfo.getAbsolutePath(); this.pathParameters = uriInfo.getPathParameters(); - this.pathSegments = uriInfo.getPathSegments(); this.queryParameters = uriInfo.getQueryParameters(); this.body = body; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2e349ed..6186d04 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,13 @@ # quarkus.analytics.disabled=true quarkus.banner.enabled=false +quarkus.application.name=httpbucket +quarkus.ssl.native=true +# +%prod.smallrye.config.source.file.locations=/run/secrets +# +quarkus.http.ssl.certificate.files=${httpbucket.ssl.cert:cert.pem} +quarkus.http.ssl.certificate.key-files=${httpbucket.ssl.key:key.pem} # quarkus.http.cors=true quarkus.http.cors.origins=* @@ -20,6 +27,3 @@ quarkus.swagger-ui.path=/swagger-ui quarkus.swagger-ui.theme=flattop quarkus.swagger-ui.title=httpbucket quarkus.swagger-ui.footer=© 2023 - Testainers -# -quarkus.jacoco.report-location=coverage -quarkus.jacoco.excludes=**/SimpleHealthCheck.class