mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-15 01:14:53 +03:00
choose editor and configure devcontainer
This commit is contained in:
parent
9f2b9f7f8d
commit
b7942bb265
|
@ -120,9 +120,12 @@ Answer the prompts with your own desired [options](http://cookiecutter-django.re
|
||||||
Choose from 1, 2, 3, 4, 5 [1]: 1
|
Choose from 1, 2, 3, 4, 5 [1]: 1
|
||||||
timezone [UTC]: America/Los_Angeles
|
timezone [UTC]: America/Los_Angeles
|
||||||
windows [n]: n
|
windows [n]: n
|
||||||
use_pycharm [n]: y
|
Select an editor to use. The choices are:
|
||||||
|
1 - None
|
||||||
|
2 - PyCharm
|
||||||
|
3 - VS Code
|
||||||
|
Choose from 1, 2, 3 [1]: 1
|
||||||
use_docker [n]: n
|
use_docker [n]: n
|
||||||
use_vscode_devcontainer [n]: n
|
|
||||||
Select postgresql_version:
|
Select postgresql_version:
|
||||||
1 - 14
|
1 - 14
|
||||||
2 - 13
|
2 - 13
|
||||||
|
|
|
@ -15,9 +15,12 @@
|
||||||
],
|
],
|
||||||
"timezone": "UTC",
|
"timezone": "UTC",
|
||||||
"windows": "n",
|
"windows": "n",
|
||||||
"use_pycharm": "n",
|
"editor": [
|
||||||
|
"None",
|
||||||
|
"PyCharm",
|
||||||
|
"VS Code"
|
||||||
|
],
|
||||||
"use_docker": "n",
|
"use_docker": "n",
|
||||||
"use_vscode_devcontainer": "n",
|
|
||||||
"postgresql_version": [
|
"postgresql_version": [
|
||||||
"14",
|
"14",
|
||||||
"13",
|
"13",
|
||||||
|
@ -63,4 +66,4 @@
|
||||||
],
|
],
|
||||||
"keep_local_envs_in_vcs": "y",
|
"keep_local_envs_in_vcs": "y",
|
||||||
"debug": "n"
|
"debug": "n"
|
||||||
}
|
}
|
|
@ -46,14 +46,15 @@ timezone:
|
||||||
windows:
|
windows:
|
||||||
Indicates whether the project should be configured for development on Windows.
|
Indicates whether the project should be configured for development on Windows.
|
||||||
|
|
||||||
use_pycharm:
|
editor:
|
||||||
Indicates whether the project should be configured for development with PyCharm_.
|
Select an editor to use. The choices are:
|
||||||
|
|
||||||
|
1. None
|
||||||
|
2. PyCharm_
|
||||||
|
3. `VS Code`_
|
||||||
|
|
||||||
use_docker:
|
use_docker:
|
||||||
Indicates whether the project should be configured to use Docker_ and `Docker Compose`_.
|
Indicates whether the project should be configured to use Docker_, `Docker Compose`_ and `devcontainer`_.
|
||||||
|
|
||||||
use_vscode_devcontainer:
|
|
||||||
Indicates whether the project should be configured to use `VS Code Dev Container`_.
|
|
||||||
|
|
||||||
postgresql_version:
|
postgresql_version:
|
||||||
Select a PostgreSQL_ version to use. The choices are:
|
Select a PostgreSQL_ version to use. The choices are:
|
||||||
|
@ -144,11 +145,11 @@ debug:
|
||||||
.. _Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
.. _Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
.. _PyCharm: https://www.jetbrains.com/pycharm/
|
.. _PyCharm: https://www.jetbrains.com/pycharm/
|
||||||
|
.. _VS Code: https://github.com/microsoft/vscode
|
||||||
|
|
||||||
.. _Docker: https://github.com/docker/docker
|
.. _Docker: https://github.com/docker/docker
|
||||||
.. _Docker Compose: https://docs.docker.com/compose/
|
.. _Docker Compose: https://docs.docker.com/compose/
|
||||||
|
.. _devcontainer: https://containers.dev/
|
||||||
.. _VS Code Dev Container: https://github.com/microsoft/vscode-dev-containers
|
|
||||||
|
|
||||||
.. _PostgreSQL: https://www.postgresql.org/docs/
|
.. _PostgreSQL: https://www.postgresql.org/docs/
|
||||||
|
|
||||||
|
|
|
@ -55,29 +55,7 @@ def remove_pycharm_files():
|
||||||
shutil.rmtree(docs_dir_path)
|
shutil.rmtree(docs_dir_path)
|
||||||
|
|
||||||
|
|
||||||
def remove_docker_files():
|
def create_devcontainer_bash_history_file():
|
||||||
if "{{ cookiecutter.use_vscode_devcontainer }}".lower() == "n":
|
|
||||||
shutil.rmtree("compose")
|
|
||||||
file_names = ["local.yml", "production.yml", ".dockerignore"]
|
|
||||||
else:
|
|
||||||
file_names = ["production.yml"]
|
|
||||||
|
|
||||||
for file_name in file_names:
|
|
||||||
os.remove(file_name)
|
|
||||||
|
|
||||||
if "{{ cookiecutter.use_pycharm }}".lower() == "y":
|
|
||||||
file_names = ["docker_compose_up_django.xml", "docker_compose_up_docs.xml"]
|
|
||||||
for file_name in file_names:
|
|
||||||
os.remove(os.path.join(".idea", "runConfigurations", file_name))
|
|
||||||
|
|
||||||
|
|
||||||
def remove_vscode_devcontainer_files():
|
|
||||||
dir_path = ".devcontainer"
|
|
||||||
if os.path.exists(dir_path):
|
|
||||||
shutil.rmtree(dir_path)
|
|
||||||
|
|
||||||
|
|
||||||
def create_vscode_devcontainer_bash_history_file():
|
|
||||||
history_dir_path = ".history"
|
history_dir_path = ".history"
|
||||||
if not os.path.exists(history_dir_path):
|
if not os.path.exists(history_dir_path):
|
||||||
os.mkdir(history_dir_path)
|
os.mkdir(history_dir_path)
|
||||||
|
@ -87,6 +65,19 @@ def create_vscode_devcontainer_bash_history_file():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def remove_docker_files():
|
||||||
|
shutil.rmtree(".devcontainer")
|
||||||
|
shutil.rmtree("compose")
|
||||||
|
|
||||||
|
file_names = ["local.yml", "production.yml", ".dockerignore"]
|
||||||
|
for file_name in file_names:
|
||||||
|
os.remove(file_name)
|
||||||
|
if "{{ cookiecutter.editor }}".lower() == "PyCharm":
|
||||||
|
file_names = ["docker_compose_up_django.xml", "docker_compose_up_docs.xml"]
|
||||||
|
for file_name in file_names:
|
||||||
|
os.remove(os.path.join(".idea", "runConfigurations", file_name))
|
||||||
|
|
||||||
|
|
||||||
def remove_utility_files():
|
def remove_utility_files():
|
||||||
shutil.rmtree("utility")
|
shutil.rmtree("utility")
|
||||||
|
|
||||||
|
@ -461,18 +452,15 @@ def main():
|
||||||
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
|
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
|
||||||
remove_gplv3_files()
|
remove_gplv3_files()
|
||||||
|
|
||||||
if "{{ cookiecutter.use_pycharm }}".lower() == "n":
|
if "{{ cookiecutter.editor }}".lower() != "PyCharm":
|
||||||
remove_pycharm_files()
|
remove_pycharm_files()
|
||||||
|
|
||||||
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
||||||
remove_utility_files()
|
remove_utility_files()
|
||||||
|
create_devcontainer_bash_history_file()
|
||||||
else:
|
else:
|
||||||
remove_docker_files()
|
remove_docker_files()
|
||||||
|
|
||||||
if "{{ cookiecutter.use_vscode_devcontainer }}".lower() == "n":
|
|
||||||
remove_vscode_devcontainer_files()
|
|
||||||
else:
|
|
||||||
create_vscode_devcontainer_bash_history_file()
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
"{{ cookiecutter.use_docker }}".lower() == "y"
|
"{{ cookiecutter.use_docker }}".lower() == "y"
|
||||||
|
@ -488,14 +476,12 @@ def main():
|
||||||
if (
|
if (
|
||||||
"{{ cookiecutter.use_docker }}".lower() == "n"
|
"{{ cookiecutter.use_docker }}".lower() == "n"
|
||||||
and "{{ cookiecutter.use_heroku }}".lower() == "n"
|
and "{{ cookiecutter.use_heroku }}".lower() == "n"
|
||||||
and "{{ cookiecutter.use_vscode_devcontainer }}".lower() == "n"
|
|
||||||
):
|
):
|
||||||
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
||||||
print(
|
print(
|
||||||
INFO + ".env(s) are only utilized when Docker Compose and/or "
|
INFO + ".env(s) are only utilized when Docker Compose and/or "
|
||||||
"Heroku and/or VS Code Dev Container support is enabled so "
|
"Heroku support is enabled so keeping them does not make sense "
|
||||||
"keeping them does not make sense given your current setup."
|
"given your current setup." + TERMINATOR
|
||||||
+ TERMINATOR
|
|
||||||
)
|
)
|
||||||
remove_envs_and_associated_files()
|
remove_envs_and_associated_files()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"mounts": [
|
"mounts": [
|
||||||
{
|
{
|
||||||
"source": "./.history/bash_history",
|
"source": "./.history/bash_history",
|
||||||
"target": "/home/vscode/.bash_history",
|
"target": "/home/dev-user/.bash_history",
|
||||||
"type": "bind"
|
"type": "bind"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -21,11 +21,12 @@
|
||||||
// /bin/sh -c "while sleep 1000; do :; done" when starting the container instead of the container’s default command
|
// /bin/sh -c "while sleep 1000; do :; done" when starting the container instead of the container’s default command
|
||||||
"overrideCommand": true,
|
"overrideCommand": true,
|
||||||
"service": "django",
|
"service": "django",
|
||||||
// "remoteEnv": {"PATH": "/home/vscode/.local/bin:${containerEnv:PATH}"},
|
// "remoteEnv": {"PATH": "/home/dev-user/.local/bin:${containerEnv:PATH}"},
|
||||||
"remoteUser": "vscode",
|
"remoteUser": "dev-user",
|
||||||
"workspaceFolder": "/app",
|
"workspaceFolder": "/app",
|
||||||
// Set *default* container specific settings.json values on container create.
|
// Set *default* container specific settings.json values on container create.
|
||||||
"customizations": {
|
"customizations": {
|
||||||
|
{% if cookiecutter.editor == "VS Code" %}
|
||||||
"vscode": {
|
"vscode": {
|
||||||
"settings": {
|
"settings": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
|
@ -73,6 +74,7 @@
|
||||||
"batisteo.vscode-django"
|
"batisteo.vscode-django"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
},
|
},
|
||||||
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
||||||
// "runServices": [],
|
// "runServices": [],
|
||||||
|
|
|
@ -35,16 +35,16 @@ ENV BUILD_ENV ${BUILD_ENVIRONMENT}
|
||||||
|
|
||||||
WORKDIR ${APP_HOME}
|
WORKDIR ${APP_HOME}
|
||||||
|
|
||||||
{% if cookiecutter.use_vscode_devcontainer == "y" %}
|
{% if cookiecutter.docker == "y" %}
|
||||||
# VS Code devcontainer dependencies and utils
|
# devcontainer dependencies and utils
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
sudo git bash-completion nano
|
sudo git bash-completion nano
|
||||||
|
|
||||||
# Create vscode user and add it to sudoers
|
# Create devcontainer user and add it to sudoers
|
||||||
RUN groupadd --gid 1000 vscode \
|
RUN groupadd --gid 1000 dev-user \
|
||||||
&& useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \
|
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
|
||||||
&& echo vscode ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/vscode \
|
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
|
||||||
&& chmod 0440 /etc/sudoers.d/vscode
|
&& chmod 0440 /etc/sudoers.d/dev-user
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
# Install required system dependencies
|
# Install required system dependencies
|
||||||
|
|
Loading…
Reference in New Issue
Block a user