From 94f5fa37ac33d400f0ab1e7ba254649ffea48565 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 22 Feb 2022 09:16:45 +0000 Subject: [PATCH] Add route to display version information. (#195) * Add version information route. * Use build action for tests. * Add version test to script. * Add testing directory to dockerignore. * Don't unnecessarily set permission for gradle wrapper script. --- .dockerignore | 1 + .github/workflows/ci.yml | 5 ++--- .github/workflows/docker-build-test.yml | 10 +++++++--- .github/workflows/docker-build.yml | 10 ++++++---- .gitignore | 3 +++ Dockerfile | 2 ++ Dockerfile.openj9 | 2 ++ src/main/java/me/kavin/piped/ServerLauncher.java | 1 + src/main/java/me/kavin/piped/consts/Constants.java | 7 +++++++ testing/api-test.sh | 3 +++ 10 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.dockerignore b/.dockerignore index 8db7dcd..4ac1703 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,4 @@ LICENSE *.md config.properties data/ +testing/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 840fa1a..99c4a34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [11, 17] + java: [ 11, 17 ] steps: - uses: actions/checkout@v2.4.0 @@ -22,6 +22,5 @@ jobs: distribution: temurin check-latest: true cache: "gradle" - - name: Run Build - run: chmod +x ./gradlew && ./gradlew build + run: ./gradlew build diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index 5c8fd1a..8b7ceb2 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -18,10 +18,14 @@ jobs: - testing/docker-compose.yugabytedb.yml steps: - uses: actions/checkout@v2.4.0 - with: - fetch-depth: 0 + - name: Create Version File + run: echo $(git log -1 --date=short --pretty=format:%cd)-$(git rev-parse --short HEAD) > VERSION - name: Build Locally - run: docker build . -t 1337kavin/piped:latest + uses: docker/build-push-action@v2.9.0 + with: + context: . + load: true + tags: 1337kavin/piped:latest - name: Start Docker-Compose services run: docker-compose -f ${{ matrix.docker-compose-file }} up -d && sleep 5 - name: Run tests diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 7bbbb55..006d9e0 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -12,8 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.4.0 - with: - fetch-depth: 0 + - name: Create Version File + run: echo $(git log -1 --date=short --pretty=format:%cd)-$(git rev-parse --short HEAD) > VERSION - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 with: @@ -40,8 +40,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.4.0 - with: - fetch-depth: 0 + - name: Create Version File + run: echo $(git log -1 --date=short --pretty=format:%cd)-$(git rev-parse --short HEAD) > VERSION - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 with: @@ -64,3 +64,5 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: 1337kavin/piped:latest,1337kavin/piped:openj9 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index ca75516..114e0ae 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ bin/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Version File +VERSION \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 464e35d..805278c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,8 @@ WORKDIR /app/ COPY --from=build /app/build/libs/piped-1.0-all.jar /app/piped.jar +COPY VERSION . + EXPOSE 8080 CMD java -jar /app/piped.jar diff --git a/Dockerfile.openj9 b/Dockerfile.openj9 index 1dd9048..752f66c 100644 --- a/Dockerfile.openj9 +++ b/Dockerfile.openj9 @@ -12,6 +12,8 @@ WORKDIR /app/ COPY --from=build /app/build/libs/piped-1.0-all.jar /app/piped.jar +COPY VERSION . + EXPOSE 8080 CMD java -server -XX:+UnlockExperimentalVMOptions -XX:+OptimizeStringConcat -XX:+UseStringDeduplication -XX:+UseCompressedOops -XX:+UseNUMA -XX:+UseParallelGC -XX:-UseBiasedLocking -Xshareclasses:allowClasspaths -jar /app/piped.jar diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index cf060c9..f4dc647 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -45,6 +45,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { RoutingServlet router = RoutingServlet.create() .map(GET, "/healthcheck", request -> getRawResponse("OK".getBytes(UTF_8), "text/plain", "no-cache")) + .map(GET, "/version", AsyncServlet.ofBlocking(executor, request -> getRawResponse(Constants.VERSION.getBytes(UTF_8), "text/plain", "no-cache"))) .map(HttpMethod.OPTIONS, "/*", request -> HttpResponse.ofCode(200)) .map(GET, "/webhooks/pubsub", request -> HttpResponse.ok200().withPlainText(Objects.requireNonNull(request.getQueryParameter("hub.challenge")))) .map(POST, "/webhooks/pubsub", AsyncServlet.ofBlocking(executor, request -> { diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 963ccbb..90da1f1 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -5,11 +5,13 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.kavin.piped.utils.PageMixin; import okhttp3.OkHttpClient; import okhttp3.brotli.BrotliInterceptor; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; +import java.io.File; import java.io.FileReader; import java.net.InetSocketAddress; import java.net.ProxySelector; @@ -43,6 +45,8 @@ public class Constants { public static final int FEED_RETENTION; + public static final String VERSION; + public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class); public static final Object2ObjectOpenHashMap hibernateProperties = new Object2ObjectOpenHashMap<>(); @@ -89,6 +93,9 @@ public class Constants { } h2client = builder.build(); h2_no_redir_client = builder_noredir.build(); + VERSION = new File("VERSION").exists() ? + IOUtils.toString(new FileReader("VERSION")) : + "unknown"; } catch (Exception e) { throw new RuntimeException(e); } diff --git a/testing/api-test.sh b/testing/api-test.sh index d59ab2a..67b947f 100755 --- a/testing/api-test.sh +++ b/testing/api-test.sh @@ -3,6 +3,9 @@ CURLOPTS=(-i -s -S -o /dev/null -f -w "%{http_code}\tTime:\t%{time_starttransfer}\t%{url_effective}\n") HOST=127.0.0.1:8080 +# Version Test +curl ${CURLOPTS[@]} $HOST/version || exit 1 + # Trending Page curl ${CURLOPTS[@]} $HOST/trending?region=US || exit 1