Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee committed Jun 2, 2024
2 parents eac6a00 + 0bfd5d1 commit 359d9cb
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 64 deletions.
52 changes: 37 additions & 15 deletions .github/workflows/docker-alpha.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
name: Update Docker alpha tag

on:
pull_request:
branches: [ "main" ]
push:
branches: ["actions-merge-preview/**"]

jobs:
env:
APP_NAME: watchlistarr
DOCKER_FILE: docker/Dockerfile
DOCKER_PLATFORMS: "linux/arm64/v8,linux/amd64"

build:

jobs:
build:
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v3
- name: Set up environment
run: echo "DOCKER_TAG=$(date +%s)" >> $GITHUB_ENV

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build the Docker image
run: docker build . --file docker/Dockerfile --tag nylonee/watchlistarr:${DOCKER_TAG} --label=VERSION=${DOCKER_TAG}
- name: Push Docker image
run: |
docker tag nylonee/watchlistarr:${DOCKER_TAG} nylonee/watchlistarr:alpha
docker push nylonee/watchlistarr:${DOCKER_TAG}
docker push nylonee/watchlistarr:alpha

- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}
tags: |
type=sha
alpha
- name: Docker Setup QEMU
uses: docker/[email protected]

- name: Docker Setup Buildx
uses: docker/[email protected]
with:
buildkitd-flags: --debug

- name: Build and push Docker images
uses: docker/[email protected]
with:
context: .
file: ${{ env.DOCKER_FILE }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
47 changes: 34 additions & 13 deletions .github/workflows/docker-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,47 @@ on:
push:
branches: [ "main" ]

jobs:
env:
APP_NAME: watchlistarr
DOCKER_FILE: docker/Dockerfile
DOCKER_PLATFORMS: "linux/arm64/v8,linux/amd64"

jobs:
build:

runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v3
- name: Set up environment
run: echo "DOCKER_TAG=$(date +%s)" >> $GITHUB_ENV

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build the Docker image
run: docker build . --file docker/Dockerfile --tag nylonee/watchlistarr:${DOCKER_TAG} --label=VERSION=${DOCKER_TAG}
- name: Push Docker image
run: |
docker tag nylonee/watchlistarr:${DOCKER_TAG} nylonee/watchlistarr:beta
docker push nylonee/watchlistarr:${DOCKER_TAG}
docker push nylonee/watchlistarr:beta

- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}
tags: |
type=sha
beta
- name: Docker Setup QEMU
uses: docker/[email protected]

- name: Docker Setup Buildx
uses: docker/[email protected]
with:
buildkitd-flags: --debug

- name: Build and push Docker images
uses: docker/[email protected]
with:
context: .
file: ${{ env.DOCKER_FILE }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
18 changes: 18 additions & 0 deletions .github/workflows/merge-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# .github/workflows/merge-preview.yml
name: "Merge preview"

on:
issue_comment:
types: [created]

jobs:
preview:
runs-on: ubuntu-latest
steps:
# https://github.com/orgs/community/discussions/25702
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT_TOKEN }}
- uses: nwtgck/actions-merge-preview@develop
with:
github-token: ${{ secrets.PAT_TOKEN }}
51 changes: 38 additions & 13 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,50 @@ on:
release:
types: [published]

jobs:
env:
APP_NAME: watchlistarr
DOCKER_FILE: docker/Dockerfile
DOCKER_PLATFORMS: "linux/arm64/v8,linux/amd64"

build:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up environment
run: echo "DOCKER_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
- uses: actions/checkout@v3


- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build the Docker image
run: docker build . --file docker/Dockerfile --tag nylonee/watchlistarr:${DOCKER_TAG} --label=VERSION=${DOCKER_TAG}
- name: Push Docker image
run: |
docker tag nylonee/watchlistarr:${DOCKER_TAG} nylonee/watchlistarr:latest
docker push nylonee/watchlistarr:${DOCKER_TAG}
docker push nylonee/watchlistarr:latest

- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.APP_NAME }}
tags: |
type=sha
type=semver,pattern={{version}}
latest
- name: Docker Setup QEMU
uses: docker/[email protected]

- name: Docker Setup Buildx
uses: docker/[email protected]
with:
buildkitd-flags: --debug

