Skip to content

Commit

Permalink
Merge pull request #5 from testainers/dev
Browse files Browse the repository at this point in the history
Version 0.0.2.
  • Loading branch information
edufolly authored Jul 8, 2023
2 parents 3139e81 + 13fdc35 commit 3f82efd
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
!build/*-runner
!build/*-runner.jar
!build/lib/*
!build/quarkus-app/*
!build/quarkus-app/*
!*.pem
33 changes: 25 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ nb-configuration.xml

# Plugin directory
/.quarkus/cli/plugins/

# Certificates
*.pem
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions src/main/docker/Dockerfile.native-micro
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 0 additions & 4 deletions src/main/java/com/testainers/ResponseBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +19,6 @@ public class ResponseBody {
public String remoteHost;
public MultivaluedMap<String, String> headers;
public MultivaluedMap<String, String> pathParameters;
public List<PathSegment> pathSegments;
public MultivaluedMap<String, String> queryParameters;

public Object body;
Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=*
Expand All @@ -20,6 +27,3 @@ quarkus.swagger-ui.path=/swagger-ui
quarkus.swagger-ui.theme=flattop
quarkus.swagger-ui.title=httpbucket
quarkus.swagger-ui.footer=&#169; 2023 - Testainers
#
quarkus.jacoco.report-location=coverage
quarkus.jacoco.excludes=**/SimpleHealthCheck.class

0 comments on commit 3f82efd

Please sign in to comment.