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/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 83f8074..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,44 +0,0 @@ -pipeline { - agent { label 'linux' } - 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?') - } - 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 - ''' - } - } - } - post { - always { - sh 'docker logout' - } - } -} \ No newline at end of file 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-2 b/Jenkinsfile-2 new file mode 100644 index 0000000..c3b363c --- /dev/null +++ b/Jenkinsfile-2 @@ -0,0 +1,45 @@ +pipeline { + agent { label 'macos' } + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + environment { + DOCKER_HUB_CREDS = credentials('darinpope-docker-hub') + AWS_CREDS = credentials('darinpope-aws-creds') + KEYCHAIN_PASSWORD = credentials('darinpope-keychain') + } + stages { + stage('Tooling versions') { + steps { + sh ''' + docker --version + docker compose version + ''' + } + } + stage('Unlock keychain') { + steps { + sh 'security -v unlock-keychain -p $KEYCHAIN_PASSWORD ~/Library/Keychains/login.keychain-db' + } + } + stage('Build') { + steps { + sh 'docker context use default' + sh 'docker compose build' + sh 'docker compose push' + } + } + stage('Deploy') { + steps { + sh 'docker context use myecscontext' + sh 'docker compose up' + sh 'docker compose ps --format json' + } + } + } + post { + always { + sh 'security -v lock-keychain ~/Library/Keychains/login.keychain-db' + } + } +} diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..04e4da5 --- /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" 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!"; } } 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