Skip to content

Eazylabs #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
122 changes: 122 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
pipeline {
environment {
ID_DOCKER = "${ID_DOCKER_PARAMS}"
IMAGE_NAME = "alpinehelloworld"
IMAGE_TAG = "latest"
// PORT_EXPOSED = "80" à paraméter dans le job obligatoirement
APP_NAME = "kamsu"
STG_API_ENDPOINT = "ip10-0-3-3-cku0bn8db1j0qechj98g-1993.direct.docker.labs.eazytraining.fr"
STG_APP_ENDPOINT = "ip10-0-3-3-cku0bn8db1j0qechj98g-80.direct.docker.labs.eazytraining.fr"
PROD_API_ENDPOINT = "ip10-0-1-3-cktdtr0db1j0qechj730-1993.direct.docker.labs.eazytraining.fr"
PROD_APP_ENDPOINT = "ip10-0-1-3-cktdtr0db1j0qechj730-80.direct.docker.labs.eazytraining.fr"
INTERNAL_PORT = "5000"
EXTERNAL_PORT = "${PORT_EXPOSED}"
CONTAINER_IMAGE = "${ID_DOCKER}/${IMAGE_NAME}:${IMAGE_TAG}"

}
agent none
stages {
stage('Build image') {
agent any
steps {
script {
sh 'docker build -t ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG .'
}
}
}
stage('Run container based on builded image') {
agent any
steps {
script {
sh '''
echo "Clean Environment"
docker rm -f $IMAGE_NAME || echo "container does not exist"
docker run --name $IMAGE_NAME -d -p ${PORT_EXPOSED}:${INTERNAL_PORT} -e PORT=${INTERNAL_PORT} ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG
sleep 5
'''
}
}
}
stage('Test image') {
agent any
steps {
script {
sh '''
curl http://172.17.0.1:${PORT_EXPOSED} | grep -q "Hello world!"
'''
}
}
}
stage('Clean Container') {
agent any
steps {
script {
sh '''
docker stop $IMAGE_NAME
docker rm $IMAGE_NAME
'''
}
}
}

stage('Save Artefact') {
agent any
steps {
script {
sh '''
docker save ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG > /tmp/alpinehelloworld.tar
'''
}
}
}
stage ('Login and Push Image on docker hub') {
agent any
environment {
DOCKERHUB_PASSWORD = credentials('dockerhub-credentials')
}
steps {
script {
sh '''
echo $DOCKERHUB_PASSWORD_PSW | docker login -u $ID_DOCKER --password-stdin
docker push ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG
'''
}
}
}

stage('STAGING - Deploy app') {
when {
expression { GIT_BRANCH == 'origin/eazylabs' }
}
agent any
steps {
script {
sh """
echo {\\"your_name\\":\\"${APP_NAME}\\",\\"container_image\\":\\"${CONTAINER_IMAGE}\\", \\"external_port\\":\\"${EXTERNAL_PORT}\\", \\"internal_port\\":\\"${INTERNAL_PORT}\\"} > data.json
curl -X POST http://${STG_API_ENDPOINT}/staging -H 'Content-Type: application/json' --data-binary @data.json
"""
}
}
}



stage('PRODUCTION - Deploy app') {
when {
expression { GIT_BRANCH == 'origin/master' }
}
agent any

steps {
script {
sh """
curl -X POST http://${PROD_API_ENDPOINT}/prod -H 'Content-Type: application/json' -d '{"your_name":"${APP_NAME}","container_image":"${CONTAINER_IMAGE}", "external_port":"${EXTERNAL_PORT}", "internal_port":"${INTERNAL_PORT}"}'
"""
}
}
}

}
}


8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# alpinehelloworld 1
An Alpine-based Docker example

[![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/)