2024-02-22 01:45:41 +05:30
|
|
|
#syntax=docker/dockerfile:1
|
2024-02-15 03:02:13 +05:30
|
|
|
|
2024-02-15 16:50:39 +05:30
|
|
|
# Add the following lines to tag the image (replace 'your_username' and 'shortener-app' with your Docker Hub username and repository name)
|
|
|
|
ARG VERSION=latest
|
2024-02-22 00:43:50 +05:30
|
|
|
ARG IMAGE_NAME=nmpl/shortener
|
2024-02-15 16:50:39 +05:30
|
|
|
ARG TAG=$VERSION
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#------STAGE 1: Build the application-----#
|
|
|
|
#
|
|
|
|
# Get Maven with JDK 21
|
2024-02-15 03:02:13 +05:30
|
|
|
FROM maven:3.9.6-eclipse-temurin-21 AS builder
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
#Cloud Install : Clone the repository
|
2024-02-15 03:02:13 +05:30
|
|
|
RUN git clone https://github.com/aamitn/URLShortener.git
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
#Local Install
|
|
|
|
#ADD . /UrlShortener
|
|
|
|
|
|
|
|
# Change working directory to the repo directory
|
2024-02-15 03:02:13 +05:30
|
|
|
WORKDIR /URLShortener
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
# Docker makes db accessible like this : mysql://<container-name>:port instead of mysql://<server-ip>:port
|
|
|
|
# Example real world db access url : mysql://127.0.0.1:3306
|
|
|
|
# Example Docker db access url : mysql://database:3306 (container name is datbase)
|
|
|
|
# Change the database ip in app config to the database docker container name/service
|
2024-02-22 04:53:55 +05:30
|
|
|
# RUN sed -i "s|database.ip=127.0.0.1|database.ip=database |g" src/main/resources/application.properties
|
2024-02-22 00:43:50 +05:30
|
|
|
|
2024-02-15 03:02:13 +05:30
|
|
|
# Build the application
|
|
|
|
RUN mvn clean install
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#------STAGE 2: Deploy the Generated War-----#
|
|
|
|
#
|
|
|
|
## Get Tomacat 10 with JDK21
|
2024-02-15 03:02:13 +05:30
|
|
|
FROM tomcat:10-jdk21-openjdk-slim
|
|
|
|
|
|
|
|
# Set environment variables
|
|
|
|
ENV CATALINA_BASE /usr/local/tomcat
|
|
|
|
ENV CATALINA_HOME /usr/local/tomcat
|
|
|
|
ENV PATH $CATALINA_HOME/bin:$PATH
|
|
|
|
|
|
|
|
# Copy the WAR file from the builder stage
|
2024-02-15 16:50:39 +05:30
|
|
|
COPY --from=builder /URLShortener/target/shortener.war $CATALINA_BASE/webapps/
|
2024-02-15 03:02:13 +05:30
|
|
|
|
|
|
|
|
2024-02-22 00:43:50 +05:30
|
|
|
|
|
|
|
#
|
|
|
|
#------STAGE 3: Configure and Start Application Server-----#
|
|
|
|
#
|
2024-02-15 03:02:13 +05:30
|
|
|
# Add configuration for document base path
|
|
|
|
COPY server.xml $CATALINA_BASE/conf/server.xml
|
|
|
|
|
|
|
|
# Expose ports
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
# Start Tomcat and MariaDB using the startup script
|
2024-02-22 00:43:50 +05:30
|
|
|
CMD ["catalina.sh", "run"]
|