Skip to content

Commit 443083d

Browse files
authored
Dynamically generate template and resolve existing issues (#16)
1 parent ede94e1 commit 443083d

File tree

8 files changed

+37
-208
lines changed

8 files changed

+37
-208
lines changed

.gitpod.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
1+
# Image source code: https://github.com/axonasif/workspace-images/tree/tmp
2+
# Also see: https://github.com/gitpod-io/workspace-images/issues/1071
3+
image: axonasif/workspace-python@sha256:f5ba627a31505ea6cf100abe8e552d7ff9e0abd6ba46745b6d6dab349c001430
4+
15
tasks:
2-
- init: |
3-
python -m venv venv
4-
source venv/bin/activate
6+
- name: Init project and run server
7+
init: |
8+
# Install Django and upgrade some dependencies
59
pip install --upgrade pip wheel setuptools
610
pip install Django
11+
12+
# Init Django project
13+
name="mysite"
14+
if test ! -e "${name}"; then {
15+
django-admin startproject "${name}" .
16+
} fi
17+
18+
# Modify settings.py to include Gitpod port hosts
19+
settings="${name}/settings.py"
20+
if test -e "${settings}" && ! grep -q 'GITPOD_WORKSPACE_URL' "${settings}" 2>/dev/null; then {
21+
cat >> "${settings}" << 'SCRIPT'
22+
23+
if __import__('os').environ.get('GITPOD_WORKSPACE_URL'):
24+
try:
25+
gp = __import__('subprocess').run(["gp", "url", "8000"], capture_output=True, text=True)
26+
if gp.returncode == 0 and gp.stdout:
27+
ALLOWED_HOSTS += [gp.stdout.strip().split('//', 1)[-1]]
28+
except:
29+
ALLOWED_HOSTS += ['*']
30+
31+
SCRIPT
32+
} fi
33+
34+
if test -e requirements.txt; then {
35+
pip install -r requirements.txt
36+
} fi
37+
738
python manage.py migrate
8-
- command: |
9-
source venv/bin/activate
39+
command: |
1040
python manage.py runserver
1141
1242
ports:
1343
- port: 8000
14-
visibility: private
1544
onOpen: open-preview
1645

1746
vscode:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A Python Django template on Gitpod
22

3-
This is a [Python Django](https://www.djangoproject.com) template configured for ephemeral cloud development environments on [Gitpod](https://www.gitpod.io/).
3+
This is a [Python Django](https://www.djangoproject.com) template generator configured for ephemeral cloud development environments on [Gitpod](https://www.gitpod.io/).
44

55
## Next Steps
66

@@ -16,4 +16,4 @@ Click the above "Open in Gitpod" button to start a new workspace. Once you're re
1616

1717
### An existing project
1818

19-
To get started with Python Django on Gitpod, add a [`.gitpod.yml`](./.gitpod.yml) file which contains the configuration to improve the developer experience on Gitpod. To learn more, please see the [Getting Started](https://www.gitpod.io/docs/getting-started) documentation.
19+
Copy and commit the [`.gitpod.yml`](./.gitpod.yml) to your existing project to have the same configuration of this template. To learn more, please see the [Getting Started](https://www.gitpod.io/docs/getting-started) documentation.

manage.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

mysite/__init__.py

Whitespace-only changes.

mysite/asgi.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

mysite/settings.py

Lines changed: 0 additions & 125 deletions
This file was deleted.

mysite/urls.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

mysite/wsgi.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)