Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

docker : review before merge #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store

.envrc
.direnv

*.pyc
__pycache__
4 changes: 4 additions & 0 deletions tips/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logs/
.git
*.md
.cache
3 changes: 3 additions & 0 deletions tips/docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_NAME=sds
DB_USER=sds
DB_PASSWORD=sds
7 changes: 7 additions & 0 deletions tips/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3
RUN pip install --upgrade pip
WORKDIR /usr/src/app
COPY . ./
RUN pip install -r requirements.txt
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
155 changes: 155 additions & 0 deletions tips/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# SDS Tech-X - Conteneurisation avec docker
<br/>

## Sommaire
1. [Introduction à la virtualisation](#virtualisation)
2. [Docker](#docker)
3. [Demo d'un exemple d'appli en microservice](#demo)



<br/>

## Introduction à la virtualisation
<br>

* *__Definition__* : Technologie permettant d'émuler plusieurs systèmes sur un même matériel physique
<br>

* *__Type de virtualisation__* :
* Virtualisation d'hardware (VM)
* Virtualisation d'OS (conteneur) <br>
<br><img src="pictures/vm_conteneur.png" alt="Your image title" width="350"/>

<br>

* *__Comparatif conteneur vm__* :
* Temps de démarrage
* Taille (MB vs GB)
* Portabilité (facile vs difficile)
* OS (partagé vs dédié)

<br>



<br><br>

## Docker

***


* *__Schéma de principe__* :
<br><img src="pictures/archi_docker.png" alt="Your image title" width="480"/>

<br>

* *__Intérêt de Docker__* : Faciliter et accélèrer les déploiements d’applications en construisant et exécutant des conteneurs

* *__Images__* : Modèle et dépendance contenant les ressources nécessaires à l’exécution d’une appli.

* *__Conteneurs__* : Processus et ses dépendances isolés. Exécution d'une image stokée mémoire

* *__Registry__* : Lieu d’échange et de stockage des images.


* *__Architecture de Docker__* : Basé sur une architecture client-serveur


* *__Docker File__* : Fichier dans lequel on renseigne des instructions qui vont permettre d’ajouter une nouvelle couche à une image afin de la personaliser.

* *__Docker Compose__* : Fonctionnalité de Docker qui permet d’orchestrer des conteneurs entre eux. Elle permet en pratique d’établir des règles de priorités telles que ce conteneur devra s’exécuter avant tel autre .





<br>
<br>

## Quelques commandes de base

***

### Ensemble des commandes applicables à une image
```
$ Docker image
```

### Visualiser les images qu'on a dans notre Docker Desktop

```
$ Docker image ls
```


### Visualiser les containers qu'on a dans notre Docker Desktop

```
$ Docker container ls
```

### Télécharger une image

```
$ Docker pull nom_image
```

Activer l'image : en pratique construit un container

```
$ Docker run nom_image
```

### Afficher les containers éteints mais disponibles dans le Docker Desktop
```
$ Docker ps -a
```

### Supprimer un container avec ses identifiants

```
$ Docker rm "4_premiers_chiffres_identifiant_container"
```

### Supprimer une image de son Docker Desktop

```
$ Docker rmi nom_image_

```


### Supprimer les container, images, volumes et réseaux inutilisés

```
$ Docker system prune
```
<br>

## Les 2 commandes de Docker compose

***
<br>


### Pour construire un container à partir d'une image
```
$ docker-compose build

```

### Pour instancier un conteneur en mémoire et le lancer
```
$ docker-compose up

```

***

<br>

## Liens utiles

A venir ...
Empty file.
16 changes: 16 additions & 0 deletions tips/docker/django_app/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for django_app project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_app.settings')

application = get_asgi_application()
154 changes: 154 additions & 0 deletions tips/docker/django_app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"""
Django settings for django_app project.

Generated by 'django-admin startproject' using Django 4.1.1.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
'crispy_forms',
'home.apps.HomeConfig',
'members',
'register',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_app.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv("DB_NAME"),
'USER': os.getenv("DB_USER"),
'PASSWORD': os.getenv("DB_PASSWORD"),
'HOST': 'pgdb',
'PORT': 5432,
}
}



# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]



MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)



CRISPY_TEMPLATE_PACK = "bootstrap4"

LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/members/login"
Loading