- name: Build and push Docker images
uses: docker/[email protected]
with:
context: .
file: ${{ env.DOCKER_FILE }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
46 changes: 24 additions & 22 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ val circeVersion = "0.14.6"
val fs2Version = "3.7.0"
val http4sVersion = "0.23.23"
val logbackVersion = "1.4.11"
val scaffeineVersion = "5.2.1"
val scalamockVersion = "5.2.0"
val scalatestVersion = "3.2.17"
val shapelessVersion = "2.3.10"
Expand All @@ -23,28 +24,29 @@ val snakeYamlVersion = "2.2"
val vaultVersion = "3.5.0"

libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % scalaVersion.value % "provided",
"ch.qos.logback" % "logback-classic" % logbackVersion % Runtime,
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.http4s" %% "http4s-ember-client" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"org.http4s" %% "http4s-client" % http4sVersion,
"org.http4s" %% "http4s-core" % http4sVersion,
"co.fs2" %% "fs2-core" % fs2Version,
"co.fs2" %% "fs2-io" % fs2Version,
"com.chuusai" %% "shapeless" % shapelessVersion,
"io.circe" %% "circe-core" % circeVersion,
"org.typelevel" %% "case-insensitive" % caseInsensitiveVersion,
"org.typelevel" %% "cats-core" % catsCoreVersion,
"org.typelevel" %% "cats-effect" % catsEffectVersion,
"org.typelevel" %% "cats-effect-kernel" % catsEffectKernelVersion,
"org.typelevel" %% "vault" % vaultVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-generic-extras" % circeGenericExtrasVersion,
"org.yaml" % "snakeyaml" % snakeYamlVersion,
"io.circe" %% "circe-parser" % circeVersion % Test,
"org.scalamock" %% "scalamock" % scalamockVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test
"org.scala-lang" % "scala-library" % scalaVersion.value % "provided",
"ch.qos.logback" % "logback-classic" % logbackVersion % Runtime,
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.http4s" %% "http4s-ember-client" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"org.http4s" %% "http4s-client" % http4sVersion,
"org.http4s" %% "http4s-core" % http4sVersion,
"co.fs2" %% "fs2-core" % fs2Version,
"co.fs2" %% "fs2-io" % fs2Version,
"com.chuusai" %% "shapeless" % shapelessVersion,
"io.circe" %% "circe-core" % circeVersion,
"org.typelevel" %% "case-insensitive" % caseInsensitiveVersion,
"org.typelevel" %% "cats-core" % catsCoreVersion,
"org.typelevel" %% "cats-effect" % catsEffectVersion,
"org.typelevel" %% "cats-effect-kernel" % catsEffectKernelVersion,
"org.typelevel" %% "vault" % vaultVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-generic-extras" % circeGenericExtrasVersion,
"org.yaml" % "snakeyaml" % snakeYamlVersion,
"com.github.blemale" %% "scaffeine" % scaffeineVersion % "compile",
"io.circe" %% "circe-parser" % circeVersion % Test,
"org.scalamock" %% "scalamock" % scalamockVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test
)

enablePlugins(JavaAppPackaging)
Expand Down
24 changes: 23 additions & 1 deletion src/main/scala/http/HttpClient.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
package http

import cats.effect.IO
import cats.effect.unsafe.implicits.global
import io.circe.Json
import org.http4s.circe._
import org.http4s.client.middleware.FollowRedirect
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.{Header, Method, Request, Uri}
import org.typelevel.ci.CIString
import com.github.blemale.scaffeine.{AsyncLoadingCache, Scaffeine}

import scala.concurrent.duration._

class HttpClient {

val client = EmberClientBuilder
private val client = EmberClientBuilder
.default[IO]
.build
.map(FollowRedirect(5))

private val cacheTtl = 5.seconds

private val cache: AsyncLoadingCache[(Method, Uri, Option[String], Option[Json]), Either[Throwable, Json]] =
Scaffeine()
.recordStats()
.expireAfterWrite(cacheTtl)
.maximumSize(1000)
.buildAsyncFuture { case (method, url, apiKey, payload) =>
makeHttpRequest(method, url, apiKey, payload).unsafeToFuture()
}

def httpRequest(
method: Method,
url: Uri,
apiKey: Option[String] = None,
payload: Option[Json] = None
): IO[Either[Throwable, Json]] = IO.fromFuture(IO(cache.get(method, url, apiKey, payload)))

private def makeHttpRequest(
method: Method,
url: Uri,
apiKey: Option[String] = None,
payload: Option[Json] = None
): IO[Either[Throwable, Json]] = {
val host = s"${url.host.getOrElse(Uri.Host.unsafeFromString("127.0.0.1")).value}"

Expand Down

0 comments on commit 359d9cb

Please sign in to comment.