Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vdsirotkin committed Aug 25, 2024
1 parent 0c0e971 commit 736a74c
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM azul/zulu-openjdk-alpine:11.0.20.1-11.66.19-arm64 AS base
RUN apk update && apk add maven
COPY <<EOF /settings/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>./.m2</localRepository>
</settings>
EOF

FROM base AS deps
WORKDIR /deps
COPY pom.xml /deps/
COPY backend/pom.xml /deps/backend/pom.xml
COPY webp-io/pom.xml /deps/webp-io/pom.xml

RUN mvn dependency:go-offline -s /settings/settings.xml

FROM base AS build
WORKDIR /sources
COPY . /sources/
COPY --from=deps /deps/.m2 /sources/.m2

RUN mvn clean package -Dmaven.test.skip=true -s /settings/settings.xml

FROM azul/zulu-openjdk-alpine:11.0.20.1-11.66.19-arm64

RUN apk update \
&& apk add ffmpeg python3 py3-pip libwebp-tools optipng \
&& pip3 install 'lottie==0.6.4' --break-system-packages

# Create the application directory
RUN mkdir /app

COPY --from=build /sources/backend/target/service.jar /app

WORKDIR /app

CMD [ "java", "-jar", "/app/service.jar" ]
7 changes: 6 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,16 @@
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<finalName>service</finalName>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ import org.springframework.scheduling.annotation.EnableScheduling
@EnableScheduling
class MyStickersBotApplication

private fun ensureExternalTools() {
val runtime = Runtime.getRuntime()
runtime.exec("ffmpeg -version").also { it.waitFor() }.exitValue().let {
if (it != 0) {
throw IllegalStateException("FFmpeg is not installed")
}
}
runtime.exec("optipng -v").also { it.waitFor() }.exitValue().let {
if (it != 0) {
throw IllegalStateException("OptiPNG is not installed")
}
}
runtime.exec("dwebp -h").also { it.waitFor() }.exitValue().let {
if (it != 0) {
throw IllegalStateException("WebP tools are not installed")
}
}
runtime.exec("lottie_convert.py -h").also { it.waitFor() }.exitValue().let {
if (it != 0) {
throw IllegalStateException("Lottie tools are not installed")
}
}
}

fun main(args: Array<String>) {
ensureExternalTools()
runApplication<MyStickersBotApplication>(*args)
}
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
<module>backend</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
</plugin>
</plugins>
</build>
</project>
Binary file removed webp-io/src/main/resources/cwebp/linux_x86/cwebp
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/linux_x86/dwebp
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/linux_x86/gif2webp
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/linux_x86_64/cwebp
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/linux_x86_64/dwebp
Binary file not shown.
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/mac_x86_64/cwebp
Binary file not shown.
Binary file removed webp-io/src/main/resources/cwebp/mac_x86_64/dwebp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 736a74c

Please sign in to comment.