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

Add Docker Support with Dockerfile and Docker Compose #9

Merged
merged 4 commits into from
Nov 26, 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
Binary file added previews/docker-console-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/docker-console-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions webrtc-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use the official Gradle 6.6.1 image with JDK 17 as the build environment
FROM gradle:6.6.1-jdk11 AS build

# Set the working directory inside the container
WORKDIR /app

# Copy the project files into the container
COPY . .

# Set JVM compatibility to 17 in the build process
RUN gradle clean build -Dorg.gradle.java.home=/opt/java/openjdk -x test --no-daemon

# Use the official OpenJDK 17 runtime as the runtime environment
FROM openjdk:17-jdk-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the built JAR from the build environment
COPY --from=build /app/build/libs/*.jar app.jar

# Expose the port that the application will run on
EXPOSE 8080

# Set environment variables if needed (e.g., for ports)
ENV PORT=8080

# Run the application
CMD ["java", "-jar", "app.jar"]
15 changes: 15 additions & 0 deletions webrtc-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@ dependencies {
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}

// JAR task configuration to include the main class in the manifest
jar {
manifest {
attributes(
'Main-Class': mainClassName, // Sets the Main-Class attribute for JAR execution
'Implementation-Title': project.name,
'Implementation-Version': project.version
)
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Exclude duplicate files
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } // Include dependencies in the JAR
}
}
9 changes: 9 additions & 0 deletions webrtc-backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'

services:
webrtc_ktro_server:
# image: DOCKER IMAGE NAME
build: .
ports:
- "8080:8080"
restart: always
Loading