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
|
||||
timezone [UTC]: America/Los_Angeles
|
||||
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_vscode_devcontainer [n]: n
|
||||
Select postgresql_version:
|
||||
1 - 14
|
||||
2 - 13
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
],
|
||||
"timezone": "UTC",
|
||||
"windows": "n",
|
||||
"use_pycharm": "n",
|
||||
"editor": [
|
||||
"None",
|
||||
"PyCharm",
|
||||
"VS Code"
|
||||
],
|
||||
"use_docker": "n",
|
||||
"use_vscode_devcontainer": "n",
|
||||
"postgresql_version": [
|
||||
"14",
|
||||
"13",
|
||||
|
|
|
@ -46,14 +46,15 @@ timezone:
|
|||
windows:
|
||||
Indicates whether the project should be configured for development on Windows.
|
||||
|
||||
use_pycharm:
|
||||
Indicates whether the project should be configured for development with PyCharm_.
|
||||
editor:
|
||||
Select an editor to use. The choices are:
|
||||
|
||||
1. None
|
||||
2. PyCharm_
|
||||
3. `VS Code`_
|
||||
|
||||
use_docker:
|
||||
Indicates whether the project should be configured to use Docker_ and `Docker Compose`_.
|
||||
|
||||
use_vscode_devcontainer:
|
||||
Indicates whether the project should be configured to use `VS Code Dev Container`_.
|
||||
Indicates whether the project should be configured to use Docker_, `Docker Compose`_ and `devcontainer`_.
|
||||
|
||||
postgresql_version:
|
||||
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
|
||||
|
||||
.. _PyCharm: https://www.jetbrains.com/pycharm/
|
||||
.. _VS Code: https://github.com/microsoft/vscode
|
||||
|
||||
.. _Docker: https://github.com/docker/docker
|
||||
.. _Docker Compose: https://docs.docker.com/compose/
|
||||
|
||||
.. _VS Code Dev Container: https://github.com/microsoft/vscode-dev-containers
|
||||
.. _devcontainer: https://containers.dev/
|
||||
|
||||
.. _PostgreSQL: https://www.postgresql.org/docs/
|
||||
|
||||
|
|
|
@ -55,29 +55,7 @@ def remove_pycharm_files():
|
|||
shutil.rmtree(docs_dir_path)
|
||||
|
||||
|
||||
def remove_docker_files():
|
||||
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():
|
||||
def create_devcontainer_bash_history_file():
|
||||
history_dir_path = ".history"
|
||||
if not os.path.exists(history_dir_path):
|
||||
os.mkdir(history_dir_path)
|
||||
|
@ -87,6 +65,19 @@ def create_vscode_devcontainer_bash_history_file():
|
|||
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():
|
||||
shutil.rmtree("utility")
|
||||
|
||||
|
@ -461,18 +452,15 @@ def main():
|
|||
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
|
||||
remove_gplv3_files()
|
||||
|
||||
if "{{ cookiecutter.use_pycharm }}".lower() == "n":
|
||||
if "{{ cookiecutter.editor }}".lower() != "PyCharm":
|
||||
remove_pycharm_files()
|
||||
|
||||
if "{{ cookiecutter.use_docker }}".lower() == "y":
|
||||
remove_utility_files()
|
||||
create_devcontainer_bash_history_file()
|
||||
else:
|
||||
remove_docker_files()
|
||||
|
||||
if "{{ cookiecutter.use_vscode_devcontainer }}".lower() == "n":
|
||||
remove_vscode_devcontainer_files()
|
||||
else:
|
||||
create_vscode_devcontainer_bash_history_file()
|
||||
|
||||
if (
|
||||
"{{ cookiecutter.use_docker }}".lower() == "y"
|
||||
|
@ -488,14 +476,12 @@ def main():
|
|||
if (
|
||||
"{{ cookiecutter.use_docker }}".lower() == "n"
|
||||
and "{{ cookiecutter.use_heroku }}".lower() == "n"
|
||||
and "{{ cookiecutter.use_vscode_devcontainer }}".lower() == "n"
|
||||
):
|
||||
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
||||
print(
|
||||
INFO + ".env(s) are only utilized when Docker Compose and/or "
|
||||
"Heroku and/or VS Code Dev Container support is enabled so "
|
||||
"keeping them does not make sense given your current setup."
|
||||
+ TERMINATOR
|
||||
"Heroku support is enabled so keeping them does not make sense "
|
||||
"given your current setup." + TERMINATOR
|
||||
)
|
||||
remove_envs_and_associated_files()
|
||||
else:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"mounts": [
|
||||
{
|
||||
"source": "./.history/bash_history",
|
||||
"target": "/home/vscode/.bash_history",
|
||||
"target": "/home/dev-user/.bash_history",
|
||||
"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
|
||||
"overrideCommand": true,
|
||||
"service": "django",
|
||||
// "remoteEnv": {"PATH": "/home/vscode/.local/bin:${containerEnv:PATH}"},
|
||||
"remoteUser": "vscode",
|
||||
// "remoteEnv": {"PATH": "/home/dev-user/.local/bin:${containerEnv:PATH}"},
|
||||
"remoteUser": "dev-user",
|
||||
"workspaceFolder": "/app",
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"customizations": {
|
||||
{% if cookiecutter.editor == "VS Code" %}
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"editor.formatOnSave": true,
|
||||
|
@ -73,6 +74,7 @@
|
|||
"batisteo.vscode-django"
|
||||
]
|
||||
}
|
||||
{% endif %}
|
||||
},
|
||||
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
||||
// "runServices": [],
|
||||
|
|
|
@ -35,16 +35,16 @@ ENV BUILD_ENV ${BUILD_ENVIRONMENT}
|
|||
|
||||
WORKDIR ${APP_HOME}
|
||||
|
||||
{% if cookiecutter.use_vscode_devcontainer == "y" %}
|
||||
# VS Code devcontainer dependencies and utils
|
||||
{% if cookiecutter.docker == "y" %}
|
||||
# devcontainer dependencies and utils
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
sudo git bash-completion nano
|
||||
|
||||
# Create vscode user and add it to sudoers
|
||||
RUN groupadd --gid 1000 vscode \
|
||||
&& useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \
|
||||
&& echo vscode ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/vscode \
|
||||
&& chmod 0440 /etc/sudoers.d/vscode
|
||||
# Create devcontainer user and add it to sudoers
|
||||
RUN groupadd --gid 1000 dev-user \
|
||||
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
|
||||
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
|
||||
&& chmod 0440 /etc/sudoers.d/dev-user
|
||||
{% endif %}
|
||||
|
||||
# Install required system dependencies
|
||||
|
|
Loading…
Reference in New Issue
Block a user