diff --git a/Dockerfile b/Dockerfile index 0966445..9b3271b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,26 @@ -FROM maven:amazoncorretto as build -WORKDIR /javaapp -COPY . . -RUN mvn clean install +# Stage 1: Build Jenkins +FROM ubuntu:latest AS jenkins-build +RUN apt-get update && \ + apt-get install -y openjdk-8-jdk wget gnupg2 && \ + wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | apt-key add - && \ + echo "deb https://pkg.jenkins.io/debian-stable binary/" >> /etc/apt/sources.list && \ + apt-get update && \ + apt-get install -y jenkins && \ + rm -rf /var/lib/apt/lists/* -FROM adhig93/tomcat-conf -COPY --from=build /javaapp/target/*.war /usr/local/tomcat/webapps/ +# Stage 2: Build Apache2 +FROM ubuntu:latest AS apache2-build +RUN apt-get update && \ + apt-get install -y apache2 && \ + rm -rf /var/lib/apt/lists/* + +# Stage 3: Create final image with Jenkins and Apache2 +FROM ubuntu:latest +COPY --from=jenkins-build /usr/share/jenkins /usr/share/jenkins +COPY --from=apache2-build /usr/sbin/apache2 /usr/sbin/apache2 +COPY --from=apache2-build /etc/apache2 /etc/apache2 +RUN apt-get update && \ + apt-get install -y openjdk-8-jdk && \ + rm -rf /var/lib/apt/lists/* +CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] +EXPOSE 80 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0dd89c0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,38 @@ +pipeline{ + agent { + label 'docker123' +} +environment { + DOCKER_LOGIN_CREDENTIALS=credentials('sachink0912') + } + stages { + stage('checkout') { + steps { + echo "checkout stage" + } + } + + stage('build') { + steps { + + sh 'docker build -t sachink0912/ubuntu:$BUILD_NUMBER .' + + } + } + + stage('push') { + steps { + sh 'echo $DOCKER_LOGIN_CREDENTIALS_PSW | docker login -u $DOCKER_LOGIN_CREDENTIALS_USR --password-stdin' + sh 'docker push sachink0912/ubuntu:$BUILD_NUMBER' + } + } + + stage('deploy') { + steps { + sh "docker run -itd -p 80:8080 sachink0912/ubuntu:$BUILD_NUMBER" + } + } + +} + +} diff --git a/test b/test index eb58ad5..0bac255 100644 --- a/test +++ b/test @@ -1 +1,2 @@ Checking POLL SCM +Checking server