Skip to content

Create README.md #25

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 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* Import shared library */
@Library('guissepm-shared-library)
pipeline {
environment {
ID_DOCKER = "${ID_DOCKER_PARAMS}"
IMAGE_NAME = "alpinehelloworld"
IMAGE_TAG = "latest"
// PORT_EXPOSED = "80" à paraméter dans le job obligatoirement
APP_NAME = "guisse"
STG_API_ENDPOINT = "ip10-0-2-3-cibh2tni3nvgqghmcct0-1993.direct.docker.labs.eazytraining.fr"
STG_APP_ENDPOINT = "ip10-0-2-3-cibh2tni3nvgqghmcct0-80.direct.docker.labs.eazytraining.fr"
PROD_API_ENDPOINT = "ip10-0-2-4-cibh2tni3nvgqghmcct0-1993.direct.docker.labs.eazytraining.fr"
PROD_APP_ENDPOINT = "ip10-0-2-4-cibh2tni3nvgqghmcct0-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 '''
docker login -u $DOCKERHUB_ID --password $DOCKERHUB_PASSWORD
docker push ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG
'''
}
}
}

stage('STAGING - Deploy app') {
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}"}'
"""
}
}
}
}

post {
always {
script {
slackNotifier currentBuild.result
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# alpinehelloworld
An Alpine-based Docker example
https://fe23-154-124-50-221.ngrok-free.app