diff --git a/Dockerfile b/Dockerfile index 250aaff1..117fe653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM openjdk:8 +FROM alpine:3.17.2 EXPOSE 8080 +ENV USERNAME=Devsecops +ENV PASSWORD=Test@123i4 +ENV ApiKey=zaCELgL. 0imfnc8mVLWwsAawjYr4Rx-Af50DDqtlx ADD target/devops-integration.jar devops-integration.jar -ENTRYPOINT ["java","-jar","/devops-integration.jar"] \ No newline at end of file +ENTRYPOINT ["java","-jar","/devops-integration.jar"] diff --git a/Dockerfile images b/Dockerfile images new file mode 100644 index 00000000..d088139e --- /dev/null +++ b/Dockerfile images @@ -0,0 +1,23 @@ +FROM docker.io/jenkins/inbound-agent:4.10-3 +USER root +RUN apt-get update && apt-get install -y \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg2 \ + lsb-release \ + software-properties-common +RUN mkdir -m 0755 -p /etc/apt/keyrings +RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +RUN echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update +RUN apt-get install -y docker-ce-cli docker-ce containerd.io docker-compose-plugin +RUN apt update -y +RUN apt install podman -y +RUN chmod u-s /usr/bin/new[gu]idmap +RUN setcap cap_setuid+eip /usr/bin/newuidmap +RUN setcap cap_setgid+eip /usr/bin/newgidmap + +USER jenkins diff --git a/Jenkins dependency b/Jenkins dependency new file mode 100644 index 00000000..dcfe6882 --- /dev/null +++ b/Jenkins dependency @@ -0,0 +1,46 @@ +pipeline { + agent { + kubernetes { + yaml ''' + apiVersion: v1 + kind: Pod + spec: + containers: + - name: maven + image: maven:alpine + command: + - cat + tty: true + - name: docker + image: docker:latest + command: + - cat + tty: true + volumeMounts: + - mountPath: /var/run/docker.sock + name: docker-sock + volumes: + - name: docker-sock + hostPath: + path: /var/run/docker.sock + ''' + } + } + stages { + stage('maven') { + steps { + container('maven') { + checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/sanjeeveejayabalan/devops-automation.git']]) + sh 'mvn org.cyclonedx:cyclonedx-maven-plugin:makeBom' + } + } + } + stage('dependencyTrackPublisher') { + steps { + withCredentials([string(credentialsId: 'dependencytrackapikey', variable: 'dependencytrackapikey')]) { + dependencyTrackPublisher artifact: 'target/bom.xml', projectName: 'dptrack3', projectVersion: '1.3', synchronous: true, projectProperties: [tags: ['10', '20'], swidTagId: 'my swid tag', group: 'dptrack3'] + } + } + } + } +} diff --git a/Jenkinsfile b/Jenkinsfile index ae953c63..8b137891 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,39 +1 @@ -pipeline { - agent any - tools{ - maven 'maven_3_5_0' - } - stages{ - stage('Build Maven'){ - steps{ - checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/Java-Techie-jt/devops-automation']]]) - sh 'mvn clean install' - } - } - stage('Build docker image'){ - steps{ - script{ - sh 'docker build -t javatechie/devops-integration .' - } - } - } - stage('Push image to Hub'){ - steps{ - script{ - withCredentials([string(credentialsId: 'dockerhub-pwd', variable: 'dockerhubpwd')]) { - sh 'docker login -u javatechie -p ${dockerhubpwd}' -} - sh 'docker push javatechie/devops-integration' - } - } - } - stage('Deploy to k8s'){ - steps{ - script{ - kubernetesDeploy (configs: 'deploymentservice.yaml',kubeconfigId: 'k8sconfigpwd') - } - } - } - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3512c335..822229d6 100644 --- a/pom.xml +++ b/pom.xml @@ -56,8 +56,14 @@ pl.project13.maven git-commit-id-plugin + + org.cyclonedx + cyclonedx-maven-plugin + 2.7.3 + devops-integration +