From fbdd9358bfab5e925854483a9de6a6d07d52de5c Mon Sep 17 00:00:00 2001 From: Dan Butuc Date: Tue, 4 Feb 2025 08:52:38 +0100 Subject: [PATCH 1/8] add docker-compose config --- .idea/.gitignore | 8 ++++++++ .idea/compiler.xml | 13 +++++++++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/misc.xml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ JMA/.gitignore | 29 +++++++++++++++++++++++++++++ JMA/.idea/.gitignore | 8 ++++++++ JMA/.idea/misc.xml | 6 ++++++ JMA/.idea/modules.xml | 8 ++++++++ JMA/.idea/vcs.xml | 6 ++++++ JMA/JMA.iml | 11 +++++++++++ JMA/src/Main.java | 5 +++++ Jenkinsfile | 6 ++++++ docker-compose.yaml | 11 +++++++++++ 14 files changed, 149 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 JMA/.gitignore create mode 100644 JMA/.idea/.gitignore create mode 100644 JMA/.idea/misc.xml create mode 100644 JMA/.idea/modules.xml create mode 100644 JMA/.idea/vcs.xml create mode 100644 JMA/JMA.iml create mode 100644 JMA/src/Main.java create mode 100644 docker-compose.yaml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9fc9174 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f24c79d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/JMA/.gitignore b/JMA/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/JMA/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/JMA/.idea/.gitignore b/JMA/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/JMA/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/JMA/.idea/misc.xml b/JMA/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/JMA/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/JMA/.idea/modules.xml b/JMA/.idea/modules.xml new file mode 100644 index 0000000..055a9cb --- /dev/null +++ b/JMA/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/JMA/.idea/vcs.xml b/JMA/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/JMA/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/JMA/JMA.iml b/JMA/JMA.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/JMA/JMA.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/JMA/src/Main.java b/JMA/src/Main.java new file mode 100644 index 0000000..d5238c9 --- /dev/null +++ b/JMA/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index e99c162..2162b02 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -52,6 +52,12 @@ pipeline { steps { script { echo "deploying" + def dockerComposeCmd = "docker-compose -f docker-compose.yaml up --detach" + + sshagent(['ec2-private-key']) { + sh "scp docker-compose.yaml ec2-user@34.244.129.21:/home/ec2-user" + sh "ssh -o StrictHostKeyChecking=no ec2-user@34.244.129.21 ${dockerComposeCmd}" + } // gv.deployApp() } } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..8d3f3b9 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3.8' +services: + java-maven-app: danbutuc2/java-maven-app-master:1.0 + ports: + - 8080:8080 + postgres: + image: postgres:15 + ports: + - 5432:5432 + environment: + - POSTGRES_PASSWORD=my-pwd \ No newline at end of file From ef61b7e68f7669c57ace60e6dde1e755c0851574 Mon Sep 17 00:00:00 2001 From: Dan Butuc <146419517+danbutuc2@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:05:36 +0100 Subject: [PATCH 2/8] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1016f28..7dc5a5b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,7 +55,7 @@ pipeline { script { echo "deploying" - def dockerComposeCmd = "docker-compose -f docker-compose.yaml up --detach" + def dockerComposeCmd = "docker compose -f docker-compose.yaml up --detach" sshagent(['ec2-private-key']) { sh "scp docker-compose.yaml ec2-user@34.244.129.21:/home/ec2-user" From d6e457b3ae9bf5c3e2e1b635d5be5aecdb7f2e72 Mon Sep 17 00:00:00 2001 From: Dan Butuc <146419517+danbutuc2@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:07:21 +0100 Subject: [PATCH 3/8] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7dc5a5b..1016f28 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,7 +55,7 @@ pipeline { script { echo "deploying" - def dockerComposeCmd = "docker compose -f docker-compose.yaml up --detach" + def dockerComposeCmd = "docker-compose -f docker-compose.yaml up --detach" sshagent(['ec2-private-key']) { sh "scp docker-compose.yaml ec2-user@34.244.129.21:/home/ec2-user" From 3fc09ef062f71feacc94f3a5f1a8c013007298c7 Mon Sep 17 00:00:00 2001 From: Dan Butuc <146419517+danbutuc2@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:21:08 +0100 Subject: [PATCH 4/8] Update docker-compose.yaml --- docker-compose.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 8d3f3b9..7990c79 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,11 +1,13 @@ version: '3.8' services: - java-maven-app: danbutuc2/java-maven-app-master:1.0 - ports: - - 8080:8080 + java-maven-app: + image: danbutuc2/java-maven-app-master:1.0 # Add "image" key + ports: + - "8080:8080" + postgres: image: postgres:15 ports: - - 5432:5432 + - "5432:5432" environment: - - POSTGRES_PASSWORD=my-pwd \ No newline at end of file + - POSTGRES_PASSWORD=my-pwd From c08a8f594931c2fb73ed81f7199d44a1ddcffc29 Mon Sep 17 00:00:00 2001 From: Dan Butuc <146419517+danbutuc2@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:27:26 +0100 Subject: [PATCH 5/8] Update docker-compose.yaml --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 7990c79..f71d06a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.8' services: java-maven-app: - image: danbutuc2/java-maven-app-master:1.0 # Add "image" key + image: danbutuc/demo-app:1.0 # Add "image" key ports: - "8080:8080" From c80f01a237fc20b3575a51bbb176a7966b0c1cfa Mon Sep 17 00:00:00 2001 From: Dan Butuc Date: Tue, 4 Feb 2025 09:44:45 +0100 Subject: [PATCH 6/8] Addes the servers-cmds.sh bash script --- Jenkinsfile | 5 +++-- server-cmds.sh | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 server-cmds.sh diff --git a/Jenkinsfile b/Jenkinsfile index 1016f28..7da60d8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,11 +55,12 @@ pipeline { script { echo "deploying" - def dockerComposeCmd = "docker-compose -f docker-compose.yaml up --detach" + def shellCmd = "bash ./server-cmds.sh" sshagent(['ec2-private-key']) { + sh "scp server-cmds.sh c2-user@34.244.129.21:/home/ec2-user" sh "scp docker-compose.yaml ec2-user@34.244.129.21:/home/ec2-user" - sh "ssh -o StrictHostKeyChecking=no ec2-user@34.244.129.21 ${dockerComposeCmd}" + sh "ssh -o StrictHostKeyChecking=no ec2-user@34.244.129.21 ${shellCmd}" } // gv.deployApp() diff --git a/server-cmds.sh b/server-cmds.sh new file mode 100644 index 0000000..9369e66 --- /dev/null +++ b/server-cmds.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +docker-compose -f docker-compose.yaml up --detach +echo "success" \ No newline at end of file From f8304cfbeb92f65547330ef2900f94e9bb1a8799 Mon Sep 17 00:00:00 2001 From: Dan Butuc Date: Tue, 4 Feb 2025 09:47:40 +0100 Subject: [PATCH 7/8] updating the servers-cmds.sh --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7da60d8..cbe4837 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { def shellCmd = "bash ./server-cmds.sh" sshagent(['ec2-private-key']) { - sh "scp server-cmds.sh c2-user@34.244.129.21:/home/ec2-user" + sh "scp server-cmds.sh ec2-user@34.244.129.21:/home/ec2-user" sh "scp docker-compose.yaml ec2-user@34.244.129.21:/home/ec2-user" sh "ssh -o StrictHostKeyChecking=no ec2-user@34.244.129.21 ${shellCmd}" } From 7c17063f8c80fe54eeecd74130d261a83f7f68c2 Mon Sep 17 00:00:00 2001 From: Dan Butuc Date: Tue, 4 Feb 2025 09:59:07 +0100 Subject: [PATCH 8/8] add changes --- Jenkinsfile | 5 ++++- docker-compose.yaml | 2 +- server-cmds.sh | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cbe4837..5d9f22a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,6 +5,9 @@ pipeline { tools { maven 'Maven=3.9.9' } + environment { + IMAGE_NAME = "danbutuc/demo-app:1.0" + } stages { stage("init") { steps { @@ -55,7 +58,7 @@ pipeline { script { echo "deploying" - def shellCmd = "bash ./server-cmds.sh" + def shellCmd = "bash ./server-cmds.sh ${IMAGE_NAME}" sshagent(['ec2-private-key']) { sh "scp server-cmds.sh ec2-user@34.244.129.21:/home/ec2-user" diff --git a/docker-compose.yaml b/docker-compose.yaml index f71d06a..9e0bd41 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.8' services: java-maven-app: - image: danbutuc/demo-app:1.0 # Add "image" key + image: ${IMAGE} ports: - "8080:8080" diff --git a/server-cmds.sh b/server-cmds.sh index 9369e66..6d31f42 100644 --- a/server-cmds.sh +++ b/server-cmds.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +export IMAGE=$1 docker-compose -f docker-compose.yaml up --detach echo "success" \ No newline at end of file