diff --git a/.gitignore b/.gitignore index d8fe0c5..5f3acb0 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,5 @@ venv.bak/ # mypy .mypy_cache/ + +.idea diff --git a/Dockerfile-online b/Dockerfile-online index 4d2df1d..045d1ed 100644 --- a/Dockerfile-online +++ b/Dockerfile-online @@ -1,8 +1,8 @@ -FROM python:2.7.16-alpine3.9 +FROM python:2 RUN mkdir /code COPY . /code WORKDIR /code/src RUN pip install /code/pkgs/base/* -ENTRYPOINT python manage.py runserver 0.0.0.0:8080 \ No newline at end of file +ENTRYPOINT python manage.py runserver 0.0.0.0:8080 diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 8678511..775fe6e 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -8,7 +8,7 @@ pipeline { DOCKER_CREDENTIAL_ID = 'dockerhub' KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'shaowenchen' + DOCKERHUB_NAMESPACE = 'kubespheredev' APP_NAME = 'devops-python-sample' SONAR_CREDENTIAL_ID = 'sonar-token' } @@ -20,7 +20,7 @@ pipeline { stage('拉取代码') { steps { container('base') { - checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/shaowenchen/devops-python-sample.git']]]) + checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/kubesphere/devops-python-sample.git']]]) } /* if in scm, you can use: checkout scm */ } @@ -32,11 +32,11 @@ pipeline { 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 - ''' + coverage erase + cd ./src/ + coverage run --source='.' manage.py test + coverage xml -i + ''' sh "sonar-scanner -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" } @@ -63,7 +63,12 @@ pipeline { stage('部署') { steps { - kubernetesDeploy(enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID", configs: 'deploy/**') + container ('base') { + withCredentials([kubeconfigFile(credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')]) { + sh 'envsubst < deploy/devops-sample.yaml | kubectl apply -f -' + sh 'envsubst < deploy/devops-sample-svc.yaml | kubectl apply -f -' + } + } } } diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..5b46da3 --- /dev/null +++ b/OWNERS @@ -0,0 +1,5 @@ +approvers: + - linuxsuren + +reviewers: + - JohnNiang diff --git a/README.md b/README.md index 4d5db55..0e947cf 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## 部署步骤 -1. 在 Kubesphere 平台,创建命名为 django-proj 的工程。 +1. 在 Kubesphere 平台,创建命名为 django-proj 的项目。 在 Kubesphere 中,项目对应 namespace 。如果不使用 django-proj 命名空间,则需要修改 Jenkinsfile 文件,保持一致。 diff --git a/makefile b/makefile new file mode 100644 index 0000000..99aeb49 --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ +run: + docker build -f Dockerfile-online -t shaowenchen/demo . + docker run -d -p 8011:8000 --name python-demo shaowenchen/demo +test: + curl localhost:8011 +stop: + docker stop python-demo + docker rm python-demo diff --git a/pkgs/base/Django-1.11.23-py2.py3-none-any.whl b/pkgs/base/Django-1.11.29-py2.py3-none-any.whl similarity index 91% rename from pkgs/base/Django-1.11.23-py2.py3-none-any.whl rename to pkgs/base/Django-1.11.29-py2.py3-none-any.whl index 8485dc3..805f1fd 100644 Binary files a/pkgs/base/Django-1.11.23-py2.py3-none-any.whl and b/pkgs/base/Django-1.11.29-py2.py3-none-any.whl differ diff --git a/pkgs/base/pytz-2019.2-py2.py3-none-any.whl b/pkgs/base/pytz-2020.4-py2.py3-none-any.whl similarity index 57% rename from pkgs/base/pytz-2019.2-py2.py3-none-any.whl rename to pkgs/base/pytz-2020.4-py2.py3-none-any.whl index c662f39..9354794 100644 Binary files a/pkgs/base/pytz-2019.2-py2.py3-none-any.whl and b/pkgs/base/pytz-2020.4-py2.py3-none-any.whl differ diff --git a/src/project/settings.py b/src/project/settings.py index 3bad2e6..ce3d3cf 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -27,6 +27,7 @@ ALLOWED_HOSTS = ['*'] +DISABLE_CHECKS = True # Application definition @@ -119,3 +120,5 @@ # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' + +STATIC_ROOT = os.path.join(BASE_DIR, 'static') diff --git a/src/requirements.txt b/src/requirements.txt index cc38b2c..88a32ac 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1,2 @@ Django==1.11.29 coverage==4.5.4 -nose==1.3.7