Commit 507fddfd authored by Aleksander Piotrowski's avatar Aleksander Piotrowski
Browse files

Merge branch 'develop' into 'staging'

Develop

See merge request geoplan/geoankieta!2292
parents 2187eef1 93a445a3
......@@ -24,7 +24,7 @@ indent_size = 2
indent_size = 2
insert_final_newline = ignore
[**/admin/js/vendor/**]
[**/panel_forms/js/vendor/**]
indent_style = ignore
indent_size = ignore
......
......@@ -18,4 +18,11 @@ plugins.sh
/test/*
kubernetes/config.ready.sh
\ No newline at end of file
kubernetes/config.ready.sh
#Python virtual environment
/web/lib/*
/web/bin/*
/web/include/*
/web/local/*
/web/man/*
\ No newline at end of file
......@@ -39,7 +39,24 @@ variables:
ENV: "development"
MINIFY: "True"
test_web:
Dummy test worker:
stage: test
tags:
- test
except:
changes:
- web/**/*
- geoforms/**/*
- panel_forms/**/*
- panel_discuss/**/*
refs:
- develop
- staging
- master
script:
- echo Dummy worker to pass Test stage when no tests were fired.
Test django server:
stage: test
image: $GEOPINE_IMAGE_BACKEND
services:
......@@ -47,12 +64,15 @@ test_web:
alias: test
tags:
- test
only:
changes:
- web/**/*
except:
- tags
- develop
- staging
- master
- schedules
refs:
- tags
- staging
- master
- schedules
variables:
POSTGRES_DB: "test"
POSTGRES_USER: "test"
......@@ -63,19 +83,23 @@ test_web:
- ./web/image/waitfordb.sh
- pip install -r web/src/requirements.txt
script:
- cd web/src/ && ./manage.py test
- cd web/src/
- ./manage.py test
test_geoforms:
Lint geoforms:
stage: test
image: $GEOPINE_IMAGE_FRONTEND
tags:
- test
only:
changes:
- geoforms/**/*
except:
- tags
- develop
- staging
- master
- schedules
refs:
- tags
- staging
- master
- schedules
before_script:
- mv /apps/geoforms/node_modules geoforms/src/node_modules
- cd geoforms/src
......@@ -84,36 +108,42 @@ test_geoforms:
- node node_modules/eslint/bin/eslint.js ./src
- node node_modules/stylelint/bin/stylelint.js "./src/**/*.css"
test_panel_forms:
Lint panel_forms:
stage: test
image: $GEOPINE_IMAGE_FRONTEND
tags:
- test
only:
changes:
- panel_forms/**/*
except:
- tags
- develop
- staging
- master
- schedules
refs:
- tags
- staging
- master
- schedules
before_script:
- mv /apps/panel_forms/node_modules admin/src/node_modules
- cd admin/src
- mv /apps/panel_forms/node_modules panel_forms/src/node_modules
- cd panel_forms/src
- npm install
script:
- node node_modules/eslint/bin/eslint.js ./src
- node node_modules/stylelint/bin/stylelint.js "./src/**/*.css"
test_panel_discuss:
Lint panel_discuss:
stage: test
image: $GEOPINE_IMAGE_FRONTEND
tags:
- test
only:
changes:
- panel_discuss/**/*
except:
- tags
- develop
- staging
- master
- schedules
refs:
- tags
- staging
- master
- schedules
before_script:
- mv /apps/panel_discuss/node_modules panel_discuss/src/node_modules
- cd panel_discuss/src
......@@ -122,45 +152,37 @@ test_panel_discuss:
- node node_modules/eslint/bin/eslint.js ./src
- node node_modules/stylelint/bin/stylelint.js "./src/**/*.css"
build_web_dev:
stage: build
tags:
- build
only:
- develop
except:
- schedules
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- docker pull $GEOPINE_IMAGE_BACKEND
- docker build -t $WEB_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f web/Dockerfile.dev web/
- docker push $WEB_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
build_web:
Build web:
stage: build
tags:
- build
only:
- staging
- master
changes:
- web/**/*
refs:
- master
- staging
- develop
except:
- schedules
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- docker pull $GEOPINE_IMAGE_BACKEND
- docker build -t $WEB_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f web/Dockerfile.release web/
- docker build --no-cache -t $WEB_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f web/Dockerfile.release web/
- docker push $WEB_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
build_geoforms:
Build geoforms:
stage: build
tags:
- build
only:
- develop
- staging
- master
changes:
- geoforms/**/*
refs:
- master
- staging
- develop
except:
- schedules
before_script:
......@@ -170,31 +192,37 @@ build_geoforms:
- docker build -t $GEOFORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f geoforms/Dockerfile.release geoforms/
- docker push $GEOFORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
build_admin:
Build panel forms:
stage: build
tags:
- build
only:
- develop
- staging
- master
changes:
- panel_forms/**/*
refs:
- master
- staging
- develop
except:
- schedules
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- docker pull $GEOPINE_IMAGE_FRONTEND
- docker build --build-arg REACT_APP_HASH=$(date +'%s') -t $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f admin/Dockerfile.release admin/
- docker build --build-arg REACT_APP_HASH=$(date +'%s') -t $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f panel_forms/Dockerfile.release panel_forms/
- docker push $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
build_panel_discuss:
Build panel_discuss:
stage: build
tags:
- build
only:
- develop
- staging
- master
changes:
- panel_discuss/**/*
refs:
- master
- staging
- develop
except:
- schedules
before_script:
......@@ -204,13 +232,17 @@ build_panel_discuss:
- docker build --build-arg REACT_APP_HASH=$(date +'%s') -t $PANEL_DISCUSS_IMAGE_NAME:${CI_COMMIT_REF_SLUG} -f panel_discuss/Dockerfile.release panel_discuss/
- docker push $PANEL_DISCUSS_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
deploy_web:
Deploy web:
stage: deploy
tags:
- deploy
only:
- staging
- master
changes:
- web/**/*
refs:
- master
- staging
- develop
except:
- schedules
environment: develop
......@@ -240,13 +272,17 @@ deploy_web:
- docker exec $WEB_CONTAINER_NAME python manage.py createcachetable
- docker exec $WEB_CONTAINER_NAME python manage.py rebuild_index --noinput
deploy_geoforms:
Deploy geoforms:
stage: deploy
tags:
- deploy
only:
- staging
- master
changes:
- geoforms/**/*
refs:
- master
- staging
- develop
except:
- schedules
environment: develop
......@@ -263,13 +299,17 @@ deploy_geoforms:
-e REACT_APP_API_URL=$API_URL
-e REACT_APP_MEDIA_URL=$MEDIA_URL $GEOFORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
deploy_admin:
Deploy panel_forms:
stage: deploy
tags:
- deploy
only:
- staging
- master
changes:
- panel_forms/**/*
refs:
- master
- staging
- develop
except:
- schedules
environment: develop
......@@ -288,13 +328,17 @@ deploy_admin:
-e REACT_APP_API_URL=$API_URL
-e REACT_APP_MEDIA_URL=$MEDIA_URL $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_REF_SLUG}
deploy_panel_discuss:
Deploy panel_discuss:
stage: deploy
tags:
- deploy
only:
- staging
- master
changes:
- panel_discuss/**/*
refs:
- master
- staging
- develop
except:
- schedules
environment: develop
......@@ -315,7 +359,7 @@ deploy_panel_discuss:
# RELEASE
release_build_web:
Release build web:
stage: build
tags:
- build
......@@ -330,7 +374,7 @@ release_build_web:
- docker build -t $WEB_IMAGE_NAME:${CI_COMMIT_TAG} -f web/Dockerfile.release web/
- docker push $WEB_IMAGE_NAME:${CI_COMMIT_TAG}
release_build_geoforms:
Release build geoforms:
stage: build
tags:
- build
......@@ -345,7 +389,7 @@ release_build_geoforms:
- docker build -t $GEOFORMS_IMAGE_NAME:${CI_COMMIT_TAG} -f geoforms/Dockerfile.release geoforms/
- docker push $GEOFORMS_IMAGE_NAME:${CI_COMMIT_TAG}
release_build_admin:
Release build panel forms:
stage: build
tags:
- build
......@@ -357,10 +401,10 @@ release_build_admin:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- docker pull $GEOPINE_IMAGE_FRONTEND
- docker build --build-arg REACT_APP_HASH=$(date +'%s') -t $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_TAG} -f admin/Dockerfile.release admin/
- docker build --build-arg REACT_APP_HASH=$(date +'%s') -t $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_TAG} -f panel_forms/Dockerfile.release panel_forms/
- docker push $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_TAG}
release_build_panel_discuss:
Release build panel_discuss:
stage: build
tags:
- build
......@@ -378,8 +422,7 @@ release_build_panel_discuss:
-f panel_discuss/Dockerfile.release panel_discuss/
- docker push $PANEL_DISCUSS_IMAGE_NAME:${CI_COMMIT_TAG}
release_deploy_web:
Release deploy web:
stage: release-deploy
only:
- tags
......@@ -419,7 +462,7 @@ release_deploy_web:
- docker exec $WEB_CONTAINER_NAME python manage.py check_sites
- docker exec $WEB_CONTAINER_NAME python manage.py trycreateextendedsuperuser
release_deploy_geoforms:
Release deploy geoforms:
stage: release-deploy
only:
- tags
......@@ -445,7 +488,7 @@ release_deploy_geoforms:
-e REACT_APP_API_URL=$API_URL
-e REACT_APP_MEDIA_URL=$MEDIA_URL $GEOFORMS_IMAGE_NAME:${CI_COMMIT_TAG}
release_deploy_admin:
Release deploy panel_forms:
stage: release-deploy
only:
- tags
......@@ -475,7 +518,7 @@ release_deploy_admin:
-e REACT_APP_API_URL=$API_URL
-e REACT_APP_MEDIA_URL=$MEDIA_URL $PANEL_FORMS_IMAGE_NAME:${CI_COMMIT_TAG}
release_deploy_panel_discuss:
Release deploy panel_discuss:
stage: release-deploy
only:
- tags
......@@ -504,43 +547,34 @@ release_deploy_panel_discuss:
-e REACT_APP_API_URL=$API_URL
-e REACT_APP_MEDIA_URL=$MEDIA_URL $PANEL_DISCUSS_IMAGE_NAME:${CI_COMMIT_TAG}
build_geopine:
Build dummy plug:
stage: build
tags:
- build
only:
changes:
- dummy_plug/**/*
refs:
- develop
except:
- schedules
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- docker build --no-cache -t $GEOPINE_IMAGE_BACKEND -f geopine/Backend.dockerfile .
- docker push $GEOPINE_IMAGE_BACKEND
- docker build --no-cache -t $GEOPINE_IMAGE_FRONTEND -f geopine/Frontend.dockerfile .
- docker push $GEOPINE_IMAGE_FRONTEND
- docker build -t ${CI_REGISTRY_IMAGE}/dummy_plug:${CI_COMMIT_REF_SLUG} -f dummy_plug/Dockerfile dummy_plug/
- docker push ${CI_REGISTRY_IMAGE}/dummy_plug:${CI_COMMIT_REF_SLUG}
# Kuberneties
deploy_to_dev:
stage: deploy
image: alpine:3.7
build_geopine:
stage: build
tags:
- build
only:
- develop
except:
- schedules
environment:
name: dev
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.recoded.co
script:
- apk update && apk add --no-cache curl jq
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl
- mkdir -p $HOME/.kube
- echo -n $KUBE_CONFIG | base64 -d > $HOME/.kube/config
- kubectl config view > /dev/null
- kubectl get job "django-migrate" -o json | jq 'del(.spec.selector)' | jq 'del(.spec.template.metadata.labels)' | kubectl replace --force -f -
- kubectl get job "django-collectstatic" -o json | jq 'del(.spec.selector)' | jq 'del(.spec.template.metadata.labels)' | kubectl replace --force -f -
- sleep 15
- kubectl patch deployment gunicorn -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
- kubectl patch deployment panel-forms -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
- kubectl patch deployment panel-discuss -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
- kubectl patch deployment geoforms -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
\ No newline at end of file
- docker build --no-cache -t $GEOPINE_IMAGE_BACKEND -f geopine/Backend.dockerfile .
- docker push $GEOPINE_IMAGE_BACKEND
- docker build --no-cache -t $GEOPINE_IMAGE_FRONTEND -f geopine/Frontend.dockerfile .
- docker push $GEOPINE_IMAGE_FRONTEND
## Adresses
https://api.k8s.thebitbybit.com | https://api.staging.thebitbybit.com
https://discuss.k8s.thebitbybit.com | https://panel.discuss.staging.thebitbybit.com
https://forms.k8s.thebitbybit.com | https://panel.forms.staging.thebitbybit.com
https://geoforms.k8s.thebitbybit.com | https://geoforms.staging.thebitbybit.com
## Praca w trybie developerskim
Aby `docker-compose` nam działał trzeba się zalogować do rejestru dockerowego. Wystarczy się zalogować raz. Potem już będzie pamiętało że jesteśmy zalogowani.
```
docker login registry.recoded.co
```
Dodatkowo **trzeba** stworzyć network geoankieta
```
docker network create geoankieta
```
___
## Aby stworzyć główny obraz (dotyczy głównie gitlabCi)
```
docker login registry.recoded.co
```
Podajemy login i hasło do gitlaba
następnie budujemy obraz (tag jest bardzo ważny, nie można go zmieniać)
```
docker build -t registry.recoded.co/geoplan/geoankieta/geopine:frontend -f geopine/Frontend.dockerfile .
docker build -t registry.recoded.co/geoplan/geoankieta/geopine:backend -f geopine/Backend.dockerfile .
```
po zbudowaniu możemy wepchnąć go do rejestru (**jeżeli nie wiesz po co to robić, to nie wykonuj teog kroku**)
```
docker push registry.recoded.co/geoplan/geoankieta/geopine:frontend
docker push registry.recoded.co/geoplan/geoankieta/geopine:backend
```
Na registry jest najnowszy obraz z najnowszymi zależnościami.
Gdy nie mamy tego obrazu a go potrzebujemy (np. debug gitlabCi) można go **pobrać**
tak samo jak z zwykłego registry po uprzednim zalogowaniu się.
\ No newline at end of file
# Lopi/Geoankieta / Geodyskusja
[![LOPI](https://lopi.io/wp-content/uploads/2019/02/Zaso%CC%81b-2@3x.png)](https://git.recoded.co/)
Lopi is a unique connection of internet surveys, discussion forums, and digital maps. It brings new possibilities for decision makers, by providing them with a tool for collecting data from citizens and automatically in a real-time analyze them. Thanks to Lopi almost everyone has a possibility to use, formerly available only for professional companies GIS software and statistical analyses.
________________
## Tech
Lopi uses a number of open source projects to work properly:
* Python - 3.7.2
* Django - 1.11.2
* Docker - 18.09.0
* Docker-Compose - 1.23.+
* React - 15.6.1
* Redux - 4.0.+
_______________
## Installation Docker and Docker-Compose
Lopi requires installation of Docker and Docker-Compose. Installation steps for individual operating systems are shown below.
#### Installation for MAC
To use Docker and Docker-Compose You only need to install [Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/install/) (Already include Compose along with other Docker apps, so Mac users do not need to install Compose separately).
#### Installation for Linux
1. Install Docker
This command update the apt package index and install the latest version of Docker Engine:
```sh
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
```
[More info about install Docker](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
2. Install Docker-Copmose
The following commands to download the current stable release of Docker Compose:
```sh
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
```
Apply executable permissions to the binary by:
```sh
sudo chmod +x /usr/local/bin/docker-compose
```
You can check if the installation was successful:
```sh
$ docker-compose --version
```
[More info about install Docker-Compose](https://docs.docker.com/compose/install/)
#### Instalation for Windows
Docker will run ONLY on Windows 10 PRO. If You use Windows 10 Home You need upgrade them to Windows 10 PRO.
In Windows case will be better to install virtual machine(with any Linux distribution e.g [Ubuntu](https://ubuntu.com/download/desktop)) for example [VirtualBox](https://www.virtualbox.org/). After that, fallow the steps as for Linux case.
Make sure you have the virtualization option enabled on your processor. You could check this in BIOS/UEFI or in task manager(in the performance tab).
_____________
## Run Lopi - Developer mode
1. Clone the repository on your device by HTTPS:
```sh
$ git clone https://git.recoded.co/geoplan/geoankieta
```
Or You may use SSH:
```sh
$ git clone git@git.recoded.co:geoplan/geoankieta.git
```
2. To run Docker-Compose you have to log in to the register(provide login details from gitlab):
```sh
docker login registry.recoded.co
docker network create geoankieta
```
3. Build image and run app:
Move to the 'geoankieta' folder:
```sh
cd geoankieta
```
* This step is only for first run app:
```sh
docker-compose up --build
```
* Next time You can run app with:
```sh
docker-compose up
```
_________________________
## Ports - Developer mode
| PORT | SERVICE | DESCRIPTION |
| ------ | ------ | ------ |
| :8000 | API | Beckend for everything |
| :3000 | geoforms | Geoforms app |
| :3001 | panel_forms | Geoforms management |
| :3002 | panel_discuss | Discuss management |
_________________
## Useful commands
* To enter the container
```sh
docker ps
```
Choose the ID of the container you are interested in and input this command:
```sh
docker exec -it CONTAINER_ID bash
```
Or You could enter the container by their name:
```sh
docker exec -it CONTAINER_NAME bash
```
- CONTAINER_NAME for example: geoankieta_web_1
__________________
* Drop database
```sh
docker exec -it geoankieta_web_1 bash
./manage.py reset_db -c --noinput
./manage.py migrate