diff --git a/ec2/create_infra.yml b/ec2/create_infra.yml index fd0deeb..29e2c54 100644 --- a/ec2/create_infra.yml +++ b/ec2/create_infra.yml @@ -92,6 +92,14 @@ ports: - 9990 cidr_ip: 0.0.0.0/0 + - proto: tcp + ports: + - 8081 + cidr_ip: 0.0.0.0/0 + - proto: tcp + ports: + - 8085 + cidr_ip: 0.0.0.0/0 state: "present" register: security_group diff --git a/ec2/requirements.yml b/ec2/requirements.yml index 2e03b96..f4b80f5 100644 --- a/ec2/requirements.yml +++ b/ec2/requirements.yml @@ -6,4 +6,5 @@ collections: - middleware_automation.common - middleware_automation.wildfly - kubernetes.core +- middleware_automation.keycloak diff --git a/ec2/roles/jboss-app-deploy/tasks/mvn-deploy.yml b/ec2/roles/jboss-app-deploy/tasks/mvn-deploy.yml index f5fe5c5..0cdb5b3 100644 --- a/ec2/roles/jboss-app-deploy/tasks/mvn-deploy.yml +++ b/ec2/roles/jboss-app-deploy/tasks/mvn-deploy.yml @@ -1,6 +1,4 @@ --- - - - name: Check if Maven is installed ansible.builtin.command: cmd: mvn --version diff --git a/ec2/roles/jboss-eap/tasks/main.yml b/ec2/roles/jboss-eap/tasks/main.yml index 2a73017..e33cf78 100644 --- a/ec2/roles/jboss-eap/tasks/main.yml +++ b/ec2/roles/jboss-eap/tasks/main.yml @@ -8,7 +8,7 @@ wildfly_archive_filename: "{{ install_name }}-{{ wildfly_version }}.zip" wildfly_user: "{{ install_name }}" wildfly_group: "{{ install_name }}" - wildfly_config_base: standalone.xml + wildfly_config_base: standalone-full.xml wildfly_home: "{{ wildfly_install_workdir }}/{{ install_name }}-{{ 7.4 }}" wildfly_offline_install: true include_role: @@ -17,7 +17,7 @@ - name: "enable service" vars: - wildfly_config_base: 'standalone.xml' + wildfly_config_base: 'standalone-full.xml' install_name: jboss-eap wildfly_basedir_prefix: "/opt/{{ install_name }}" wildfly_config_name: "{{ install_name }}" @@ -51,4 +51,4 @@ register: out - name: "INFO: Display localhost:8080 content" - debug: var=out.stdout_lines \ No newline at end of file + debug: var=out.stdout_lines diff --git a/ec2/roles/kyma_infra/.travis.yml b/ec2/roles/kyma_infra/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/ec2/roles/kyma_infra/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/ec2/roles/kyma_infra/README.md b/ec2/roles/kyma_infra/README.md new file mode 100644 index 0000000..9511fb9 --- /dev/null +++ b/ec2/roles/kyma_infra/README.md @@ -0,0 +1,70 @@ +Role Name +========= + +Installs java11 and java8 on a Fedora server that can be used with Quarkus and EAP app deployment respectively. + +Requirements +------------ + +Provision the fedora server using ./create_infra.sh. Please refer to the [readme](../README.md) + +Dependencies +------------ +* This role is dependent on the following roles + - jboss-eap + - Wildfly utils + - Wildfly driver + - keycloak + +How to deploy the apps +------------- +* For setting up the ec2 instance, refer to [ec2 role](https://github.com/migtools/playpen/tree/main/ec2#readme) + +* Once its setup, make sure the app you want to install has the [correct configuration](./ec2/roles/kyma_infra/defaults/main.yml) + +* Run the role using the script `./setup_kyma_infra.sh` + +Once the run is successful you can access the apps in the following URLs, + +* Kitchensink - https://github.com/tqvarnst/jboss-eap-quickstarts/tree/quarkus-3.2, https://github.com/windup/jboss-eap-quickstarts/tree/7.4.x/kitchensink/src/main/java/org/jboss/as/quickstarts/kitchensink + * eap - http://:8080/kitchensink + * quarkus - http://:8085/kitchensink + +* helloworld-mdb - https://github.com/savitharaghunathan/helloworld-mdb + * eap - http://:8080/helloworld-mdb/HelloWorldMDBServletClient (to send messages to the queue) + * eap - http://:8080/helloworld-mdb/HelloWorldMDBServletClient?topic ( to send messages to the topic) + * quarkus - http://:8085/HelloWorldMDBServletClient + * quarkus - http://:8085/HelloWorldMDBServletClient?topic + +* coolstoredb - https://github.com/mathianasj/eap-coolstore-monolith/tree/quarkus-migration, https://github.com/deewhyweb/eap-coolstore-monolith + * eap - http://:8080 + * quarkus - http://:8085 + + +Additional Information +------------- + +Background +------------- + +* Infra setup: + * Server: fedora 38 + * docker-ce + * EAP 7.4 using java 8 + * EAP running on port 8080 + * Quarkus using java 11/17 depending on the app + * Quarkus running on port 8085 + * Java versions and quarkus installations are managed by sdkman + * manual maven install + * uses roles from migtools/playpen repo to create ec2 instance and configure eap + * note: eap should use standalone full config for messaging to work + * created a new role called kyma_infra - https://github.com/migtools/playpen/pull/5 + * run the role using the script ./setup_kyma_infra.sh + +Todo: +------ +* refactor java installation + * Take input of java versions and install that using sdkman +* Run apps in prod mode +* Note: wildfly role overrides java8 installed by sdkman. Refactor wildfly role to not install java, it is installed already +* Use mainitained ansible role for maven install and management if possible \ No newline at end of file diff --git a/ec2/roles/kyma_infra/defaults/main.yml b/ec2/roles/kyma_infra/defaults/main.yml new file mode 100644 index 0000000..c45a3f7 --- /dev/null +++ b/ec2/roles/kyma_infra/defaults/main.yml @@ -0,0 +1,44 @@ +--- +# defaults file for kyma_infra + +jboss_install_home: /opt/jboss-eap +jboss_owner: jboss-eap +jboss_group: jboss-eap + +#helloworld-mdb +#maven_deploy: false +#app_path: . +#app_name: helloworld-mdb +#git_url: https://github.com/savitharaghunathan/helloworld-mdb.git +#local_app_path: /home/fedora/{{ app_name }} +#javaee_git_branch: javaee +#quarkus_git_branch: quarkus +#same_repo: true +#war_file_path: '{{ local_app_path }}/target/{{ app_name }}.war' +#quarkus_java_version: 11.0.21-tem + + +# kitchensink +#maven_deploy: false +#app_path: kitchensink +#app_name: jboss-eap-quickstarts +#local_app_path: /home/fedora/{{ app_name }}/{{ app_path }} +#war_file_path: '{{ local_app_path }}/target/{{ app_path }}.war' +#git_url: https://github.com/windup/jboss-eap-quickstarts.git +#git_url_quarkus: https://github.com/tqvarnst/jboss-eap-quickstarts.git +#javaee_git_branch: 7.4.x +#quarkus_git_branch: quarkus-3.2 +#same_repo: false +#quarkus_java_version: 17.0.9-tem + +# coolstoredb +maven_deploy: false +app_path: . +app_name: coolstoredb +git_url: https://github.com/mathianasj/eap-coolstore-monolith +local_app_path: /home/fedora/{{ app_name }} +javaee_git_branch: main +quarkus_git_branch: quarkus-migration +same_repo: true +war_file_path: '{{ local_app_path }}/target/ROOT.war' +quarkus_java_version: 17.0.9-tem \ No newline at end of file diff --git a/ec2/roles/kyma_infra/files/postgres-config.sh b/ec2/roles/kyma_infra/files/postgres-config.sh new file mode 100644 index 0000000..d95e400 --- /dev/null +++ b/ec2/roles/kyma_infra/files/postgres-config.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/opt/jboss-eap-7.4/bin/jboss-cli.sh --connect --file=/opt/jboss-eap-7.4/bin/postgres.cli \ No newline at end of file diff --git a/ec2/roles/kyma_infra/files/postgres.cli b/ec2/roles/kyma_infra/files/postgres.cli new file mode 100644 index 0000000..e95c622 --- /dev/null +++ b/ec2/roles/kyma_infra/files/postgres.cli @@ -0,0 +1,20 @@ +# Batch script to add the PostgreSQL driver to the WildFly server configuration + +# Start batching commands +batch + +# Add the PostgreSQL database driver to the datasources subsystem + +/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql) + +data-source add --name=CoolstoreDS --jndi-name=java:jboss/datasources/CoolstoreDS --driver-name=postgresql --connection-url=jdbc:postgresql://localhost:5432/postgresDB --user-name=postgresUser --password=postgresPW + +jms-topic add --topic-address=topic.orders --entries=topic/orders + +/subsystem=messaging-activemq/server=default:write-attribute(name=cluster-password, value=password) + +# Run the batch commands +run-batch + +# Reload the server configuration +reload \ No newline at end of file diff --git a/ec2/roles/kyma_infra/handlers/main.yml b/ec2/roles/kyma_infra/handlers/main.yml new file mode 100644 index 0000000..984c11a --- /dev/null +++ b/ec2/roles/kyma_infra/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for kyma_infra diff --git a/ec2/roles/kyma_infra/meta/main.yml b/ec2/roles/kyma_infra/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/ec2/roles/kyma_infra/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/ec2/roles/kyma_infra/tasks/install-docker.yml b/ec2/roles/kyma_infra/tasks/install-docker.yml new file mode 100644 index 0000000..5cfa98c --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/install-docker.yml @@ -0,0 +1,48 @@ +- name: Install required packages + become: true + dnf: + name: "{{ item }}" + state: present + loop: + - dnf-plugins-core + +- name: Set up Docker repository + become: true + command: "dnf config-manager --add-repo=https://download.docker.com/linux/fedora/docker-ce.repo" + +- name: Install Docker + become: true + dnf: + name: "{{ item }}" + state: present + loop: + - docker-ce + - docker-ce-cli + - containerd.io + +- name: Start and enable Docker service + become: true + service: + name: docker + state: started + enabled: yes + +- name: Add user to the docker group + become: true + user: + name: "fedora" + groups: docker + append: yes + +# run command newgrp docker +- name: Run command newgrp docker + command: "newgrp docker" + +# restart docker service +- name: Restart docker service + become: true + service: + name: docker + state: restarted + +- meta: reset_connection diff --git a/ec2/roles/kyma_infra/tasks/install-mvn.yml b/ec2/roles/kyma_infra/tasks/install-mvn.yml new file mode 100644 index 0000000..9750d47 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/install-mvn.yml @@ -0,0 +1,39 @@ +--- +- name: Download Apache Maven + get_url: + url: "https://dlcdn.apache.org/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz" + dest: "/home/fedora/apache-maven-3.9.4-bin.tar.gz" + +- name: Extract Maven archive + ansible.builtin.unarchive: + src: "/home/fedora/apache-maven-3.9.4-bin.tar.gz" + dest: "/home/fedora/" + remote_src: true + +- name: Set Maven environment variables + ansible.builtin.lineinfile: + path: "/home/fedora/.bashrc" + line: "export MAVEN_HOME=/home/fedora/apache-maven-3.9.4; export PATH=$MAVEN_HOME/bin:$PATH" + regexp: "^export MAVEN_HOME=/home/fedora/apache-maven-3.9.4; export PATH=\\$MAVEN_HOME/bin:\\$PATH$" + become_user: fedora + +- name: Load Maven environment variables for the current session + ansible.builtin.shell: source /home/fedora/.bashrc + args: + executable: /bin/bash + environment: + PATH: "{{ ansible_env.PATH }}" + +# register this output to a variable +- name: Check Maven version + command: "mvn -v" + args: + chdir: "/home/fedora/" + become_user: fedora + register: mvn_output + +# print the mvn version +- name: Display Maven version + debug: + var: mvn_output.stdout_lines + when: mvn_output.rc == 0 diff --git a/ec2/roles/kyma_infra/tasks/java-app-deploy-prereq.yml b/ec2/roles/kyma_infra/tasks/java-app-deploy-prereq.yml new file mode 100644 index 0000000..dee64a1 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/java-app-deploy-prereq.yml @@ -0,0 +1,70 @@ +--- +# check if docker container myPostgresDb is running +- name: Check if docker container myPostgresDb is running + ansible.builtin.shell: docker ps -a | grep myPostgresDb + register: docker_container_status + ignore_errors: true + +# create docker db container +- name: Create docker db container + ansible.builtin.shell: docker run --name myPostgresDb -p 5432:5432 -e POSTGRES_USER=postgresUser -e POSTGRES_PASSWORD=postgresPW -e POSTGRES_DB=postgresDB -d postgres:9 + become_user: fedora + when: docker_container_status.rc != 0 + +- name: "JBoss EAP installation and configuration 1" + vars: + wildfly_install_workdir: '/opt' + wildfly_version: '7.4.0' + install_name: jboss-eap + wildfly_archive_filename: "{{ install_name }}-{{ wildfly_version }}.zip" + wildfly_user: "{{ install_name }}" + wildfly_group: "{{ install_name }}" + wildfly_config_base: standalone-full.xml + wildfly_home: "{{ wildfly_install_workdir }}/{{ install_name }}-{{ 7.4 }}" + wildfly_driver_module_name: "org.postgresql" + wildfly_driver_version: "42.5.4" + wildfly_driver_jar_filename: "postgresql-{{ wildfly_driver_version }}.jar" + wildfly_driver_jar_url: "https://jdbc.postgresql.org/download/postgresql-42.5.4.jar" + include_role: + name: middleware_automation.wildfly.wildfly_driver + +#restart jboss server +- name: Restart JBoss EAP + ansible.builtin.service: + name: jboss-eap + state: restarted + become: true +# copy files/postgres.cli to /opt/jboss-eap-7.4/bin +- name: Copy postgres.cli to /opt/jboss-eap-7.4/bin + ansible.builtin.copy: + src: files/postgres.cli + dest: /opt/jboss-eap-7.4/bin + owner: jboss-eap + group: jboss-eap + mode: 0644 + become: true + + +- name: "Execute jboss-cli script to configure db and messagequeue" + vars: + wildfly_install_workdir: '/opt' + wildfly_version: '7.4.0' + install_name: jboss-eap + wildfly_home: "{{ wildfly_install_workdir }}/{{ install_name }}-{{ 7.4 }}" + wildfly_no_restart_after_patch: False + jboss_cli_file: /opt/jboss-eap-7.4/bin/postgres.cli + include_role: + name: middleware_automation.wildfly.wildfly_utils + tasks_from: jboss_cli.yml + + +# install keycloak using middleware_automation.keycloak role +- name: Install Keycloak + include_role: + name: middleware_automation.keycloak.keycloak + vars: + #keycloak_version: 20.0.5 + keycloak_admin_password: adminchangemelater + #keycloak_download_url: https://github.com/keycloak/keycloak/releases/download/20.0.5/keycloak-20.0.5.zip + #keycloak_http_port: 8081 + keycloak_jboss_port_offset: 1 \ No newline at end of file diff --git a/ec2/roles/kyma_infra/tasks/java-app-deploy.yml b/ec2/roles/kyma_infra/tasks/java-app-deploy.yml new file mode 100644 index 0000000..e29da63 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/java-app-deploy.yml @@ -0,0 +1,80 @@ +--- +# check if java is installed and print version usimd debug module +- name: Check if Java is installed + ansible.builtin.command: + cmd: java -version + ignore_errors: true + register: java_output + +- name: Display Java version + debug: + var: java_output.stdout_lines + when: java_output.rc == 0 + +- name: Check if Maven is installed + ansible.builtin.command: + cmd: mvn --version + ignore_errors: true + register: mvn_output + +- name: Display Maven version + debug: + var: mvn_output.stdout_lines + when: mvn_output.rc == 0 + +- name: when Maven is not installed + debug: + msg: "Maven is not installed on the target machine." + when: mvn_output.rc != 0 + +# Hack: to avoid ssl certificate error +- name: Download certificate from maven.repository.redhat.com + ansible.builtin.shell: "echo -n | openssl s_client -connect maven.repository.redhat.com:443 -servername maven.repository.redhat.com 2>/dev/null | openssl x509 > /tmp/maven_repository_redhat_com.cert" + +# Hack: to avoid ssl certificate error +- name: Check if certificate is already installed + ansible.builtin.shell: "keytool -list -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit" + ignore_errors: true + register: cert_check + +- name: Import certificate into Java keystore + ansible.builtin.shell: "keytool -import -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -file /tmp/maven_repository_redhat_com.cert -storepass changeit -noprompt" + when: cert_check.rc != 0 + +- name: Configure jboss + include_tasks: java-app-deploy-prereq.yml + when: app_name is defined and app_name == "coolstoredb" + +- name: Clone the Java EE application + ansible.builtin.git: + repo: "{{ git_url }}" + dest: "/home/fedora/{{ app_name }}" + version: "{{ javaee_git_branch }}" + +- name: Deploy the application with Maven to EAP + ansible.builtin.shell: mvn clean package + args: + chdir: "{{ local_app_path }}" + + +- name: Check if war file is present + ansible.builtin.stat: + path: "{{ war_file_path }}" + register: warfile + +# print the result of war file check +- name: Display war file status + debug: + var: warfile.stat.exists + +- name: Deploy the application with Maven to EAP + ansible.builtin.copy: + src: "{{ war_file_path }}" + dest: "{{ jboss_install_home }}/deployments/" + remote_src: yes + owner: "{{ jboss_owner }}" + group: "{{ jboss_group }}" + mode: '0644' + become: true + +# todo verify url \ No newline at end of file diff --git a/ec2/roles/kyma_infra/tasks/main.yml b/ec2/roles/kyma_infra/tasks/main.yml new file mode 100644 index 0000000..8e79722 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/main.yml @@ -0,0 +1,25 @@ + + +- name: Include tasks from prereq.yaml + include_tasks: pre-req.yml + +- name: install docker ce + include_tasks: install-docker.yml + +- name: Configure Maven + include_tasks: install-mvn.yml + +- name: include roles jboss-eap + include_role: + name: jboss-eap + tasks_from: main.yml + +- name: Deploy Java EE application + include_tasks: java-app-deploy.yml + + +- name: setup quarkus env + include_tasks: quarkus-setup.yml + +- name: Deploy Quarkus application + include_tasks: quarkus-app-deploy.yml \ No newline at end of file diff --git a/ec2/roles/kyma_infra/tasks/pre-req.yml b/ec2/roles/kyma_infra/tasks/pre-req.yml new file mode 100644 index 0000000..0f17676 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/pre-req.yml @@ -0,0 +1,77 @@ +--- +- name: Install necessary packages + become: true + ansible.builtin.dnf: + name: "{{ item }}" + state: present + with_items: + - git + - zip + - wget + +# check if java is installed +- name: Check if java is installed + command: "java -version" + register: java_version + ignore_errors: true + +# display output of java -version + +- name: Display java version + debug: var=java_version.stdout_lines + when: java_version.rc != 0 + + +- name: Check if SDKMAN is Installed + command: "which sdk" + register: sdk_check + ignore_errors: true + +- name: Print SDKMAN Installation Status + debug: + msg: "SDKMAN is {{ 'installed' if sdk_check.rc == 0 else 'not installed' }}" + +- name: Download and install SDKMAN + shell: "curl -s 'https://get.sdkman.io' | bash" + args: + creates: "/home/fedora/.sdkman" + when: sdk_check.rc != 0 + +- name: Add SDKMAN initialization to ~/.bashrc + ansible.builtin.lineinfile: + path: "/home/fedora/.bashrc" + line: "source $HOME/.sdkman/bin/sdkman-init.sh" + when: sdk_check.rc != 0 + +- name: Source SDKMAN initialization script and install Java 8.0.392-tem + shell: | + source /home/fedora/.sdkman/bin/sdkman-init.sh + sdk install java 8.0.392-tem + sdk default java 8.0.392-tem + sdk use java 8.0.392-tem + args: + executable: /bin/bash + environment: + HOME: "/home/fedora" + +# check java version +- name: Check if java is installed + command: "java -version" + register: java_version + ignore_errors: true + +# print java version and add a console statement that says sdk instal +- name: Display java version + debug: var=java_version.stdout_lines + +- name: Check if the repository directory exists + ansible.builtin.stat: + path: "/home/fedora/{{ app_name }}" + register: app_repo +# delete java app if the repo exists +- name: Delete the Java EE application if the repo exists + ansible.builtin.file: + path: "/home/fedora/{{ app_name }}" + state: absent + when: app_repo.stat.exists + diff --git a/ec2/roles/kyma_infra/tasks/quarkus-app-deploy.yml b/ec2/roles/kyma_infra/tasks/quarkus-app-deploy.yml new file mode 100644 index 0000000..9776498 --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/quarkus-app-deploy.yml @@ -0,0 +1,78 @@ +--- + +# chdir to /home/fedora/{{app_name}} +- name: chdir to /home/fedora/{{app_name}} + ansible.builtin.shell: cd /home/fedora/{{app_name}} + args: + chdir: /home/fedora/{{app_name}} + when: same_repo == true + + +# checkout quarkus branch and track it - git checkout remotes/origin/quarkus --track +- name: checkout quarkus branch and track it + ansible.builtin.shell: git checkout remotes/origin/{{ quarkus_git_branch }} --track + args: + chdir: /home/fedora/{{ app_name }} + when: same_repo == true + + +- name: Add new Git remote + ansible.builtin.shell: + cmd: "git remote add quarkus {{ git_url_quarkus }}" + chdir: "/home/fedora/{{ app_name }}" + when: same_repo == false + +- name: Checkout branch from remote + ansible.builtin.shell: + cmd: | + git fetch quarkus "+refs/heads/quarkus-3.2:refs/remotes/quarkus/quarkus-3.2" + git checkout -b quarkus-3.2 quarkus/quarkus-3.2 + chdir: "/home/fedora/{{ app_name }}" + when: same_repo == false + + +- name: Check if Docker is accessible using socket + ansible.builtin.wait_for: + path: /var/run/docker.sock + state: present + timeout: 10 + ignore_errors: false + register: docker_socket_status + +- name: Display Docker socket status + ansible.builtin.debug: + var: docker_socket_status + +# display docker version +- name: Display Docker version + ansible.builtin.shell: docker version + register: docker_version + +- name: Display Docker version + ansible.builtin.debug: + var: docker_version.stdout_lines + +# build the quarkus app - mvn clean package +- name: build the quarkus app + ansible.builtin.shell: mvn clean package + args: + chdir: "{{ local_app_path }}" + +# Run the quarkus app locally +- name: Start the server + ansible.builtin.shell: "nohup mvn clean quarkus:dev -Dquarkus.http.port=8085 > server.log 2>&1 & echo $! > server.pid" + args: + chdir: "{{ local_app_path }}" + register: start_server_result + +# check if quarkus process is running using pid +# need a better way to check if quarkus app is running +- name: Check if Quarkus app is running + ansible.builtin.shell: "ps -p $(cat server.pid) | grep -v PID" + args: + chdir: "{{ local_app_path }}" + register: quarkus_app_running + until: quarkus_app_running.stdout != "" + retries: 10 + delay: 5 + diff --git a/ec2/roles/kyma_infra/tasks/quarkus-setup.yml b/ec2/roles/kyma_infra/tasks/quarkus-setup.yml new file mode 100644 index 0000000..e8a138a --- /dev/null +++ b/ec2/roles/kyma_infra/tasks/quarkus-setup.yml @@ -0,0 +1,22 @@ +--- + +- name: Source SDKMAN initialization script and install {{ quarkus_java_version}} + shell: | + source /home/fedora/.sdkman/bin/sdkman-init.sh + sdk install java {{ quarkus_java_version}} + sdk default java {{ quarkus_java_version}} + sdk use java {{ quarkus_java_version}} + sdk install quarkus + args: + executable: /bin/bash + environment: + HOME: "/home/fedora" + +- name: Check Maven version + command: "mvn -v" + register: maven_version + +- name: Display Maven version + debug: + var: maven_version.stdout_lines + diff --git a/ec2/roles/kyma_infra/tests/inventory b/ec2/roles/kyma_infra/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/ec2/roles/kyma_infra/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/ec2/roles/kyma_infra/tests/test.yml b/ec2/roles/kyma_infra/tests/test.yml new file mode 100644 index 0000000..6c5d789 --- /dev/null +++ b/ec2/roles/kyma_infra/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - kyma_infra diff --git a/ec2/roles/kyma_infra/vars/main.yml b/ec2/roles/kyma_infra/vars/main.yml new file mode 100644 index 0000000..f563c1f --- /dev/null +++ b/ec2/roles/kyma_infra/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for kyma_infra diff --git a/ec2/setup_kyma_infra.sh b/ec2/setup_kyma_infra.sh new file mode 100755 index 0000000..6156d67 --- /dev/null +++ b/ec2/setup_kyma_infra.sh @@ -0,0 +1 @@ +ansible-playbook -v -i my_hosts.aws_ec2.yml setup_kyma_infra.yml --extra-vars "@my_vars.yml" \ No newline at end of file diff --git a/ec2/setup_kyma_infra.yml b/ec2/setup_kyma_infra.yml new file mode 100644 index 0000000..5443978 --- /dev/null +++ b/ec2/setup_kyma_infra.yml @@ -0,0 +1,9 @@ +--- + - name: "Run tasks to setup kyma_infra" + hosts: "role_{{ project_tag }}_node" + roles: + # See Role's readme for more info + - role: kyma_infra + # intended to run as 'fedora' user, so no on 'become' + become: no + \ No newline at end of file