Skip to content

Commit

Permalink
Adding a local dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreLarochelle authored and j-bernard committed Jun 28, 2022
1 parent 4339386 commit 1d8b0ab
Show file tree
Hide file tree
Showing 18 changed files with 661 additions and 1 deletion.
5 changes: 4 additions & 1 deletion containers/lgr-django/files/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Django==3.1.7
django-widget-tweaks==1.4.8
celery[redis]==5.0.5
#django-redis==4.12.1
django-redis @ git+https://github.com/jazzband/django-redis.git@683ebcf16a5c342d9794552c9897c8baa2d6b0be
django-autocomplete-light==3.5.1
vine==5.0.0
Expand All @@ -14,5 +13,9 @@ django-celery-beat==2.2.0
picu==1.2
munidata==2.1.0
lgr-core @ git+https://github.com/icann/[email protected]

# Natural sorting implementation
natsort==7.1.1

# OAuth support
social-auth-app-django==5.0.0
82 changes: 82 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# LGR-Tool local development deployment

## About

This tool will permit to recreate mostly fatefully the ICANN production
environement in local container deploy with docker-compose instead of helm.

Of course as it is not a K8S environement many ajustement had to be made to
make everything possible. There is the exaustive list of change:

- No daily manage.py cronjob for DB cleanup
- No Helm/K8S deployement (Obviously)
- Use a MariaDB container instead of a localy shared sqlite DB
- Use a Redis container instead of a Redis Sentinel Cluster

## Warning

To permit a simple local deployment for developement purpose, spoof password
have been put in plain text inside the configuration files. This is NOT a good
production pratice and therefore THIS DEPLOYEMENT SCRIPT SHOULD NEVER BE USE IN
A PRODUCTION ENVIRONEMENT. At least not without removing plain text password
before hand.

## Requirement

Everything run in docker containers and is manage with the docker-compose
script so the requirement are:

- Docker service (accesible by the user)
- docker-compose script

## Use

The deployment process is very simple and is actualy pretty easy to use.

```
#Execute the lgr container build script
./dockerbuild.sh
#This step should take around 30 minutes and 1 hour the first time.
#The subsequent build should be about a minute as docker had now a build cache
#Start all the lgr microservice
docker-compose up -d
# The startup process can take about a minute the first time
#Create SuperUser (only on the first time)
docker exec lgr-gunicorn ../manage.py createsuperuser --noinput [email protected]
```

Open a browser to http://localhost:8080 and log in with:
- email: [email protected]
- password: 1234

## Update container code

When new code need to be push inside de container, they need to be rebuild with
the new code and the currently running container change with the new image.
```
#Rebuild container (Should be fast if docker build cache still intact)
./dockerbuild.sh
#Reload the new container
docker-compose up -d
```

## Cleanup

Once finish some step are needed to remove all trace on the host computer
```
#Stop and destroy lgr container
docker-compose down
#Remove lgr images
docker image rm lgr-base lgr-django lgr-celery lgr-gunicorn lgr-static
#Remove dependancy images
docker image rm centos:8 redis traefik mariadb
#Remove persitants volumes
docker volume rm dev_lgr-redis dev_lgr-maria dev_lgr-storage
```
110 changes: 110 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
version: '3.9'
services:

lgr-reverseproxy:
container_name: lgr-reverseproxy
image: traefik:latest
restart: unless-stopped
command:
- "--providers.docker=true"
- "--api.dashboard=true"
- "--entrypoints.http.address=:8080"
ports:
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.http.routers.lgr-reverseproxy.entrypoints=http"
- "traefik.http.routers.lgr-reverseproxy.rule=(Host(`localhost`) && PathPrefix(`/reverseproxy`))"
- "traefik.http.routers.lgr-reverseproxy.service=api@internal"

lgr-maria:
container_name: lgr-maria
image: mariadb:latest
restart: unless-stopped
volumes:
- lgr-maria:/var/lib/mysql
environment:
MARIADB_RANDOM_ROOT_PASSWORD: 'yes'
MARIADB_DATABASE: lgr
MARIADB_USER: lgr
#Please don't use Plain password in any kind of production environement
MARIADB_PASSWORD: UNSECURE_DEV_PWD

lgr-redis:
container_name: lgr-redis
image: redis:latest
restart: unless-stopped
volumes:
- lgr-redis:/data
command:
- "redis-server"
- "--appendonly yes"

lgr-gunicorn:
container_name: lgr-gunicorn
image: lgr-gunicorn:latest
restart: unless-stopped
volumes:
- lgr-storage:/var/www/lgr/src/lgr_web/storage
environment:
lgrURL: localhost
lgrMariaDB: lgr
#The email system won't work in dev, but value must be set
lgrEmail: [email protected]
lgrMariaUser: lgr
#Please don't use Plain password in any kind of production environement
lgrMariaPwd: UNSECURE_DEV_PWD
lgrMariaHost: lgr-maria
lgrRedisHost: lgr-redis
lgrRedisPort: 6379
#Again, don't use Plain password in any kind of production environement
lgrSecretKey: UNSECURE_SECRET_KEY
labels:
- "traefik.http.routers.lgr-gunicorn.entrypoints=http"
- "traefik.http.routers.lgr-gunicorn.rule=Host(`localhost`)"

lgr-celery:
container_name: lgr-celery
image: lgr-celery:latest
restart: unless-stopped
volumes:
- lgr-storage:/var/www/lgr/src/lgr_web/storage
environment:
lgrURL: localhost
lgrMariaDB: lgr
#The email system won't work in dev, but value must be set
lgrEmail: [email protected]
lgrMariaUser: lgr
#Please don't use Plain password in any kind of production environement
lgrMariaPwd: UNSECURE_DEV_PWD
lgrMariaHost: lgr-maria
lgrRedisHost: lgr-redis
lgrRedisPort: 6379
#Again, don't use Plain password in any kind of production environement
lgrSecretKey: UNSECURE_SECRET_KEY

lgr-static:
container_name: lgr-static
image: lgr-static:latest
restart: unless-stopped
environment:
lgrURL: localhost
lgrMariaDB: lgr
#The email system won't work in dev, but value must be set
lgrEmail: [email protected]
lgrMariaUser: lgr
#Please don't use Plain password in any kind of production environement
lgrMariaPwd: UNSECURE_DEV_PWD
lgrMariaHost: lgr-maria
lgrRedisHost: lgr-redis
lgrRedisPort: 6379
#Again, don't use Plain password in any kind of production environement
lgrSecretKey: UNSECURE_SECRET_KEY
labels:
- "traefik.http.routers.lgr-static.entrypoints=http"
- "traefik.http.routers.lgr-static.rule=(Host(`localhost`) && PathPrefix(`/static`))"
volumes:
lgr-storage:
lgr-maria:
lgr-redis:
11 changes: 11 additions & 0 deletions dev/dockerbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

#Build container and follow logical link in the build process
Containers="lgr-base lgr-django lgr-gunicorn lgr-celery lgr-static"
#Containers="lgr-django lgr-gunicorn lgr-celery lgr-static"

for it in $Containers
do
#So the logical links files are followed
tar -ch -C $it . | docker build -t $it -
done
6 changes: 6 additions & 0 deletions dev/lgr-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM centos:8
LABEL MAINTAINER [email protected]
USER root

COPY lgr-base.sh .
RUN ./lgr-base.sh && rm lgr-base.sh
Loading

0 comments on commit 1d8b0ab

Please sign in to comment.