From ba5ec1ad561b803d63ba668584ae4b09b566f05e Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Mon, 4 Jan 2021 15:06:10 -0500 Subject: [PATCH] Import --- Dockerfile | 53 ++++++++++++++++++++++++++++++++++++ Jenkinsfile | 44 ++++++++++++++++++++++++++++++ Jenkinsfile-pod-template.yml | 22 +++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 Jenkinsfile-pod-template.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b0a5776 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# The MIT License +# +# Copyright (c) 2021-2021, Cabillot Julien +# Copyright (c) 2015-2020, CloudBees, Inc. and other Jenkins contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +#FROM adoptopenjdk/openjdk11:alpine +FROM alpine:latest + +RUN apk add --no-cache openjdk11-jre-headless + +ARG VERSION=4.6 +ARG user=jenkins +ARG group=jenkins +ARG uid=1000 +ARG gid=1000 + +RUN addgroup -g ${gid} ${group} +RUN adduser -h /home/${user} -u ${uid} -G ${group} -D ${user} +LABEL Description="This is a base image, which provides the Jenkins agent executable (slave.jar)" Vendor="Jenkins project" Version="${VERSION}" + +ARG AGENT_WORKDIR=/home/${user}/agent + +RUN apk add --update --no-cache curl bash git git-lfs openssh-client openssl procps \ + && curl --create-dirs -fsSLo /usr/share/jenkins/agent.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar \ + && chmod 755 /usr/share/jenkins \ + && chmod 644 /usr/share/jenkins/agent.jar \ + && ln -sf /usr/share/jenkins/agent.jar /usr/share/jenkins/slave.jar \ + && apk del curl +USER ${user} +ENV AGENT_WORKDIR=${AGENT_WORKDIR} +RUN mkdir /home/${user}/.jenkins && mkdir -p ${AGENT_WORKDIR} + +VOLUME /home/${user}/.jenkins +VOLUME ${AGENT_WORKDIR} +WORKDIR /home/${user} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..31d69cd --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,44 @@ +pipeline { + environment { + registry = 'https://registry.hub.docker.com' + registryCredential = 'dockerhub_jcabillot' + dockerImage = 'jcabillot/docker-inbound-agent-arm64' + } + + //agent { label 'arm64' } + agent { + kubernetes { + defaultContainer 'docker' // All `steps` instructions will be executed by this container + yamlFile 'Jenkinsfile-pod-template.yml' + } + } + + triggers { + cron('@midnight') + } + + stages { + stage('Clone repository') { + steps{ + checkout scm + } + } + + stage('Build image') { + steps{ + sh 'docker build --force-rm=true --no-cache=true --network host --pull -t ${dockerImage} .' + } + } + + stage('Deploy Image') { + steps{ + script { + withCredentials([usernamePassword(credentialsId: 'dockerhub_jcabillot', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { + sh 'docker login --username ${DOCKER_USER} --password ${DOCKER_PASS}' + sh 'docker push ${dockerImage}' + } + } + } + } + } +} diff --git a/Jenkinsfile-pod-template.yml b/Jenkinsfile-pod-template.yml new file mode 100644 index 0000000..a7cc769 --- /dev/null +++ b/Jenkinsfile-pod-template.yml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Pod +metadata: + labels: + jenkins: 'true' +spec: + containers: + - name: jnlp + image: 'jcabillot/docker-inbound-agent-arm64' + - name: docker + image: docker:20.10-dind + securityContext: + privileged: true + #volumeMounts: + #- mountPath: '/var/run/docker.sock' + # name: docker-socket + #volumes: + #- name: docker-socket + # hostPath: + # path: '/var/run/docker.sock' + securityContext: + runAsUser: 0