konveyor / move2kube

Move2Kube is a command-line tool for automating creation of Infrastructure as code (IaC) artifacts. It has inbuilt support for creating IaC artifacts for replatforming to Kubernetes/Openshift.
https://move2kube.konveyor.io/
Apache License 2.0
383 stars 118 forks source link

Incorrect port mapping for Tomcat server #801

Open Akash-Nayak opened 2 years ago

Akash-Nayak commented 2 years ago

Describe the bug The Dockerfile and the K8s deployment yamls use incorrect port instead of using the port entered by the user for the service during the QA.

To Reproduce Steps to reproduce the behavior:

  1. Run move2kube transform on the enterprise-app sample.
  2. Select the default selected port (8082) for the customers service during the QA.

    ? Select the port to be exposed for the service customers.childModules.customers :
    ID: move2kube.services.customers.childModules.customers.port
    Hints:
    - Select 'Other' if you want to expose the service using a different port.
    
    [Use arrows to move, type to filter]
    > 8082
    Other (specify custom option)

Dockerfile created by Move2Kube exposes port 8080 instead of port 8082.

FROM registry.access.redhat.com/ubi8/ubi:latest AS customers-buildstage
RUN yum install -y java-1.8.0-openjdk-devel

WORKDIR /app
# copy only the pom and download the dependencies for caching purposes
COPY pom.xml .
COPY mvnw .
COPY .mvn .mvn
RUN ./mvnw dependency:go-offline
# copy the source files to do a build
COPY . .

RUN ./mvnw clean package -Dmaven.test.skip -Dcheckstyle.skip -P dev-inmemorydb,prod-externaldb

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR /usr/local
RUN microdnf update && microdnf install -y java-1.8.0-openjdk-devel wget tar gzip shadow-utils && microdnf clean all

# environment variables
ENV CATALINA_PID='/usr/local/tomcat10/temp/tomcat.pid' CATALINA_HOME='/usr/local/tomcat10' CATALINA_BASE='/usr/local/tomcat10'
ENV SERVER_PORT 8082
ENV SPRING_PROFILES_ACTIVE dev-inmemorydb

# install tomcat
RUN wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.16/bin/apache-tomcat-10.0.16.tar.gz && \
    tar -zxf apache-tomcat-10.0.16.tar.gz && \
    rm -f apache-tomcat-10.0.16.tar.gz && \
    mv apache-tomcat-10.0.16 tomcat10 && \
    rm -r "$CATALINA_BASE"/webapps/ROOT && \
    adduser -r tomcat && chown -R tomcat:tomcat tomcat10
USER tomcat:tomcat

COPY --chown=tomcat:tomcat --from=customers-buildstage /app/target/ROOT.war "$CATALINA_BASE"/webapps-javaee/
EXPOSE 8080
CMD [ "/usr/local/tomcat10/bin/catalina.sh", "run" ]

customers-service.yaml

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    move2kube.konveyor.io/service: customers
  name: customers
spec:
  internalTrafficPolicy: Cluster
  ports:
    - name: port-8080
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    move2kube.konveyor.io/service: customers
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

Expected behavior In this case, the Dockerfile and the K8s yamls should use port 8082 instead of port 8080.

HarikrishnanBalagopal commented 7 months ago

This bug is still present in v0.3.x

To change the default port in TomCat we will need to edit the server.xml in the generated Dockerfile: