Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IHP-7] - Docker package #12

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/publish-resizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: publish resizer

on:
push:
branches: [ master ]

env:
IMAGE_NAME: image-hosting-processing-resizer

jobs:
publish-container:
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v3

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

#- name: run tests
# run: sbt test

#- name: run integration tests
# run: sbt it:test

- name: Assembly
run: sbt buildResizer

- name: Build image
run: docker build ./resizer --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Push image
run: |

IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# make version be equal to branch name (in case we want to have several branches to push container)
VERSION=$GITHUB_REF_NAME

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Image hosting processing

Support part of https://github.com/Baklanov-Soft/image-hosting-storage

## Resizer

Resizer service for generating the previews

Environment variables:

```
KAFKA_BOOTSTRAP_SERVERS - kafka cluster url (Default: localhost:9092)
CONSUMER_GROUP_ID - consumer id, multiple instances with same id will allow horizontal scaling (depends on topic paritions) (Default: resizer-local-test)
NEW_IMAGES_TOPIC - topic for notifications about new images (Default: "new-images.v1")
```
1 change: 1 addition & 0 deletions alias.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addCommandAlias("buildResizer", "project resizer;assembly;")
21 changes: 20 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ import Dependencies._

ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / organization := "com.github.baklanov-soft"
ThisBuild / organization := "com.github.baklanovsoft"

ThisBuild / scalacOptions += "-Ymacro-annotations"
ThisBuild / libraryDependencies ++= Dependencies.plugins

val assemblyStrategy = assembly / assemblyMergeStrategy := {
// to not apply local development override configurations
case PathList("params.conf") =>
MergeStrategy.discard

// openapi docs generation
case PathList("META-INF", "maven", "org.webjars", "swagger-ui", "pom.properties") =>
MergeStrategy.singleOrError

// deduplicate error because of logback, this will fix
case x =>
MergeStrategy.first
}

lazy val domain = (project in file("domain"))
.settings(
name := "image-hosting-processing-domain"
Expand Down Expand Up @@ -38,6 +52,11 @@ lazy val resizer = (project in file("resizer"))
.settings(
name := "image-hosting-processing-resizer"
)
.settings(
assemblyStrategy,
// for no main manifest attribute error
assembly / mainClass := Some("com.github.baklanovsoft.imagehosting.resizer.Main")
)
.settings(
libraryDependencies ++= Seq(
pureconfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class KafkaConsumer[F[_]: Async, K, V](bootstrapServers: String, consumerGroup:
ConsumerSettings[F, K, V]
.withAutoOffsetReset(AutoOffsetReset.Earliest)
.withEnableAutoCommit(false)
.withAllowAutoCreateTopics(false)
.withBootstrapServers(bootstrapServers)
.withGroupId(consumerGroup)

Expand Down
30 changes: 29 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
version: "3"

services:

resizer:
build: ./resizer
container_name: resizer
depends_on:
- kafka-init
environment:
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
- CONSUMER_GROUP_ID=resizer-local-test

zookeeper:
image: docker.io/bitnami/zookeeper:3.8
container_name: zoo
Expand All @@ -19,11 +29,29 @@ services:
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,UI:PLAINTEXT
KAFKA_LISTENERS: PLAINTEXT://kafka:9092,UI://kafka:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,UI://kafka:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,UI://kafka:9093
KAFKA_INTER_BROKER_LISTENER_NAME: UI
depends_on:
- zookeeper

kafka-init:
image: wurstmeister/kafka
container_name: kafka-init
depends_on:
- kafka
entrypoint: [ '/bin/sh', '-c' ]
command: |
"
# blocks until kafka is reachable
kafka-topics --bootstrap-server kafka:9092 --list

echo -e 'Creating kafka topics'
kafka-topics.sh --bootstrap-server "kafka:9092" --create --replication-factor 1 --partitions 2 --topic "new-images.v1"

echo -e 'Successfully created the following topics:'
kafka-topics.sh --bootstrap-server kafka:9092 --list
"

kafka-ui:
image: provectuslabs/kafka-ui
container_name: kafka-ui
Expand Down
8 changes: 8 additions & 0 deletions resizer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM eclipse-temurin:17.0.6_10-jre-jammy

WORKDIR /opt/app

#COPY ./application.conf ./app/target/scala-2.13/image-hosting-processing-resizer-assembly-0.1.0-SNAPSHOT.jar ./
COPY ./target/scala-2.13/image-hosting-processing-resizer-assembly-0.1.0-SNAPSHOT.jar ./

ENTRYPOINT ["java", "-cp", "image-hosting-processing-resizer-assembly-0.1.0-SNAPSHOT.jar", "com.github.baklanovsoft.imagehosting.resizer.Main"]
2 changes: 1 addition & 1 deletion resizer/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include "params.conf"
kafka-bootstrap-servers = "localhost:9092"
kafka-bootstrap-servers = ${?KAFKA_BOOTSTRAP_SERVERS}

consumer-group-id = "image-resizer-local"
consumer-group-id = "resizer-local-test"
consumer-group-id = ${?CONSUMER_GROUP_ID}

new-images-topic = "new-images.v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.baklanovsoft.imagehosting
package com.github.baklanovsoft.imagehosting.resizer

import pureconfig.ConfigReader
import pureconfig.generic.semiauto._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.baklanovsoft.imagehosting
package com.github.baklanovsoft.imagehosting.resizer

import cats.effect.{ExitCode, IO, IOApp}
import com.github.baklanovsoft.imagehosting.NewImage
import com.github.baklanovsoft.imagehosting.imagehosting.kafka.{KafkaConsumer, KafkaJsonDeserializer}
import fs2.kafka.commitBatchWithin
import org.typelevel.log4cats.LoggerFactory
import org.typelevel.log4cats.slf4j.Slf4jFactory
import pureconfig.ConfigSource
import pureconfig.module.catseffect.syntax.CatsEffectConfigSource

import scala.concurrent.duration._

object Main extends IOApp with KafkaJsonDeserializer {
Expand Down
Loading