diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1e72730 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,71 @@ +pipeline { + agent { + node { + label 'base' + } + } + environment { + DOCKER_CREDENTIAL_ID = 'dockerhub' + KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' + REGISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'a-ethan' + APP_NAME = 'devops-python-sample' + SONAR_CREDENTIAL_ID = 'sonar-token' + } + parameters { + string(name: 'BRANCH_NAME', defaultValue: 'master', description: '') + } + + stages { + stage('拉取代码') { + steps { + container('base') { + checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/a-ethan/devops-python-sample.git']]]) + } + /* if in scm, you can use: checkout scm */ + } + } + + // stage('代码检查') { + // steps { + // container('base') { + // withCredentials([string(credentialsId : "$SONAR_CREDENTIAL_ID" ,variable : 'SONAR_TOKEN' ,)]) { + // withSonarQubeEnv('sonar') { + // sh '''pip install pkgs/base/* & pip install pkgs/extra/* + // coverage erase + // cd ./src/ + // coverage run --source='.' manage.py test + // coverage xml -i + // ''' + // sh "sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + // } + + // } + + // } + + // } + // } + + // stage('推送镜像') { + // steps { + // container('base') { + // withCredentials([usernamePassword(credentialsId : "$DOCKER_CREDENTIAL_ID" ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) { + // sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' + // sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER .' + // sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER' + // } + + // } + + // } + // } + + // stage('部署') { + // steps { + // kubernetesDeploy(enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID", configs: 'deploy/**') + // } + // } + + } +} diff --git a/Jenkinsfile-online b/Jenkinsfile-online.bak similarity index 100% rename from Jenkinsfile-online rename to Jenkinsfile-online.bak diff --git a/makefile b/makefile index 99aeb49..1e7a3a5 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ run: - docker build -f Dockerfile-online -t shaowenchen/demo . - docker run -d -p 8011:8000 --name python-demo shaowenchen/demo + docker build -f Dockerfile-online -t a-ethan/demo . + docker run -d -p 8011:8000 --name python-demo a-ethan/demo test: curl localhost:8011 stop: