diff --git a/.gitea/workflows/checks-and-policy.yml b/.gitea/workflows/checks-and-policy.yml index 8fc17ec..409b5e4 100644 --- a/.gitea/workflows/checks-and-policy.yml +++ b/.gitea/workflows/checks-and-policy.yml @@ -74,6 +74,7 @@ jobs: frontend-${{ runner.os }}-yarn- run: | yarn install --frozen-lockfile + yarn build #yarn test --watchAll=false --ci #Check frontend linting diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e9a367 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# ===== 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"] \ No newline at end of file diff --git a/build-image.sh b/build-image.sh new file mode 100644 index 0000000..9fb4fea --- /dev/null +++ b/build-image.sh @@ -0,0 +1,8 @@ +#! /bin/bash +set -e # Exit immediately if a command exits with a non-zero status + +export $(grep -v '^#' C:/atrizult/projects/.env | xargs) + +#Build +docker buildx build --no-cache -t eberen/services:backend-${VERSION} . +echo "Docker Image Built Successfully"