From 42df3d0083320ef20cb480bb2e26bf3125b4dbae Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 14:16:18 -0400 Subject: [PATCH 01/12] first Signed-off-by: Darin Pope --- Jenkinsfile | 29 ++----------------- .../com/example/demo/DemoApplication.java | 8 ++--- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83f8074..74faa83 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,38 +1,15 @@ pipeline { - agent { label 'linux' } + agent { label 'macos' } options { buildDiscarder(logRotator(numToKeepStr: '5')) } environment { - HEROKU_API_KEY = credentials('darinpope-heroku-api-key') - } - parameters { - string(name: 'APP_NAME', defaultValue: '', description: 'What is the Heroku app name?') + DOCKER_HUB_CREDS = credentials('darinpope-docker-hub') } stages { - stage('Build') { - steps { - sh 'docker build -t darinpope/java-web-app:latest .' - } - } stage('Login') { steps { - sh 'echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com' - } - } - stage('Push to Heroku registry') { - steps { - sh ''' - docker tag darinpope/java-web-app:latest registry.heroku.com/$APP_NAME/web - docker push registry.heroku.com/$APP_NAME/web - ''' - } - } - stage('Release the image') { - steps { - sh ''' - heroku container:release web --app=$APP_NAME - ''' + sh 'echo $DOCKER_HUB_CREDS_PSW | docker login --username=$DOCKER_HUB_CREDS_USR --password-stdin' } } } diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 761a793..2b03067 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -9,12 +9,12 @@ @RestController public class DemoApplication { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } @RequestMapping("/") public String home() { - return "Hello Docker World!"; + return "Hello World!"; } } From 14804894f60f8db99f4961b26e247440e7de070f Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 15:56:51 -0400 Subject: [PATCH 02/12] next Signed-off-by: Darin Pope --- .env | 1 + Dockerfile | 5 ++++- compose.yaml | 8 ++++++++ src/main/resources/application.properties | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 compose.yaml diff --git a/.env b/.env new file mode 100644 index 0000000..c88bfa8 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PORT=8080 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fe398b8..3483db4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ FROM adoptopenjdk/openjdk11:alpine-slim as build WORKDIR /workspace/app +ARG PORT +ENV PORT ${PORT} + COPY mvnw . COPY .mvn .mvn COPY pom.xml . @@ -15,4 +18,4 @@ ARG DEPENDENCY=/workspace/app/target/dependency COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app -ENTRYPOINT ["java","-Dserver.port=${PORT}","-cp","app:app/lib/*","com.example.demo.DemoApplication"] \ No newline at end of file +ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.demo.DemoApplication"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..53ae318 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,8 @@ +x-aws-vpc: "vpc-0dece3d7dce2d0578" +services: + web: + image: darinpope/java-web-app:latest + build: + context: . + ports: + - "8080:8080" \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..4c00e40 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +server.port=8080 From 29a5ea91e8d913b3b430795b14d2323efddca2cc Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 16:02:31 -0400 Subject: [PATCH 03/12] more Signed-off-by: Darin Pope --- Jenkinsfile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 74faa83..aefaec0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,17 +5,13 @@ pipeline { } environment { DOCKER_HUB_CREDS = credentials('darinpope-docker-hub') + AWS_CREDS = credentials('darinpope-aws-creds') } stages { - stage('Login') { + stage('Select context') { steps { - sh 'echo $DOCKER_HUB_CREDS_PSW | docker login --username=$DOCKER_HUB_CREDS_USR --password-stdin' + sh 'docker context use darinpope-ecs-context' } } } - post { - always { - sh 'docker logout' - } - } } \ No newline at end of file From a75911af240586306c398e7047a3a2c041756f5f Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 16:09:36 -0400 Subject: [PATCH 04/12] update Signed-off-by: Darin Pope --- Jenkinsfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index aefaec0..412afe8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,9 +8,18 @@ pipeline { AWS_CREDS = credentials('darinpope-aws-creds') } stages { - stage('Select context') { + stage('Build') { + steps { + sh 'docker context use default' + sh 'docker compose build' + sh 'docker compose push' + } + } + stage('Deploy') { steps { sh 'docker context use darinpope-ecs-context' + sh 'docker compose up' + sh 'docker compose ps --format json' } } } From 5289936fc9195f2bda7c176eb846c21b349916e0 Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 18:24:18 -0400 Subject: [PATCH 05/12] keychain Signed-off-by: Darin Pope --- Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 412afe8..7bf54e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,6 +8,11 @@ pipeline { AWS_CREDS = credentials('darinpope-aws-creds') } stages { + stage('Unlock keychain') { + steps { + sh 'security -v unlock-keychain ~/Library/Keychains/login.keychain-db' + } + } stage('Build') { steps { sh 'docker context use default' @@ -23,4 +28,9 @@ pipeline { } } } + post { + always { + sh 'security -v lock-keychain ~/Library/Keychains/login.keychain-db' + } + } } \ No newline at end of file From 328cb201ffc1e6a78253e7ec97721014d9b74896 Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 19:01:54 -0400 Subject: [PATCH 06/12] ignore password Signed-off-by: Darin Pope --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7bf54e7..c23b7c6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { stages { stage('Unlock keychain') { steps { - sh 'security -v unlock-keychain ~/Library/Keychains/login.keychain-db' + sh 'security -v unlock-keychain -u ~/Library/Keychains/login.keychain-db' } } stage('Build') { From 4bed6e74ed41d0a5fc9851a6ecd644b04f234f6d Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 19:04:25 -0400 Subject: [PATCH 07/12] try password Signed-off-by: Darin Pope --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c23b7c6..33fc625 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,11 +6,12 @@ pipeline { environment { DOCKER_HUB_CREDS = credentials('darinpope-docker-hub') AWS_CREDS = credentials('darinpope-aws-creds') + KEYCHAIN_PASSWORD = credentials('darinpope-keychain') } stages { stage('Unlock keychain') { steps { - sh 'security -v unlock-keychain -u ~/Library/Keychains/login.keychain-db' + sh 'security -v unlock-keychain -p $KEYCHAIN_PASSWORD ~/Library/Keychains/login.keychain-db' } } stage('Build') { From cc951f04c29451511d84b8e7e7e8940da1e82778 Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 19:35:52 -0400 Subject: [PATCH 08/12] add checkout Signed-off-by: Darin Pope --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 33fc625..bc83b21 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,11 @@ pipeline { KEYCHAIN_PASSWORD = credentials('darinpope-keychain') } stages { + stage('Checkout') { + steps { + git branch: 'docker-compose', url: 'https://github.com/darinpope/java-web-app.git' + } + } stage('Unlock keychain') { steps { sh 'security -v unlock-keychain -p $KEYCHAIN_PASSWORD ~/Library/Keychains/login.keychain-db' From 8d55609b2d3ad8a0e749ecd5e1d93269b94210cd Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 19:44:49 -0400 Subject: [PATCH 09/12] 2 Signed-off-by: Darin Pope --- src/main/java/com/example/demo/DemoApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 2b03067..612f067 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -15,6 +15,6 @@ public static void main(String[] args) { @RequestMapping("/") public String home() { - return "Hello World!"; + return "Hello World 2!"; } } From 539ef8711b46ed52f1d6b3ad9f27ae415a7583de Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Mon, 14 Jun 2021 20:34:36 -0400 Subject: [PATCH 10/12] hello Signed-off-by: Darin Pope --- src/main/java/com/example/demo/DemoApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 612f067..2b03067 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -15,6 +15,6 @@ public static void main(String[] args) { @RequestMapping("/") public String home() { - return "Hello World 2!"; + return "Hello World!"; } } From c5c0ffd36affb44c73c629fbebb7b01c739a3464 Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Thu, 17 Jun 2021 10:23:34 -0400 Subject: [PATCH 11/12] cleanup Signed-off-by: Darin Pope --- Jenkinsfile-1 | 16 ++++++++++++++++ Jenkinsfile => Jenkinsfile-2 | 7 +++++-- compose.yaml | 1 - 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Jenkinsfile-1 rename Jenkinsfile => Jenkinsfile-2 (88%) diff --git a/Jenkinsfile-1 b/Jenkinsfile-1 new file mode 100644 index 0000000..bfcdc39 --- /dev/null +++ b/Jenkinsfile-1 @@ -0,0 +1,16 @@ +pipeline { + agent { label 'macos' } + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + stages { + stage('Tooling versions') { + steps { + sh ''' + docker --version + docker compose version + ''' + } + } + } +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile-2 similarity index 88% rename from Jenkinsfile rename to Jenkinsfile-2 index bc83b21..32fd7b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile-2 @@ -9,9 +9,12 @@ pipeline { KEYCHAIN_PASSWORD = credentials('darinpope-keychain') } stages { - stage('Checkout') { + stage('Tooling versions') { steps { - git branch: 'docker-compose', url: 'https://github.com/darinpope/java-web-app.git' + sh ''' + docker --version + docker compose version + ''' } } stage('Unlock keychain') { diff --git a/compose.yaml b/compose.yaml index 53ae318..6ca6e22 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,4 +1,3 @@ -x-aws-vpc: "vpc-0dece3d7dce2d0578" services: web: image: darinpope/java-web-app:latest From 4a008a16e86b5d865c70a5385f070c239e1e70ae Mon Sep 17 00:00:00 2001 From: Darin Pope Date: Thu, 17 Jun 2021 13:52:13 -0400 Subject: [PATCH 12/12] fix --- Jenkinsfile-2 | 4 ++-- compose.yaml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile-2 b/Jenkinsfile-2 index 32fd7b8..c3b363c 100644 --- a/Jenkinsfile-2 +++ b/Jenkinsfile-2 @@ -31,7 +31,7 @@ pipeline { } stage('Deploy') { steps { - sh 'docker context use darinpope-ecs-context' + sh 'docker context use myecscontext' sh 'docker compose up' sh 'docker compose ps --format json' } @@ -42,4 +42,4 @@ pipeline { sh 'security -v lock-keychain ~/Library/Keychains/login.keychain-db' } } -} \ No newline at end of file +} diff --git a/compose.yaml b/compose.yaml index 6ca6e22..04e4da5 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,7 +1,8 @@ +x-aws-vpc: "vpc-0dece3d7dce2d0578" services: web: image: darinpope/java-web-app:latest build: context: . ports: - - "8080:8080" \ No newline at end of file + - "8080:8080"