mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-30 01:39:45 +03:00
Use single question to configure GitLab CI.
Switch to a single question with three options: "None", "Test Only" and "Test and Deploy". If "Test and Deploy" is chosen then the master branch is automatically deployed to {{ cookiecutter.domain_name }}.
This commit is contained in:
parent
8a9eecea0e
commit
e561907c50
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -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 <IP address of staging site> {{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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user