Skip to content

Instantly share code, notes, and snippets.

@olivx
Last active June 11, 2019 16:59
Show Gist options
  • Save olivx/f589409a92c1644f367e4d7c60cc679a to your computer and use it in GitHub Desktop.
Save olivx/f589409a92c1644f367e4d7c60cc679a to your computer and use it in GitHub Desktop.
jenkinsfile exemplos
FROM python:3.7.3-slim-stretch
WORKDIR /app
COPY Pipfile* ./
RUN apt-get update -y && apt-get install git -y && apt-get clean -y
RUN pip install pipenv
RUN pipenv install --system --deploy
COPY . /app
RUN groupadd -g 999 appuser && \
useradd -r -u 999 -g appuser appuser
RUN chown -R appuser:appuser ./conf
RUN chmod 755 ./conf
USER appuser
ENTRYPOINT ["python", "-m"]
CMD [ "kafka_producer_nimsoft.main" ]
FROM python:3.7.3-slim-stretch
WORKDIR /app
COPY Pipfile* ./
RUN apt-get update -y && apt-get install git make -y && apt-get clean -y
RUN pip install pipenv
RUN pipenv install --system --deploy --dev
COPY . /app
ENTRYPOINT ["python", "-m"]
pipeline {
agent any
environment {
DOCKER_REGISTRY_URL = 'localhost:5000'
IMAGE_BASE_NAME = 'kafka-producer-nimsoft'
DEPLOYMENT_NAME = 'kafka-producer-nimsoft'
NAMESPACE = 'default'
}
stages {
stage('test') {
steps {
sh 'docker build -t DOCKER_REGISTRY_URL/$IMAGE_BASE_NAME:$GIT_COMMIT'
sh 'docker-compose run --entrypoint make nimsoft-agent test'
}
post{
always{
cobertura coberturaReportFile: 'coverage.xml',
conditionalCoverageTargets: '80, 0, 0',
enableNewApi: false,
lineCoverageTargets: '90, 0, 0',
maxNumberOfBuilds: 10,
methodCoverageTargets: '90, 0, 0',
sourceEncoding: 'ASCII',
zoomCoverageChart: false
junit 'junit.xml'
}
}
}
stage('build'){
steps {
sh 'docker build -t $DOCKER_REGISTRY_URL/$IMAGE_BASE_NAME:$GIT_COMMIT .'
sh 'docker push $DOCKER_REGISTRY_URL/$IMAGE_BASE_NAME:$GIT_COMMIT'
}
}
stage('deploy-stagging'){
when {
branch 'stagging'
}
steps {
sh 'kubectl --record deployment.apps/$DEPLOYMENT_NAME \
set image deployment.v1.apps/$DEPLOYMENT_NAME \
kafka-consumer-bigpanda=$DOCKER_REGISTRY_URL/$IMAGE_BASE_NAME:$GIT_COMMIT -n $NAMESPACE'
}
}
}
post {
always {
office365ConnectorSend message: "New pipeline run for branch project - ${env.IMAGE_BASE_NAME} - branch ${env.BRANCH_NAME}",
status:"${currentBuild.currentResult}",
webhookUrl:'https://outlook.office.com/webhook/860cd5c1-6d35-433a-987b-76f8938d06ae@68f06401-3da9-4972-96e1-bd5e2bf1d646/JenkinsCI/1ad19474f48e41c09be40265e3f7cbdb/1f89debb-d369-4dbc-9ce0-94d375b9d701'
}
}
}
podTemplate(
label: 'questcode',
name: 'questcode',
namespace: 'devops',
containers: [
containerTemplate(
args: 'cat',
command: '/bin/sh -c',
image: 'lachlanevenson/k8s-helm:v2.11.0',
name: 'helm-container',
ttyEnabled: true
),
containerTemplate(
alwaysPullImage: false,
args: 'cat',
command: '/bin/sh -c',
envVars: [],
image: 'docker',
livenessProbe: containerLivenessProbe(
execArgs: '',
failureThreshold: 0,
initialDelaySeconds: 0,
periodSeconds: 0,
successThreshold: 0,
timeoutSeconds: 0
),
name: 'docker-container',
ports: [],
privileged: false,
resourceLimitCpu: '',
resourceLimitMemory: '',
resourceRequestCpu: '',
resourceRequestMemory: '',
shell: null,
ttyEnabled: true,
workingDir: '/home/jenkins'
)
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')
],
){
// start pipeline
node('questcode') {
def REPOPS
def IMAGE_TAG
def IMAGE = 'olvx/questcode-frontend'
def ENVIRONMENT = 'staging'
def CHART_MUSEUM_URL = 'http://helm-chartmuseum:8080'
def GITLAB_URL = '[email protected]:olivx-questcode/frontend.git'
stage('Build') {
echo 'Iniciando Build'
repos = git credentialsId: 'id_gitlab', url: GITLAB_URL
IMAGE_TAG = sh returnStdout: true, script: 'sh read-package-version.sh'
IMAGE_TAG = IMAGE_TAG.trim()
}
stage('Package'){
// docker tag end push
echo 'Inicinado Package'
container('docker-container'){
withCredentials([usernamePassword(
credentialsId: 'id_dockerhube',
passwordVariable: 'DOCKER_HUB_PASSWORD',
usernameVariable: 'DOCKER_HUB_USER')]) {
sh "docker login -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD}"
sh "docker build -t ${IMAGE}:${IMAGE_TAG} . --build-arg NPM_ENV=${ENVIRONMENT}"
sh "docker push ${IMAGE}:${IMAGE_TAG}"
}
}
sh 'ls -ltra'
}
stage('Deploy'){
// deploy via helm
echo 'Iniciando Deploy com heml'
container('helm-container'){
sh """
helm init --client-only
helm repo add questcode ${CHART_MUSEUM_URL}
helm search questcode
helm repo update
helm upgrade staging-frontend questcode/frontend --set image.tag=${IMAGE_TAG}
"""
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment