[+] Docker

pull/6/head
Azalea Gui 2023-12-21 01:27:18 -05:00
parent dd70265cb6
commit 0fda25b482
3 changed files with 72 additions and 0 deletions

32
Dockerfile 100644
View File

@ -0,0 +1,32 @@
# Use a multi-stage build to keep the image size small
# Start with a Gradle image for building the project
FROM gradle:jdk11 as builder
# Copy the Gradle wrapper and configuration files separately to leverage Docker cache
COPY --chown=gradle:gradle gradlew /home/gradle/
COPY --chown=gradle:gradle gradle /home/gradle/gradle
COPY --chown=gradle:gradle build.gradle.kts settings.gradle.kts /home/gradle/
# Set working directory
WORKDIR /home/gradle
# Download dependencies - cached if build.gradle.kts and settings.gradle.kts are unchanged
RUN ./gradlew dependencies
# Copy the project source, this layer is rebuilt whenever a file has changed
COPY --chown=gradle:gradle src /home/gradle/src
# Build the application
RUN ./gradlew build -x test
# Start with a fresh image for the runtime
FROM openjdk:11-jre-slim
# Set the deployment directory
WORKDIR /app
# Copy only the built JAR from the builder image
COPY --from=builder /home/gradle/build/libs/aqua-?.?.??.jar /app/
# The command to run the application
CMD java -jar aqua-*.jar

14
deploy.sh 100755
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# This is a deploy script for this java program
# 1. Build the jar
rm -rf build/libs
JAVA_HOME="/usr/lib/jvm/java-17-openjdk" ./gradlew build
# 2. Copy the jar to the server
jar_name=$(ls -v build/libs/aqua-*.jar | grep -v "plain" | head -n 1)
scp "$jar_name" lux:/root/aqua/aqua.jar
# 3. Restart the service
ssh lux "systemctl restart aqua"

26
docker-compose.yml 100644
View File

@ -0,0 +1,26 @@
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080" # Replace with your application's port
environment:
- DB_HOST=db
- DB_PORT=3306
- DB_USER=root
- DB_PASSWORD=mysecret
depends_on:
- db
db:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: mysecret
MYSQL_DATABASE: myappdb
MYSQL_USER: myappuser
MYSQL_PASSWORD: myapppassword
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql