From 0662240b311e3ee7c5ef1c8a6fedd5356329c530 Mon Sep 17 00:00:00 2001 From: Freezed Date: Sun, 17 Mar 2019 23:42:18 +0100 Subject: [PATCH] GrandPy realisation --- ...randpy-bot-zappa-flask-lambda-gitlab-en.md | 72 +++++++++++++++++++ .../grandpy-bot-zappa-flask-lambda-gitlab.md | 68 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 content/grandpy-bot-zappa-flask-lambda-gitlab-en.md create mode 100644 content/grandpy-bot-zappa-flask-lambda-gitlab.md diff --git a/content/grandpy-bot-zappa-flask-lambda-gitlab-en.md b/content/grandpy-bot-zappa-flask-lambda-gitlab-en.md new file mode 100644 index 0000000..59f9401 --- /dev/null +++ b/content/grandpy-bot-zappa-flask-lambda-gitlab-en.md @@ -0,0 +1,72 @@ +Title: GrandPy Bot in «serverless» style +Date: 2019-03-16 23:34 +Summary: Evolution of project 7 realized during the OpenClassrooms course with : Zappa, AWS Lambda & Gitlab-CI/Pages. +Category: Réalisations +Lang: en +Slug: grandpy-bot-zappa-flask-lambda-gitlab +Status: Published +Tags: zappa, flask, aws, aws-lambda, gitlab-ci, gitlab-pages, devops, ci, cd, ci-cd, git, bot, api-gateway, python + +This was a [student project][oc] previously hosted on [Github][ocp7]. I updated it to play with : + +* [Zappa][zappa] +* [Flask][flask] +* [AWS Lambda][awslmbd] +* [Gitlab-ci][glci] + +It is a _robot_ grandfather talking about geographic memories and quoting Wikipedia fetching data over public APIs. + +If you can speak French, [have a talk with him][prod] (^_^) + +Run yours ! +----------- + +Need some environment variables to run : + +- `EMAIL_ADDRESS` (Nominatim API) +- `MAPBOX_API_KEY` (Mapbox API) +- `GOO_API_KEY` (not used [but needed][issue51]) + + +### Locally : + +It works as a simple single-page [Flask][flask] application : + +- [fork-it][fork] +- set up a virtualenv : `virtualenv .venv` +- install requirements : `pip install -r requirements.txt` +- run it locally : `python run.py` + +### On Gitlab : + +Set up a [AWS IAM profile][awsiam] on **your AWS account** and add valid environment variables in `https://gitlab.com//grandpy/settings/ci_cd` : + +- `AWS_ACCESS_KEY_ID` +- `AWS_SECRET_ACCESS_KEY` + +Push it back and the _CI script_ will : + +- put chat code on [AWS Lambda][awslmbd] with the magic of [Zappa][zappa] +- edit [JavaScript][js] with the URL of the _AWS API Gateway_ just updated +- generate the HTML landing page (with a [flask script][genstat]) +- deploy statics on _gitlab-pages_ (HTML, images & CSS) + +…and _voilà_, have a chat with _GrandPy_ on `https://.gitlab.io/grandpy/` (-; + +--- + +Feel free to give feedback using [issues][issues]. + +[awsiam]: https://github.com/Miserlou/Zappa/blob/master/example/policy/deploy.json +[awslmbd]: https://console.aws.amazon.com/lambda/ +[flask]: http://flask.pocoo.org/ +[fork]: https://gitlab.com/free_zed/grandpy/forks/new +[genstat]: https://gitlab.com/free_zed/grandpy/blob/master/genstat.py +[glci]: https://gitlab.com/free_zed/grandpy/blob/master/.gitlab-ci.yml +[issue51]: https://gitlab.com/free_zed/grandpy/issues/ +[issues]: https://gitlab.com/free_zed/grandpy/issues/new +[js]: https://gitlab.com/free_zed/grandpy/tree/master/static/js/ask.js +[oc]: {filename}/ocp7.md +[ocp7]: https://github.com/freezed/ocp7 +[prod]: https://free_zed.gitlab.io/grandpy +[zappa]: https://github.com/Miserlou/Zappa/ diff --git a/content/grandpy-bot-zappa-flask-lambda-gitlab.md b/content/grandpy-bot-zappa-flask-lambda-gitlab.md new file mode 100644 index 0000000..2252b4f --- /dev/null +++ b/content/grandpy-bot-zappa-flask-lambda-gitlab.md @@ -0,0 +1,68 @@ +Title: GrandPy Bot à la mode «serverless» +Date: 2019-03-16 23:34 +Summary: Évolution du projet 7 réalisé durant le parcours OpenClassrooms avec : Zappa, AWS Lambda & Gitlab-CI/Pages. +Category: Réalisations +Lang: fr +Slug: grandpy-bot-zappa-flask-lambda-gitlab +Status: Published +Tags: zappa, flask, aws, aws-lambda, gitlab-ci, gitlab-pages, devops, ci, cd, ci-cd, git, bot, api-gateway, python + +Il s'agissait d'un [projet étudiant][oc] précédemment hébergé sur [Github][ocp7]. Je l'ai mis à jour pour jouer avec : + +* [Zappa][zappa] +* [Flask][flask] +* [AWS Lambda][awslmbd] +* [Gitlab-ci][glci] + +Un papy-robot qui parle de souvenirs géographiques et citant Wikipedia. + +Échangez donc [quelques phrases][prod] avec lui (^_^) + +Installez le vôtre ! +-------------------- + +L'exécution a besoin de quelques variables d'environnement : + +- `EMAIL_ADDRESS` (Nominatim API) +- `MAPBOX_API_KEY` (Mapbox API) +- `GOO_API_KEY` (not used [but needed][issue51]) + +### Localement : + +Il fonctionne comme une simple application mono-page [flask][flask] : + +- [forkez-le][fork] +- mettez en place un environement virtuel : `virtualenv .venv` +- installez les dépendances : `pip install -r requirements.txt` +- executez locallement : `python run.py` + +### Sur Gitlab : + +Créez un profil [AWS IAM][awsiam] sur **votre compte AWS** et ajoutez des variables d'environnement valides dans `https://gitlab.com//grandpy/settings/ci_cd` : + +Repoussez le et le script d'intégration continue : + +- déployera le code du _chat_ sur [AWS Lambda][awslmbd] avec l'aide magique de [Zappa][zappa] +- mettra à jour le [JavaScript][js] avec l'URL _AWS API Gateway_ pointant vers _Lambda_ +- génèrera la page d'accueil HTML (avec un [script flask][genstat]) +- déployera les fichiers statiques sur _gitlab-pages_ (HTML, images & CSS) + +...et voilà, vous pouvez maintenant discuter avec _GrandPy_ sur `https://.gitlab.io/grandpy/` (- ; + +--- + +N'hésitez pas à me faire part de vos commentaires via les [tickets][issues]. + +[awsiam]: https://github.com/Miserlou/Zappa/blob/master/example/policy/deploy.json +[awslmbd]: https://console.aws.amazon.com/lambda/ +[flask]: http://flask.pocoo.org/ +[fork]: https://gitlab.com/free_zed/grandpy/forks/new +[genstat]: https://gitlab.com/free_zed/grandpy/blob/master/genstat.py +[glci]: https://gitlab.com/free_zed/grandpy/blob/master/.gitlab-ci.yml +[issue51]: https://gitlab.com/free_zed/grandpy/issues/ +[issues]: https://gitlab.com/free_zed/grandpy/issues/new +[js]: https://gitlab.com/free_zed/grandpy/tree/master/static/js/ask.js +[oc]: {filename}/ocp7.md +[ocp7]: https://github.com/freezed/ocp7 +[prod]: https://free_zed.gitlab.io/grandpy +[zappa]: https://github.com/Miserlou/Zappa/