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 and Automation Script #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# First stage - Build the Java application
FROM openjdk:8-jdk as java-build

# Set the working directory for the Java build
WORKDIR /app

# Copy the Java project files
COPY . .

# Install Gradle
ARG GRADLE_VERSION=3.4.1
RUN wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -P /tmp && \
unzip -d /opt/gradle /tmp/gradle-${GRADLE_VERSION}-bin.zip && \
rm /tmp/gradle-${GRADLE_VERSION}-bin.zip

# Add Gradle to the PATH environment variable
ENV GRADLE_HOME=/opt/gradle/gradle-${GRADLE_VERSION}
ENV PATH=${GRADLE_HOME}/bin:${PATH}

# Initialize Gradle wrapper and build the Java project
RUN gradle wrapper && \
./gradlew build -x test

# Second stage - Build the Angular application
FROM node:14 as angular-build

# Set working directory for Angular build
WORKDIR /webui

# Copy the Angular project files from the first stage
COPY --from=java-build /app/webui .

# Install npm dependencies for Angular
RUN npm install
RUN npm install -g @angular/[email protected]

# Build the Angular project
RUN ng build

# Final stage - Prepare the runtime image
FROM openjdk:8-jdk

# Expose the port the app runs on
EXPOSE 8080

# Set the working directory for the final image
WORKDIR /app

# Copy the built jar file from the Java build stage
COPY --from=java-build /app/build/libs/*.jar app.jar

# Copy the built Angular application from the Angular build stage
COPY --from=angular-build /webui/dist /app/webui/dist


# Set the entry point of the container
# Set the default command to execute when creating a new container

CMD ["java", "-jar", "/app/app.jar"]

27 changes: 27 additions & 0 deletions run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Name of the Docker image
IMAGE_NAME="angular-springboot-image"

# Build the Docker image
echo "Building Docker image..."
docker build -t $IMAGE_NAME .

# Check if build was successful
if [ $? -eq 0 ]; then
echo "Docker image built successfully."

# Run the Docker container
echo "Running Docker container..."
docker run -p 8080:9119 -d $IMAGE_NAME

# Check if the container started successfully
if [ $? -eq 0 ]; then
echo "Docker container is running."
echo "Access the application at http://localhost:8080"
else
echo "Failed to start Docker container."
fi
else
echo "Failed to build Docker image."
fi