...
The main steps for the Dockerfile are:
Create a
.ssh
folder.Copy the deploy key into the
.ssh
folder.Add gitlab server to
known_hosts
file.Setup
.ssh/config
file to explicitly specify the deploy key and username to be used.Clone the repo.
Here is some example Dockerfile code.
Code Block RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh ADD id_rsa_ece_li_scheduling_deploy /root/.ssh/id_rsa_ece_li_scheduling_deploy RUN chmod 600 /root/.ssh/id_rsa_ece_li_scheduling_deploy RUN ssh-keyscan -H git.uwaterloo.ca >> /root/.ssh/known_hosts RUN echo "Host git.uwaterloo.ca\n\ HostName git.uwaterloo.ca\n\ IdentityFile /root/.ssh/id_rsa_ece_li_scheduling_deploy\n\ StrictHostKeyChecking no\n\ User ist-git" >> /root/.ssh/config RUN chmod 600 /root/.ssh/config RUN git clone ist-git@git.uwaterloo.ca:d24lau/ece_li_scheduling.git
Docker build and run
At this stage, you should be able to use a browser to test that the Django server is up and running. Go to http://<server address>:8000
.
Start First App
Navigate to the root directory of the Django project (where the
manage.py
file is located).Use
manage.py
to initialize the app:Code Block python3 manage.py startapp <app name>
Register app
Register the app with the project.
Go to the project folder (e.g.
/opt/ece_li_scheduling/ece_li_scheduling
) where thesettings.py
file is stored.In the
settings.py
file, add the name of the new app to theINSTALLED_APPS
list:Code Block INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', '<app name>', ]
In the
urls.py
file, direct all traffic for the new app to its.urls
file.Code Block urlpatterns = [ path('admin/', admin.site.urls), path('<app name>/', include('<app name>.urls')) ]
Note that
include
needs to be imported fromdjango.urls
.
Create view
The app needs at least one view.