diff --git a/src/main.py b/src/main.py index 0c492a3..d6706b1 100644 --- a/src/main.py +++ b/src/main.py @@ -20,6 +20,9 @@ def podman_init(project_name, language): type=click.Choice(['django', 'fastapi', 'flask', 'exit'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -31,6 +34,9 @@ def podman_init(project_name, language): type=click.Choice(['spring', 'quarkus', 'micronaut', 'vertx', 'exit'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -42,6 +48,9 @@ def podman_init(project_name, language): type=click.Choice(['gin', 'echo', 'chi', 'fiber', 'exit'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -53,6 +62,9 @@ def podman_init(project_name, language): type=click.Choice(['express', 'nest', 'koa', 'fastify', 'exit'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -64,6 +76,9 @@ def podman_init(project_name, language): type=click.Choice(['.net core', 'blazor'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -75,6 +90,9 @@ def podman_init(project_name, language): type=click.Choice(['actix', 'axum', 'rocket', 'warp', 'tide', 'exit'], case_sensitive=False), show_choices=True) + port = click.prompt('Choose port', + type=int) + if framework == 'exit': click.echo(style("Exiting...", fg='red')) sys.exit() @@ -88,13 +106,13 @@ def podman_init(project_name, language): load_jinja_env = Environment(loader=FileSystemLoader(template_dir)) dockerfile_template = load_jinja_env.get_template('Dockerfile.j2') - dockerfile_content = dockerfile_template.render(project_name=project_name, framework=framework) + dockerfile_content = dockerfile_template.render(project_name=project_name, framework=framework, port=port) with open('Dockerfile', 'w') as f: f.write(dockerfile_content) compose_template = load_jinja_env.get_template('docker-compose.yml.j2') - compose_content = compose_template.render(project_name=project_name, framework=framework) + compose_content = compose_template.render(project_name=project_name, framework=framework, port=port) with open('docker-compose.yml', 'w') as f: f.write(compose_content) diff --git a/src/templates/c#/docker-compose.yml.j2 b/src/templates/c#/docker-compose.yml.j2 index 9f397fa..50b2aaf 100644 --- a/src/templates/c#/docker-compose.yml.j2 +++ b/src/templates/c#/docker-compose.yml.j2 @@ -8,7 +8,7 @@ services: {% if framework == 'dot-net_core' %}container_name: dot-net_core {% elif framework == 'blazor' %}container_name: blazor {% endif %}ports: - - "5000:80" + - "{{ port }}:80" environment: - ASPNETCORE_ENVIRONMENT=Development diff --git a/src/templates/go/Dockerfile.j2 b/src/templates/go/Dockerfile.j2 index 83cfd90..dcc614a 100644 --- a/src/templates/go/Dockerfile.j2 +++ b/src/templates/go/Dockerfile.j2 @@ -24,9 +24,7 @@ FROM alpine:latest COPY --from=build /app/main . # Expose port 3000 to the outside world -{% if framework == 'gin' or framework == 'echo' %}EXPOSE 8080 -{% elif framework == 'chi' %}EXPOSE 3333 -{% elif framework == 'fiber' %}EXPOSE 3000 -{% endif %} +EXPOSE {{ port }} + # Command to run the executable CMD ["./main"] diff --git a/src/templates/go/docker-compose.yml.j2 b/src/templates/go/docker-compose.yml.j2 index 103552a..28bd1df 100644 --- a/src/templates/go/docker-compose.yml.j2 +++ b/src/templates/go/docker-compose.yml.j2 @@ -6,16 +6,9 @@ services: context: . dockerfile: Dockerfile {% if framework == 'gin' %}container_name: gin - ports: - - "8080:8080" {% elif framework == 'echo' %}container_name: echo - ports: - - "8080:8080" {% elif framework == 'chi' %}container_name: chi - ports: - - "3333:3333" {% elif framework == 'fiber' %}container_name: fiber - ports: - - "3000:3000" - {% endif %} + {% endif %}ports: + - "{{ port }}:{{ port }}" # Add additional configurations as needed \ No newline at end of file diff --git a/src/templates/java/Dockerfile.j2 b/src/templates/java/Dockerfile.j2 index 7f07586..c742d6c 100644 --- a/src/templates/java/Dockerfile.j2 +++ b/src/templates/java/Dockerfile.j2 @@ -8,7 +8,7 @@ WORKDIR /src COPY target/*.jar /src/app.jar # Expose port 8080 to allow external access to the application -EXPOSE 8080 +EXPOSE {{ port }} # Define the entry point to execute the application when the container starts ENTRYPOINT ["java", "-jar" , "app.jar"] \ No newline at end of file diff --git a/src/templates/java/docker-compose.yml.j2 b/src/templates/java/docker-compose.yml.j2 index b6141c5..3d91f6d 100644 --- a/src/templates/java/docker-compose.yml.j2 +++ b/src/templates/java/docker-compose.yml.j2 @@ -10,6 +10,6 @@ services: {% elif framework == 'micronaut' %}container_name: micronaut {% elif framework == 'vertx' %}container_name: vertx {% endif %}ports: - - "8080:8080" + - "{{ port }}:{{ port }}" # Add additional configurations as needed \ No newline at end of file diff --git a/src/templates/node/Dockerfile.j2 b/src/templates/node/Dockerfile.j2 index 0c5026b..31861d7 100644 --- a/src/templates/node/Dockerfile.j2 +++ b/src/templates/node/Dockerfile.j2 @@ -13,8 +13,8 @@ RUN npm install # Copy the rest of the application code to the working directory COPY . . -# Expose port 3000 -EXPOSE 3000 +# Expose port +EXPOSE {{ port }} # Command to run the application CMD ["node", "app.js"] diff --git a/src/templates/node/docker-compose.yml.j2 b/src/templates/node/docker-compose.yml.j2 index 88da10b..73b8329 100644 --- a/src/templates/node/docker-compose.yml.j2 +++ b/src/templates/node/docker-compose.yml.j2 @@ -10,7 +10,7 @@ services: {% elif framework == 'koa' %}container_name: koa {% elif framework == 'fastify' %}container_name: fastify {% endif %}ports: - - "3000:3000" + - "{{ port }}:{{ port }}" volumes: - .:/usr/src/app environment: diff --git a/src/templates/python/Dockerfile.j2 b/src/templates/python/Dockerfile.j2 index 0e4012f..0f6d7ea 100644 --- a/src/templates/python/Dockerfile.j2 +++ b/src/templates/python/Dockerfile.j2 @@ -18,18 +18,16 @@ RUN pip install --upgrade pip && \ pip install --no-cache-dir --upgrade -r requirements.txt && \ # Expose ports and define startup commands based on selected framework -{% if framework == 'django' %}EXPOSE 8000 - +EXPOSE {{ port }} +{% if framework == 'django' %} # Specify the entry point CMD ["python", "manage.py", "runserver"] -{% elif framework == 'fastapi' %}EXPOSE 8000 - -# # Specify the entry point (Replace "mail" with your actual file name) +{% elif framework == 'fastapi' %} +# Specify the entry point (Replace "mail" with your actual file name) CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--reload"] -{% elif framework == 'flask' %}EXPOSE 5000 - +{% elif framework == 'flask' %} # Specify the entry point CMD ["flask", "run"] {% endif %} \ No newline at end of file diff --git a/src/templates/python/docker-compose.yml.j2 b/src/templates/python/docker-compose.yml.j2 index ced3a44..d4e039c 100644 --- a/src/templates/python/docker-compose.yml.j2 +++ b/src/templates/python/docker-compose.yml.j2 @@ -6,15 +6,11 @@ services: context: . dockerfile: Dockerfile {% if framework == 'django' %}container_name: django - ports: - - "8000:8000" {% elif framework == 'fastapi' %}container_name: fastapi - ports: - - "8000:8000" - {% elif framework == 'flask' %}container_name: flask - ports: - - "5000:5000" - {% endif %}volumes: + {% elif framework == 'flask' %}container_name: flask + {% endif %}ports: + - "{{ port }}:{{ port }}" + volumes: - .:/app # Add additional configurations as needed \ No newline at end of file diff --git a/src/templates/rust/Dockerfile.j2 b/src/templates/rust/Dockerfile.j2 index a6c6f22..73cd531 100644 --- a/src/templates/rust/Dockerfile.j2 +++ b/src/templates/rust/Dockerfile.j2 @@ -27,10 +27,7 @@ FROM debian:buster-slim COPY --from=builder /usr/src/myapp/target/release/myapp . # Expose the port the Actix Web application will listen on -{% if framework == 'actix' %}EXPOSE 8080 -{% elif framework == 'axum' %}EXPOSE 3000 -{% elif framework == 'rocket' or framework == 'tide' %}EXPOSE 8000 -{% elif framework == 'warp' %}EXPOSE 3030 -{% endif %} +Expose {{ port }} + # Command to run the application CMD ["./myapp"] diff --git a/src/templates/rust/docker-compose.yml.j2 b/src/templates/rust/docker-compose.yml.j2 index c430019..087f0b9 100644 --- a/src/templates/rust/docker-compose.yml.j2 +++ b/src/templates/rust/docker-compose.yml.j2 @@ -6,19 +6,10 @@ services: context: . dockerfile: Dockerfile {% if framework == 'actix' %}container_name: actix - ports: - - "8080:8080" {% elif framework == 'axum' %}container_name: axum - ports: - - "3000:3000" {% elif framework == 'rocket' %}container_name: rocket - ports: - - "8000:8000" {% elif framework == 'warp' %}container_name: warp - ports: - - "3030:3030" - {% elif framework == 'tide' %}container_name: tide - ports: - - "8000:8000" - {% endif %} + {% elif framework == 'tide' %}container_name: tide + {% endif %}ports: + - "{{ port }}:{{ port }}" # Add additional configurations as needed diff --git a/tests/test_podman_init.py b/tests/test_podman_init.py index bf42962..f18184d 100644 --- a/tests/test_podman_init.py +++ b/tests/test_podman_init.py @@ -6,7 +6,7 @@ def test_podman_init_python_flask(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='flask\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='flask\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -17,7 +17,7 @@ def test_podman_init_python_flask(): def test_podman_init_python_fastapi(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='fastapi\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='fastapi\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -28,7 +28,7 @@ def test_podman_init_python_fastapi(): def test_podman_init_python_django(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='django\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'python'], input='django\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -39,7 +39,7 @@ def test_podman_init_python_django(): def test_podman_init_java_spring(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='spring\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='spring\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -50,7 +50,7 @@ def test_podman_init_java_spring(): def test_podman_init_java_quarkus(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='quarkus\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='quarkus\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -61,7 +61,7 @@ def test_podman_init_java_quarkus(): def test_podman_init_java_micronaut(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='micronaut\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='micronaut\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -72,7 +72,7 @@ def test_podman_init_java_micronaut(): def test_podman_init_java_vertx(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='vertx\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'java'], input='vertx\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -83,7 +83,7 @@ def test_podman_init_java_vertx(): def test_podman_init_go_gin(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='gin\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='gin\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -94,7 +94,7 @@ def test_podman_init_go_gin(): def test_podman_init_go_echo(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='echo\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='echo\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -105,7 +105,7 @@ def test_podman_init_go_echo(): def test_podman_init_go_chi(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='chi\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='chi\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -116,7 +116,7 @@ def test_podman_init_go_chi(): def test_podman_init_go_fiber(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='fiber\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'go'], input='fiber\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -127,7 +127,7 @@ def test_podman_init_go_fiber(): def test_podman_init_node_express(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='express\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='express\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -138,7 +138,7 @@ def test_podman_init_node_express(): def test_podman_init_node_nest(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='nest\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='nest\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -149,7 +149,7 @@ def test_podman_init_node_nest(): def test_podman_init_node_koa(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='koa\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='koa\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -160,7 +160,7 @@ def test_podman_init_node_koa(): def test_podman_init_node_fastify(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='fastify\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'node'], input='fastify\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -171,7 +171,7 @@ def test_podman_init_node_fastify(): def test_podman_init_chash_dotnet_core(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'c#'], input='.net core\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'c#'], input='.net core\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -182,7 +182,7 @@ def test_podman_init_chash_dotnet_core(): def test_podman_init_chash_blazor(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'c#'], input='blazor\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'c#'], input='blazor\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -193,7 +193,7 @@ def test_podman_init_chash_blazor(): def test_podman_init_rust_actix(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='actix\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='actix\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -204,7 +204,7 @@ def test_podman_init_rust_actix(): def test_podman_init_rust_axum(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='axum\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='axum\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -215,7 +215,7 @@ def test_podman_init_rust_axum(): def test_podman_init_rust_rocket(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='rocket\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='rocket\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -226,7 +226,7 @@ def test_podman_init_rust_rocket(): def test_podman_init_rust_warp(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='warp\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='warp\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml') @@ -237,7 +237,7 @@ def test_podman_init_rust_warp(): def test_podman_init_rust_tide(): runner = CliRunner() - result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='tide\n') + result = runner.invoke(podman_init, ['--project-name', 'test_project', '--language', 'rust'], input='tide\n8000\n') assert result.exit_code == 0 assert os.path.isfile('Dockerfile') assert os.path.isfile('docker-compose.yml')