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

adding support to jboss #3

Merged
merged 8 commits into from
Nov 19, 2022
Merged
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
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# xmigrate_cli
VM to container migration tool

# Overview
Cmigrate is an open-source project for migrating your VM-based application deployments to container. Cmigrate is a CLI based tool wriitten in python which can discover the application runtime on the server and generate a docker file and the application artifacts to containerize.

## Current release
---

We have shipped cmigrate with the following features :

- Automatic Environment discovery
- Option to select from multiple environments
- Automatically collect the application-related environment variable and configurations
- Generates docker file for containerization of the application
- Support for tomcat and jboss based application


> 💡 *Currently cmigrate only support tomcat and Jboss. We will add support for more application in the forthcoming releases.


## Tech stack
Cmigrate is build on the below tech stack
- Click python framework
- Jinja web template engine


All the code for cmigrate is written in python. Jinja is a web template engine for the Python programming language and it is used to create the template for generating a docker file. Click is a Python package for creating command-line interfaces.

## Future Roadmap
- Support for more applications runtimes

## 🚀How to run?

Run the cmigrate.py file.

```
python3 cmigrate.py
```

if you have multiple application runtime running you can pass one in --runtime parameter.

Stay tuned for more updates 🎉

22 changes: 21 additions & 1 deletion cmigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def find_runtime():
app_runtimes.append("tomcat")
elif "httpd" in proc.as_dict().values():
app_runtimes.append("httpd")
elif "jboss" in str(proc.as_dict().values()):
app_runtimes.append("jboss")

return list(set(app_runtimes))

Expand All @@ -34,6 +36,21 @@ def get_artefacts(app_runtime):
continue
else:
artefact['APP_PORT'] = conn.laddr.port
# jboss
if app_runtime=='jboss':
for proc in psutil.process_iter():
if "jboss" in str(proc.as_dict().values()):
break
artefact['APP_RUNTIME'] = app_runtime
war_files = glob(proc.environ()['JBOSS_HOME'] + 'standalone/deployments/*.war')
artefact['APP_DIR'] = war_files
artefact['APP_CONFIG'] = proc.environ()['JBOSS_HOME'] + '/bin/standalone/configuration/standalone.xml'
for conn in proc.connections():
if conn.laddr.port == 8080:
continue
else:
artefact['APP_PORT'] = conn.laddr.port

if app_runtime == 'httpd':
for proc in psutil.process_iter():
if "httpd" in proc.as_dict().values():
Expand All @@ -49,6 +66,10 @@ def generate_docker_file(artefacts):
templateEnv = jinja2.Environment(loader=templateLoader)
if artefacts['APP_RUNTIME'] == "tomcat":
TEMPLATE_FILE = "Dockerfile-tomcat.j2"
elif artefacts['APP_RUNTIME'] == "jboss":
TEMPLATE_FILE = "Dockerfile-jboss.j2"
# elif artefacts['APP_RUNTIME'] == "httpd":
# TEMPLATE_FILE = "Dockerfile-httpd.j2"
template = templateEnv.get_template(TEMPLATE_FILE)
output_dir = './artefact'
isExist = os.path.exists(output_dir)
Expand Down Expand Up @@ -90,4 +111,3 @@ def build_dockerfile(runtime):

if __name__ == '__main__':
build_dockerfile()

8 changes: 8 additions & 0 deletions templates/Dockerfile-jboss.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM registry.access.redhat.com/jboss-eap-7/eap71-openshift
LABEL maintainer="xmigrate.cloud"
{% for artefact in artefacts.APP_DIR %}
COPY {{ artefact }} standalone/deployments
{% endfor %}
COPY {{ artefacts.APP_CONFIG }} /bin/standalone/configuration/standalone.xml
EXPOSE {{ artefacts.APP_PORT }}
CMD ["standalone.sh", "run"]