Skip to content

Commit 994a36a

Browse files
committed
Merge branch 'main' of https://github.com/newrelic/open-install-library into pchinthapenta-NR-191162
2 parents 2da0651 + c4c2e33 commit 994a36a

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
- debug:
3+
msg: Install Java, Create Dockerfile, and setup Java application
4+
5+
# create a directory to host java application and newrelic
6+
- name: Create myJavaApp directory
7+
file:
8+
path: "/home/{{ ansible_user }}/myJavaApp"
9+
state: directory
10+
11+
# create a sample Dockerfile
12+
- name: Create a sample Dockerfile
13+
copy:
14+
content: |
15+
FROM openjdk:8
16+
WORKDIR /app
17+
COPY . /app
18+
EXPOSE 80
19+
CMD ["java", "Main"]
20+
dest: "/home/{{ ansible_user }}/myJavaApp/Dockerfile"
21+
mode: "0644"
22+
when: ansible_os_family == 'RedHat'
23+
24+
- name: Install Java
25+
yum:
26+
name: java-1.8.0-openjdk-devel
27+
state: present
28+
become: yes
29+
when: ansible_os_family == 'RedHat'
30+
31+
# create a java app
32+
- name: Create sample Java application
33+
copy:
34+
content: |
35+
public class Main {
36+
public static void main(String[] args) {
37+
// define the number of iterations for the loop
38+
int iterations = 500;
39+
40+
// loop to print "Hello, Java!" multiple times with a delay
41+
for (int i = 0; i < iterations; i++) {
42+
System.out.println("Hello, Java!");
43+
44+
// Delay for 5 secsonds (5000 ms)
45+
try {
46+
Thread.sleep(5000);
47+
} catch (InterruptedException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
}
52+
}
53+
dest: "/home/{{ ansible_user }}/myJavaApp/Main.java"
54+
mode: 0644
55+
56+
# compile java file
57+
- name: compile java code
58+
shell: javac Main.java
59+
args:
60+
chdir: "/home/{{ ansible_user }}/myJavaApp"
61+
62+
# create Manifest
63+
- name: Create Manifest.txt file
64+
copy:
65+
content: |
66+
Main-Class: Main
67+
dest: "/home/{{ ansible_user }}/myJavaApp/Manifest.txt"
68+
69+
# create jar file for the Java app
70+
- name: Create JAR file
71+
command: jar cfm Main.jar Manifest.txt Main.class
72+
args:
73+
chdir: "/home/{{ ansible_user }}/myJavaApp"
74+
75+
# Give all permissions to the jar file
76+
- name: Change permissions for the JAR file
77+
file:
78+
path: "/home/{{ ansible_user }}/myJavaApp/Main.jar"
79+
mode: "0777" # Adjust the permissions as needed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"global_tags": {
3+
"owning_team": "virtuoso",
4+
"Environment": "development",
5+
"Department": "product",
6+
"Product": "virtuoso"
7+
},
8+
"resources": [
9+
{
10+
"id": "linux2",
11+
"provider": "aws",
12+
"type": "ec2",
13+
"size": "t3.micro",
14+
"ami_name": "amzn2-ami-hvm-2.0.????????.?-x86_64-gp2",
15+
"user_name": "ec2-user"
16+
}
17+
],
18+
"services": [
19+
{
20+
"id": "docker",
21+
"source_repository": "https://github.com/newrelic/open-install-library.git",
22+
"deploy_script_path": "test/deploy/linux/docker/install/roles",
23+
"port": 9999,
24+
"destinations": ["linux2"]
25+
},
26+
{
27+
"id": "java",
28+
"source_repository": "https://github.com/newrelic/open-install-library.git",
29+
"deploy_script_path": "test/deploy/linux/java/docker-flow/roles",
30+
"port": 80,
31+
"destinations": ["linux2"]
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)