diff --git a/cookiecutter.json b/cookiecutter.json index e91b3c1f5..8dfbc09ea 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -20,9 +20,6 @@ "use_compressor": "n", "js_task_runner": ["Gulp", "Grunt", "None"], "use_lets_encrypt": "n", - "use_gitlab_ci": "n", - "staging_branch": "", - "staging_domain_name": "beta.{{ cookiecutter.domain_name }}", - "production_branch": "", + "use_gitlab_ci": ["No", "Test Only", "Test and Deploy"], "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] } diff --git a/docs/ci-gitlab.rst b/docs/ci-gitlab.rst index c3bc45f8a..b594834c4 100644 --- a/docs/ci-gitlab.rst +++ b/docs/ci-gitlab.rst @@ -48,23 +48,16 @@ set up continuous deployment. Configuring GitLab CI for Continuous Deployment ----------------------------------------------- -1) Set up Ubuntu machines with Docker for the staging (if desired) and production -sites. Digital Ocean has a droplet configuration that makes this very convenient -but any machines will do. +1) Set up an Ubuntu machine with Docker for the production site. Digital Ocean +has a droplet configuration that makes this very convenient but any machine will do. 2) On the test runner, create an ssh key. Add it as an authorized key on the -staging and production machines and as a deploy key in the GitLab project: +production machine and as a deploy key in the GitLab project: :: sudo -u gitlab-runner -H ssh-keygen -t rsa -C "gitlab-runner@DOMAIN" -3) On the test runner, create a docker machine for the staging site: - -:: - - sudo -u gitlab-runner -H docker-machine create -d generic --generic-ip-address {{cookiecutter.staging_domain_name}} - 4) On the test runner, create a docker machine for the production site: :: @@ -76,5 +69,5 @@ All Done Congratulations! You now have a GitLab CI environment to run the tests for every commit (all branches including feature branches) and automatically deploy -staging and production environments. +the master branch to the production site. diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 32fefb63b..98994d9fe 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -49,19 +49,8 @@ use_python2 [n] By default, the Python code generated will be for Python 3.x. But if you answer `y` here, it will be legacy Python 2.7 code. -use_gitlab_ci [n] - Whether to use GitLab CI for testing. - -staging_branch [] - If using GitLab for continuous deployment, the git branch to deploy in the - staging environment. - -staging_domain_name [beta.domain_name] - If deploying to a staging environment, the domain name of the staging site. - -production_branch [] - If using GitLab for continuous deployment, the git branch to deploy in the - production environment. +use_gitlab_ci ["No"] + Whether to use GitLab CI for testing and continuous deployment. .. _WhiteNoise: https://github.com/evansd/whitenoise .. _Celery: https://github.com/celery/celery diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 65c7ed614..372c126ca 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -174,7 +174,7 @@ def remove_gitlab_ci_files(): """ Removes files needed for GitLab CI if it isn't going to be used """ - for filename in [".gitlab-ci.yml, test.yml"]: + for filename in [".gitlab-ci.yml", "test.yml"]: os.remove(os.path.join( PROJECT_DIRECTORY, filename )) @@ -260,11 +260,11 @@ if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use ) # 11. Removes all GitLab CI files if it isn't going to be used -if '{{ cookiecutter.use_gitlab_ci }}'.lower() != 'y': +if '{{ cookiecutter.use_gitlab_ci }}'.lower() == 'no': remove_gitlab_ci_files() # 12. Removes the GitLab CI files and display a warning if use_gitlab_ci is selected and use_docker isn't. -if '{{ cookiecutter.use_gitlab_ci }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': +if '{{ cookiecutter.use_gitlab_ci }}'.lower() != 'no' and '{{ cookiecutter.use_docker }}'.lower() != 'y': remove_gitlab_ci_files() print( "You selected to use GitLab CI and didn't select to use docker. This is NOT supported out of the box for now. You " @@ -272,7 +272,7 @@ if '{{ cookiecutter.use_gitlab_ci }}'.lower() == 'y' and '{{ cookiecutter.use_do ) # 13. Directs the user to the documentation if certbot and docker are selected. -if '{{ cookiecutter.use_gitlab_ci }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': +if '{{ cookiecutter.use_gitlab_ci }}'.lower() != 'no' and '{{ cookiecutter.use_docker }}'.lower() == 'y': print( "You selected to use GitLab CI. Please see the documentation for instructions on how to set up the GitLab CI environment" ) diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index fbbf47afb..3064d522f 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -1,6 +1,8 @@ stages: - test +{% if cookiecutter.use_gitlab_ci == 'Test and Deploy' %} - deploy +{% endif %} test: script: @@ -8,22 +10,7 @@ test: - docker-compose -f test.yml run --rm django bash -c "flake8" - docker-compose -f test.yml run --rm django bash -c "coverage run --branch manage.py test && coverage report -m" -{% if cookiecutter.staging_branch != '' %} -staging: - type: deploy - script: - - eval "$(docker-machine env {{cookiecutter.staging_domain_name}})" - - docker-compose build - - docker-compose run --rm django python manage.py migrate - - docker-compose up -d - - docker rm -v `docker ps -a -q -f status=exited` || true - - docker rmi `docker images -f "dangling=true" -q` || true - - docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes - only: - - {{cookiecutter.staging_branch}} -{% endif %} - -{% if cookiecutter.production_branch != '' %} +{% if cookiecutter.use_gitlab_ci == 'Test and Deploy' %} production: type: deploy script: @@ -35,5 +22,6 @@ production: - docker rmi `docker images -f "dangling=true" -q` || true - docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes only: - - {{cookiecutter.production_branch}} + - master {% endif %} +