All checks were successful
checks / Set up Node and other necessary dependencies for Frontend Tests and Build (push) Successful in 12s
checks / Set up Java for Backend Tests and Build (push) Successful in 15s
Gitea Actions Demo / Explore-Gitea-Actions-2 (pull_request) Successful in 3s
checks / Set up Node and other necessary dependencies for Frontend Tests and Build (pull_request) Successful in 12s
checks / Set up Java for Backend Tests and Build (pull_request) Successful in 11s
47 lines
1.5 KiB
Docker
47 lines
1.5 KiB
Docker
# ===== Stage 1: Build with Maven =====
|
|
FROM eclipse-temurin:21-jdk-alpine AS builder
|
|
|
|
ARG MAVEN_VERSION=3.9.9
|
|
ENV MAVEN_HOME=/opt/maven
|
|
ENV PATH=${MAVEN_HOME}/bin:${PATH}
|
|
|
|
# Install required tools quietly and set up Maven
|
|
RUN set -eux; \
|
|
apk add --no-cache curl tar bash openssl >/dev/null; \
|
|
echo "Downloading Maven ${MAVEN_VERSION}..."; \
|
|
curl -fsSL "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" -o /tmp/maven.tar.gz; \
|
|
mkdir -p /opt >/dev/null; \
|
|
tar -xzf /tmp/maven.tar.gz -C /opt >/dev/null; \
|
|
ln -s /opt/apache-maven-${MAVEN_VERSION} ${MAVEN_HOME}; \
|
|
rm /tmp/maven.tar.gz; \
|
|
echo "✅ Maven ${MAVEN_VERSION} installed successfully."
|
|
|
|
WORKDIR /build
|
|
|
|
# Copy pom.xml and prefetch dependencies silently
|
|
COPY pom.xml .
|
|
RUN mvn -B -q dependency:go-offline
|
|
|
|
# Copy source code
|
|
COPY src ./src
|
|
|
|
# Build project (skip tests, quiet mode)
|
|
RUN mvn -B -q clean package -DskipTests
|
|
|
|
# ===== Stage 2: Runtime image =====
|
|
FROM eclipse-temurin:21-jre-alpine
|
|
|
|
RUN addgroup -S spring && adduser -S spring -G spring
|
|
USER spring:spring
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder /build/target/*.jar app.jar
|
|
|
|
EXPOSE 8080
|
|
|
|
# Optional: Health check (Spring Boot actuator)
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
|
CMD wget -qO- http://localhost:8080/actuator/health | grep '"status":"UP"' || exit 1
|
|
|
|
ENTRYPOINT ["java", "-XX:+UseContainerSupport", "-XX:MaxRAMPercentage=75.0", "-jar", "app.jar"] |