<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Carlos Espino Timón on Medium]]></title>
        <description><![CDATA[Stories by Carlos Espino Timón on Medium]]></description>
        <link>https://medium.com/@carlosespinotimon?source=rss-7cedd3e36a35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1oW7DWWa-eLEJ9Ul</url>
            <title>Stories by Carlos Espino Timón on Medium</title>
            <link>https://medium.com/@carlosespinotimon?source=rss-7cedd3e36a35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:59:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@carlosespinotimon/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Containerized Development Environment for Flask + Angular + MySQL]]></title>
            <link>https://medium.com/swlh/dockerized-development-environment-for-flask-angular-60719c111f51?source=rss-7cedd3e36a35------2</link>
            <guid isPermaLink="false">https://medium.com/p/60719c111f51</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Carlos Espino Timón]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 06:45:17 GMT</pubDate>
            <atom:updated>2019-11-22T06:27:03.188Z</atom:updated>
            <content:encoded><![CDATA[<h4>Should you use containers and how</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*1Duxf2_pCdRXSaf5iU0bqw.png" /></figure><p>If you look for this topic on the Internet you will see that (as always) there are lovers and detractors about containerize your environment. Obviously it has its benefits and its drawbacks, it is you and your team who has to decide what weights more.</p><p>In this article I will to talk about both the benefits and drawbacks of using a containerized environment, and then I will set up a complete environment with Flask as backend, Angular for the frontend and MySQL as database.</p><h3>Why use it</h3><p>How many times have you ever come to work on a project where you have had to install so many things before write a single line of code? Or how many times have you had dependency problems? your team mate developed something and when you try it it does not work and you realized that you were working with different versions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FkSxTqT5Qvxp60%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FkSxTqT5Qvxp60%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FkSxTqT5Qvxp60%2F200w.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="440" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bc39f7bab53e6b925ade23fee3aaa4a/href">https://medium.com/media/8bc39f7bab53e6b925ade23fee3aaa4a/href</a></iframe><p>To me, these two were the big selling points. This is why I started thinking about containerized my environment in the beginning. To help newcomers working in the project, as they will just need to have installed Docker and docker-compose (you will see in the example) and to prevent dependency problems, as everyone will work in the same environment which is under version control system. But obviously, that’s not all.</p><p>Unless you have a project under .asp or .net technology, you will probably deploy in a Linux server. If you containerized your environment you will have a much more consistent environment. You can have developers developing in almost the same developing and production environment despite the OS they use eliminating cross-platform compatibility issues almost completely. What’s more, with a containerized environment you can reproduce production behaviors and escalate the services starting more containers and see how they behave.</p><p>On of the things that from my point of view is really important to is that when you containerize your environment you will face integration problems since the beginning, in an early stage, with plenty of time an a lot of room for changes.</p><h3>Why not use it</h3><p>I have to be honest, I have no much experience in real live with this. Just what I have learnt by myself in my free time, and a small project at work where I started to create a development environment just like the one I am about to explain in the following section.</p><p>However I have look for this topic on the Internet and after reading a few articles and discussions I mainly agree in two points. In one hand, it increases the complexity as adds a new layer. The developers have to adapt to a new way of working as everything must be run inside the container. In the other hand it can reduce performance, I read one discussion that pointed out that if you use Docker from Mac you could experience a significantly worse performance than a native environment when working with mounted volumes. You can see the <a href="https://docs.docker.com/docker-for-mac/osxfs-caching/">Docker documentation</a> talking about it.</p><p>Another area that it’s tricky is security but I will not discuss in depth any of this as this is a topic that I know very little and I prefer to shut down than look like a fool. I will just comment three things: First, you will see that I use Alpine Linux, which is a security-oriented, lightweight Linux distribution; second, I create the image with a root user bu then I use a user without root privileges that is the one that runs the containers; and third, I have no third point, but when talking about security in containers this videos always comes to my mind:</p><h3>Sylvia van Os on Twitter</h3><p>Sysadmins: &quot;It&#39;s secure because it&#39;s in a container&quot; Hackers: https://t.co/3MgS9jX2Ky</p><h3>Example of containerized environment</h3><p>Now is play time. As I mentioned at the beginning I will configure a stack with Flask, Angular and MySQL. It consists in a backend with a simple CRUD for dishes that store them in a MySQL database and a simple frontend that just displays the stored dishes, both services have even a few tests.</p><blockquote>The backend uses the <a href="https://www.sqlalchemy.org/">SQLAlchemy ORM</a> to connect with the MySQL database, I will not talk about it as the article will be too long, you can see the code to see how is configured. If you have any question you can ask :)</blockquote><p>You can find the complete code in my <a href="https://github.com/CarlosEspinoTimon/containerized-environment">repository</a>.</p><p>I this section I will show you the Dockerfile of each service (but MySQL as it is just a public image), then the docker-compose file that orchestrates all the services and its communications, a Makefile that simplifies the interactions with the running containers and how to debug the code running inside the container with Visual Code.</p><p>Let’s begin with it!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F4529720&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fminions-football-play-oops-wong-ball-gif-4529720&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F15d84f2bec26271698f9f764baaa4c07%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/02567d1abad36d840201a93921c1b65d/href">https://medium.com/media/02567d1abad36d840201a93921c1b65d/href</a></iframe><h4>1. Dockerfiles</h4><p>As I mentioned before, each service will be in it’s own container. The database will be created from a public images, but the backend and frontend will be created from an image that I will declare.</p><p><strong>Backend</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bf1229930b98477604e174b84fb7628/href">https://medium.com/media/8bf1229930b98477604e174b84fb7628/href</a></iframe><p><strong>Frontend</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/baf86ab127eb107bd6d4c3a15df682ac/href">https://medium.com/media/baf86ab127eb107bd6d4c3a15df682ac/href</a></iframe><p>If you look closely you will see that in both cases I am using <a href="https://hub.docker.com/_/alpine">alpine images</a>.</p><blockquote>A minimal Docker images based on Alpine Linux with a complete package index and only 5 MB in size!</blockquote><p>What is Alpine Linux?</p><blockquote>Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox. <a href="https://alpinelinux.org/">https://alpinelinux.org/</a></blockquote><p>Cool isn’t it. At the beginning I used Ubuntu images where I installed everything I needed and each service container could weight around 1,5Gb and now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*a1CtO4t-L76XF-rU9fmOdA.png" /></figure><p>Probably someone with more experience would shrink it even more. I have seen containers much smaller but not with the ability to listen to changes you made in your host machine, in these cases when you make a change you must rebuild the image, with my containers it will just reload the code.</p><h4>2. Docker-compose</h4><p>I use docker-compose to orchestrate all the containers integrated in my environment.</p><blockquote>Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.</blockquote><blockquote><a href="https://docs.docker.com/compose/">https://docs.docker.com/compose/</a></blockquote><p>Here is it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/370c3a1df933f2b7e2dff75d7dedac6d/href">https://medium.com/media/370c3a1df933f2b7e2dff75d7dedac6d/href</a></iframe><p>Now that I have the Dockerfiles and the docker-compose, I can run from the <em>development_environment</em> directory:</p><pre>docker-compose up</pre><p>The first time, this command will build the images for each service and start them.</p><blockquote>If you make a change in the Dockerfile you must rebuild the image. You have two possibilities:</blockquote><blockquote>docker-compose up --build</blockquote><blockquote>docker-compose build and then docker-compose</blockquote><p>Once is finished, you can check that everything is working by visiting:</p><p><em>http://localhost:5000/</em> for the backend:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*tunkrCnpOX-XSeu_ZdxeEQ.png" /></figure><p>and <em>http://localhost:4200/</em> for the frontend:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*_jP0K_tteZLhg0iTQGi4_w.png" /></figure><p>As I said before, for this article I have created a dummy CRUD for dishes in the backend and a simple frontend where display the dishes stored in the database, it is not prepared to create dishes from the frontend as it is not the scope of this article.</p><blockquote>You can create dishes by making a POST request to <em>localhost:5000/api/dishes</em>. You can see and example in <em>backend/server/controllers</em></blockquote><p>If you click in the frontend menu, you can visit the Dishes page and see the stored dishes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*teDNeQhiW118mjxhI8U4MQ.png" /></figure><h4>3. Makefile</h4><p>As I said before, one of the drawbacks of working in a containerized environment is that everything have to be run inside the container.</p><p>To do so, you have 2 possibilities, you can get into the container (and then run the command):</p><pre>docker exec -it CONTAINER_ID sh</pre><p>or you can run the command inside the container from out site:</p><pre>docker exec -t CONTAINER_ID command to run</pre><p>As this is a little tedious, first you have to get the CONTAINER_ID and then run the command, that’s why I always like to create a Makefile where define some easy commands that Make translates them to the complicated ones:</p><p>This is an example of the Makefile, if you want to see the complete Makefile, just go to my repo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c18b188982892c7440527f408775838d/href">https://medium.com/media/c18b188982892c7440527f408775838d/href</a></iframe><p>With this, if a developer want to get into the backend to execute something, just runs:</p><pre>make backend-access</pre><h4>4. Debug</h4><p>As soon as you start having any problem during development, it’s a must to be able to debug your code. This was a tricky part, because you want to put some breakpoints in the code hosted in your machine, but you want to debug a code that is running inside the container (remote).</p><p>In this article I will explain how to configure Visual Studio Code for debug in this situation. I am going to show you the <em>launch.json</em> file that is used to configure the debugger.</p><p><strong><em>Backend</em></strong>:</p><p>This is the <em>launch.json</em> for the backend:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/341025741366d94b7710c306141fbed5/href">https://medium.com/media/341025741366d94b7710c306141fbed5/href</a></iframe><p>Here the magic is in the <em>pathMappings</em>, as we can see, is mapping the local files in the host with the remote code in the container. It is important to mind from where you open the Visual Studio Code.</p><blockquote>In this case I opened from the root of the project, if you like to open each service code in a different Visual Studio Code, you must change the localRoot to “${workspaceFolder}/server/”.</blockquote><p>For the backend I will need to start the server in a different way, adding the ptvsd (the module use for debug) and sharing other ports. In the repo, there is another docker-compose file that configures all its needed for this situation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7b39e1890dc399eced3e2714866d7b1/href">https://medium.com/media/c7b39e1890dc399eced3e2714866d7b1/href</a></iframe><p>As you can see it shares some ports, execute a command that uses the ptvsd module and connects to the network were is already running the database.</p><blockquote>Beware that you must have in your host machine the same ptvsd version than the one that is running in the container, this is the only dependency that you will have in your machine. You can find out the version in the backend/Pipfile.log.</blockquote><p>Once again, there is a command in the Makefile that simplifies this action. You can just run:</p><pre>make backend-debug</pre><blockquote>When you want to start the services declared in a docker-compose file but with a diferent name, you have to run docker-compose -f filename up.</blockquote><p>Let’s see it working. As you can see, there is a home endpoint that just returns <em>‘The server is running!!’</em> I can put some dummy code to see the debugger working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*X6fshd6rw_kJ6T6CZSFl0g.png" /></figure><p>The steps are:</p><ol><li>Start the debugger with the command <em>make backend-debug</em></li><li>Start the debugger in Visual Studio Code with the Backend debug configuration</li><li>Visit <em>localhost:5001/</em></li></ol><p>This will make the code stop at the break point and make us really happy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*oYRJsXratkE_hKZVoZIvXw.png" /></figure><p>Sorry we have to stop, is time to dance:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F13hxeOYjoTWtK8%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F13hxeOYjoTWtK8%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F13hxeOYjoTWtK8%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/85037ee96ff81142780f31ad864479a3/href">https://medium.com/media/85037ee96ff81142780f31ad864479a3/href</a></iframe><p><strong><em>Frontend</em></strong>:</p><p>For the frontend, first I need to install an extension in Visual Studio Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*soIEs_D1UrlHE73OyGDl0Q.png" /></figure><p>In this case I need to configure the <em>launch.json</em> file too to declare a new configuration. As there is already a configuration for the backend, I just added the new one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98b388ffdb92c2d81e548744c8a8583c/href">https://medium.com/media/98b388ffdb92c2d81e548744c8a8583c/href</a></iframe><p>Then, I just need to start the <em>Frontend debug </em>configuration<em> </em>and a new window will open. Let’s see it working!</p><p>I left a button in the homepage of the frontend that says “Debug me!”, so let’s listen to the poor button. I can put a break point in its function (<em>home.component.ts)</em>, start the debugging and hit the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkfaLMVhlU0atEJarC5Qvw.png" /></figure><p>The debugger stopped at the break point :)</p><p>That’s it, we are ready to go, but before we keep going, we need to dance again:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fpa37AAGzKXoek%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fpa37AAGzKXoek%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fpa37AAGzKXoek%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/b482fceb5979f796ed62c2f45677e611/href">https://medium.com/media/b482fceb5979f796ed62c2f45677e611/href</a></iframe><h3>We have talked about</h3><p>We have come a long way. In this article I have talk about:</p><ul><li>the benefits and the drawbacks of a containerized development environment</li><li>the necessary Dockerfiles to containerize the services (Flask backend and Angular frontend) which were build from alpine images</li><li>the docker-file that help us to manage and configure the containers</li><li>the Makefile and how can help us to interact with the containerized services</li><li>how to debug the code running in the containers</li></ul><h3>Conclusions</h3><p>Now that you have reach the end of the article, you should ask again, should you containerize our development environment?</p><p>You must analyze the situation with the rest of the team to see what weights more. As we have seen through the article, in one hand, the containerized environment give you a consistent environment between developers and between development and production, reducing dependency problems. In the other hand, is true that it might complicate a little the workflow and in some cases it can reduce the performance (as everything is run inside the container).</p><p>For my little experience, in the projects I have work in, I thing it’s worth it!</p><p>That’s it, if you have reach the end of the article, and read everything, thank you, it was a long one:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F4EF5xIO5yiivWh4gGn%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F4EF5xIO5yiivWh4gGn%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F4EF5xIO5yiivWh4gGn%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81b65341fd33841d2212646b54536c9/href">https://medium.com/media/c81b65341fd33841d2212646b54536c9/href</a></iframe><h3>Annotations</h3><ul><li>If you want to see the code you can visit my <a href="https://github.com/CarlosEspinoTimon/containerized-environment">repo</a>.</li><li>All the <strong>make commands</strong> must bu run form <em>development_environmet/</em></li><li>If you see that you are not able to set the break point, or as soon as you start the debugger, the break point change:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*-qAr-9QWAEFCQyTpbVdslQ.png" /></figure><p>This is probably because you have set the wrong <em>webRoot</em> or <em>pathMapping</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60719c111f51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/dockerized-development-environment-for-flask-angular-60719c111f51">Containerized Development Environment for Flask + Angular + MySQL</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[if not schema.validate(data): print(“Validation rules”)]]></title>
            <link>https://medium.com/swlh/if-not-schema-validate-data-print-validation-rules-dbb8df4f8cb7?source=rss-7cedd3e36a35------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb8df4f8cb7</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[marshmallow]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Carlos Espino Timón]]></dc:creator>
            <pubDate>Wed, 25 Sep 2019 06:03:16 GMT</pubDate>
            <atom:updated>2019-10-03T15:21:24.999Z</atom:updated>
            <content:encoded><![CDATA[<h4>Trust no one, even yourself, validate everything</h4><p>When we implement an API it’s important to check whether the data we are receiving in an endpoint is the kind of data we are expecting. Even if you have developed some validation in the client side, you should not trust data coming from it. The mechanism of validation in the client side can have a bug or someone could be interacting directly with the API through curl or Postman and try to run malicious code such a SQL Injection attack.</p><p>If we validate our data we ensure that it is consistent, accurate and complete, so it will prevent for data loss and error during its manipulation. If we don’t validate the data in the API we can end up with malicious data, breaking the integrity of our database or sending back unuseful http responses.</p><h3>What are we going to do</h3><p>First, we are going to write a simple API with the classic CRUD (Create, Read, Update and Delete) for handling Social Events using Python (I think you had already guess it by the title of the article) with Flask (a lightweight web framework). I say simple because we are not going to configure any fancy thing such as SQLAlchemy (the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL) or implement a login system or tests as it would be out of the scope of the article.</p><p>Once implemented we will use marshmallow and we will compare the validation of data in both cases.</p><h3>Configuration of initial server</h3><p>Let’s suppose this are the requirements of the social events:</p><ul><li>name: The name of the event (required, no longer than 100 characters)</li><li>description: The description of the event (required, no longer than 1000 characters)</li><li>organizer: The organizer of the event (optional, no longer than 100 characters)</li><li>datetime_of_ovent: The date and time of the event (required)</li></ul><p>If you want to see the complete server you can visit my <a href="https://github.com/CarlosEspinoTimon/validator_example/tree/without-marshmallow">repository</a> however, given that we are talking about validation of data, here we will see just the code for two endpoints, create and update, the ones that receive data.</p><p>Here is the relevant code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca6ef4686718a1271248724c0a186d33/href">https://medium.com/media/ca6ef4686718a1271248724c0a186d33/href</a></iframe><blockquote>Before we start talking about the validation I would like to point out how cool is the new feature released in Python 3.8, the walrus operator ( := ) which allows me to do an assignment expressions and save me one line :)</blockquote><blockquote>You can see what’s new in Python 3.8 in <a href="https://docs.python.org/3.9/whatsnew/3.8.html">here</a>. Now let’s validate!</blockquote><p>As we can see in the code, we have to validate each parameter that we will be receiving and processing, we have to check if the required fields are present and if they meet the requirements.This is a small example with an entity that just has 4 parameters and it is making us to write a lot of lines, image if we have more complicated entities…</p><p>Here is when comes handy things like marshmallow:</p><blockquote><strong>marshmallow</strong> is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.</blockquote><blockquote>In short, marshmallow schemas can be used to:</blockquote><blockquote><strong>- Validate</strong> input data.</blockquote><blockquote><strong>- Deserialize</strong> input data to app-level objects.</blockquote><blockquote><strong>- Serialize</strong> app-level objects to primitive Python types. The serialized objects can then be rendered to standard formats such as JSON for use in an HTTP API.</blockquote><p>As we can see, marshmallow is giving us the possibility to validate our input data. Neat!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F111ebonMs90YLu%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fthumbs-up-111ebonMs90YLu&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2F111ebonMs90YLu%2F200.gif%3Fcid%3D790b761191fe68668b29552b22aa9804af12098964fe86f1%26rid%3D200.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5c6140ba1613c7369490c27d11b1a6f/href">https://medium.com/media/a5c6140ba1613c7369490c27d11b1a6f/href</a></iframe><h3>Configure Marshmallow</h3><p>Let see what should we do to use it.</p><p>First we write the Schemes for our Event model. We will implement one for the Create Event and another for the Update Event, as both have different required fields.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c93ba58bcf2471a2f3b646ffa51fa97/href">https://medium.com/media/6c93ba58bcf2471a2f3b646ffa51fa97/href</a></iframe><p>Then we can easily validate the data in our endpoints:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c1e0f6e5455279d2c33f8f8a24b7aea/href">https://medium.com/media/8c1e0f6e5455279d2c33f8f8a24b7aea/href</a></iframe><p>As we can see there are clearly less code to write :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F4840096&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fself-five-barney-himym-gif-4840096&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F31031ba78338c142795e6486b5049217%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c114e92eccdbc09667348314857c73be/href">https://medium.com/media/c114e92eccdbc09667348314857c73be/href</a></iframe><p>But for the moment this is just theory, let’s play with it and see how it works!</p><p>As we expected we can create an events as before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*gJyd9CS4fjG2tpN6DNIgaA.png" /></figure><p>However, if we try to create one with a field longer than required, a different type or if we miss a required parameter, marshmallow will tell us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*UGxuIkP_sqqYonNl_PG5kg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5122518&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Famazing-amazed-chrispratt-gif-5122518&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2F64966c88400e1e629bf95dbc75e5f41e%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/53cd85770cc80503f013a06963631a32/href">https://medium.com/media/53cd85770cc80503f013a06963631a32/href</a></iframe><h4>Custom checks</h4><p>These are pretty straight forward checks, but what if we want to check more complicated things. What if we want to check if the date of the event is a date in the future and no more than one year in advance?</p><p>With marshmallow we can implement our own validation functions (you can check it out in the <a href="https://marshmallow.readthedocs.io/en/stable/quickstart.html#validation">documentation</a>) but for this example, we will write our validator as a method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/572ae3199234e1c69abd9c4c7bdc9d1d/href">https://medium.com/media/572ae3199234e1c69abd9c4c7bdc9d1d/href</a></iframe><p>Let’s try it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*tpmj1_5zbtS67VFVH2MI7Q.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5089552&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Foscars-standing-ovation-clap-clapping-applause-gif-5089552&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fc9143af696b8a748041800151d83013b%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f0f0128f1591d31e2d1ebfa60d29653/href">https://medium.com/media/6f0f0128f1591d31e2d1ebfa60d29653/href</a></iframe><h3>Conclusion</h3><p>Validation is a must. Is a good practice that should be implemented in any API as it will improve the security, make it more robust and it will offer a better interaction with it’s users giving them a better response explaining the errors.</p><h4>Source code</h4><p>If you want to check out the code used for this article you can visit my <a href="https://github.com/CarlosEspinoTimon/validator_example">repository</a>. The code for the first part is in the without-marshmallow branch, and the rest is in the marshmallow branch.</p><p>If you want to see a more complicated configuration with a real database an a ORM such as SQLAlchemy stay tuned for my next article where I will show you how to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb8df4f8cb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/if-not-schema-validate-data-print-validation-rules-dbb8df4f8cb7">if not schema.validate(data): print(“Validation rules”)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git hooks]]></title>
            <link>https://medium.com/swlh/git-hooks-cc07908cd54?source=rss-7cedd3e36a35------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc07908cd54</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[git-hooks]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Carlos Espino Timón]]></dc:creator>
            <pubDate>Mon, 08 Jul 2019 05:30:48 GMT</pubDate>
            <atom:updated>2019-07-09T21:06:34.423Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*bAJrSit_8HoM5sy7ydw0zw.png" /></figure><p>The other day I was talking with a coworker and he was telling me about a project that he had worked in where he had to dealt with git hooks. He explained me that his code had to pass all the tests before pushing anything, and to be honest, it amazed me!</p><h3>What are git hooks</h3><p>I started to dig about it and the first thing I did was to look for what git hooks really are:</p><blockquote>Git hooks are scripts that Git executes before or after events such as: <strong>commit</strong>, <strong>push</strong>, and <strong>receive</strong>. Git hooks are a built-in feature — no need to download anything. Git hooks are run locally.</blockquote><blockquote><a href="https://githooks.com/">https://githooks.com/</a></blockquote><p>Now that I know this concept, it’s pretty clear that in my coworker’s project there is a git hook with a script that runs the tests before the push, if they pass, the push is completed. Sweet, isn’t it?</p><p>With git hooks we can ensure that any code to be pushed won’t break what is already working. Imagine that we are in a project where when we push our code to develop, it triggers a pipeline that runs the tests, checks the code quality, builds the project and deploys it. If we have been pushing bad code to our branch, the moment we merge it with develop and push it, it will break the pipeline as it will not pass the tests. This is an awkward moment for us, as it tells our teammates that we haven’t been running the tests to check whether our code had broken something that was already working. If we’d had configured the git hooks, it would have saved us this uncomfortable moment.</p><p>Once I understood this useful use case of git hooks it rapidly came to my mind another handy hook that could be configured. What if we can restrict the days on which we can upload code to some branches?</p><p>As in the previous example, imagine that we have a pipeline that in the end, deploys our app to production. Presumably, the code we pushed is perfect, as it has passed all the tests, however, sometimes new problems not checked by the tests arise, and our app starts to fail and what’s more… it’s Saturday and there is no one in the office.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FENt72LgUE2gV2%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FENt72LgUE2gV2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FENt72LgUE2gV2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b473347513a532389b5094bdba58dea/href">https://medium.com/media/6b473347513a532389b5094bdba58dea/href</a></iframe><p>With git hooks we can control the “allowed days” to push to the specific branch that triggers the pipeline, for example, we could allow it from Monday to Thursday because we will always have someone in the office the day after the app is deployed to solve any problem.</p><p>With these two cases, I think we have enough to play with, so… let’s get our hands dirty! I have created a repository to work with the hooks, the code can be checked <a href="https://github.com/CarlosEspinoTimon/pre-push">here</a>.</p><h3>How to configure the hooks</h3><p>First of all, we need to know how to “install” a hook.</p><blockquote>The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that’s .git/hooks. When you initialize a new repository with git init, Git populates the hooks directory with a bunch of example scripts, many of which are useful by themselves; but they also document the input values of each script. All the examples are written as shell scripts, with some Perl thrown in, but any properly named executable scripts will work fine — you can write them in Ruby or Python or what have you. If you want to use the bundled hook scripts, you’ll have to rename them; their file names all end with .sample.</blockquote><blockquote><a href="https://git-scm.com/book/uz/v2/Customizing-Git-Git-Hooks">https://git-scm.com/book/uz/v2/Customizing-Git-Git-Hooks</a></blockquote><p>Every git repository has a few default hooks, they are placed in the .git/hooks directory. Let’s check it out in an empty repository that I have just init:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*_nGLBa4O1TZQz_gn" /></figure><p>As we can see, when we init a repository it comes with some sample hooks. All of them come with the .sample extension, if we want to activate a hook we just have to remove the .sample extension. Easy, isn’t it?</p><p>There are lots of hooks that could be really useful but in this post I will just talk about two, pre-commit and pre-push.</p><h3>Git pre-commit</h3><p>Let’s start with the first example I talked about, the hook that controlled that our code passed the tests before pushing it, however, I will configure my hook to do it before any commit. With this approach I see two advantages, in one hand, it will ensure that all our code that has been tracked by git is good and passes the tests, in the other, it saves us having to be fixing everything in the last minute before we push, forcing us to commit chunks of “good code”.</p><p>After removing the .sample extension of the pre-commit.sample hook, and replace it with the code we want to be executed, this is the result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/340b3ece2ba8618f1958a43f355b1a68/href">https://medium.com/media/340b3ece2ba8618f1958a43f355b1a68/href</a></iframe><blockquote>I will not get into detail about my development environment as is irrelevant for the scope of this post. I am just going to say that I am becoming a container freak (I’m starting to use Docker for everything) and to facilitate the execution of some commands that have to be run inside the container I usually create a Makefile. In this case, I the tests must be run from within the local_environment directory with the make backend-tests command.</blockquote><p>That’s it, this is the hook. We run the test and the result is used as output of the script, if the tests passed we can commit.</p><p>Let’s see it in action. I have changed a test to not pass, and I will try to commit my code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uFey_jxO0RdoaOET" /></figure><p>As we can see, the commit run the tests and as I did not passed them, the commit was not made.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F6nuiJjOOQBBn2%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fparty-how-i-met-your-mother-applause-6nuiJjOOQBBn2&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F6nuiJjOOQBBn2%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="249" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5aae6797ea9d77b8bc75cb8479b6ec0/href">https://medium.com/media/e5aae6797ea9d77b8bc75cb8479b6ec0/href</a></iframe><p>Let’s fix the test to see how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SiLIPnwGbS5H4cZm" /></figure><p>Perfect there was a successful execution of the tests and the commit was made :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FLZElUsjl1Bu6c%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FLZElUsjl1Bu6c%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FLZElUsjl1Bu6c%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2c169e6abb6fbe16b99edf5bb16f0bc/href">https://medium.com/media/a2c169e6abb6fbe16b99edf5bb16f0bc/href</a></iframe><h3>Git pre-push</h3><p>With this hook I am going to control two things: first, that I will never push something to the master branch, and second that the pushes to develop must be done from from Monday to Thursday. Here is the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5d67bfc754e6752dc0a1a08e14293be/href">https://medium.com/media/f5d67bfc754e6752dc0a1a08e14293be/href</a></iframe><p>Now let’s see it in action, I am going to try to push something to master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/0*PvGWD2ReV9j40NCq" /></figure><p>As we can see, the hook blocked the push to master. Now to try the restriction by days I will modify the hook to control master instead develop (as I do not have develop branch in this project) and remove the first restriction that forbids to push to master.</p><p>This is the new hook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ced6ee7e401c32f7593d550e1116132c/href">https://medium.com/media/ced6ee7e401c32f7593d550e1116132c/href</a></iframe><p>Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*i1b3Nhsumkythd5h" /></figure><p>Today is Friday and the hook blocked the push :)</p><p>This is really cool, all the team could configure the same hooks and it would increase the quality of the code that is tracked by git and also prevent problems in production. However, sometimes we will be in a situation where we must to commit or push even if our code has a bug or if is Friday and this hook could be our worst friend. Do not worry, there is a way to avoid the hooks!</p><h3>Skip hooks</h3><p>You probably have noticed that in the first line of both hooks there is an echo line that explains how to avoid the hook.</p><pre>Skip pre-push hooks with --no-verify (not recommended)</pre><p>If we do our commit or push with the flag — no-verify, the hooks will be ignored.</p><p>Let’s see it in action. I’ll try to push something to master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/0*cX1LubJWc-ab3W84" /></figure><p>The first push was blocked by the hook, in the second I used the flag --no-verify and I could do the push.</p><h3>How to share it with the team</h3><blockquote>Maintaining hooks for a team of developers can be a little tricky because the .git/hooks directory isn’t cloned with the rest of your project, nor is it under version control. A simple solution to both of these problems is to store your hooks in the actual project directory (above the .git directory). This lets you edit them like any other version-controlled file. To install the hook, you can either create a symlink to it in .git/hooks, or you can simply copy and paste it into the .git/hooks directory whenever the hook is updated.</blockquote><blockquote><a href="https://www.atlassian.com/git/tutorials/git-hooks">https://www.atlassian.com/git/tutorials/git-hooks</a></blockquote><p>As we can see, the hooks’ directory isn’t tracked by git, with the solution given by Atlassian, we could have a version control of the hooks. However, regarding the solution to install the hook, I prefer to configure the hookspath, an option that is available since Git 2.9.</p><p>In my repository I have created a directory .githooks/ where I have put both hooks, so now are tracked, then I configured the hookspath by running:</p><pre>git config core.hooksPath .githooks</pre><p>For now on, every developer that starts working in this project, it will have to run this command to configure the hookspath and use the hooks tracked by the repository.</p><h3>Conclusion</h3><p>Git hooks are a powerful tool that, configured in the right way, can help us to improve our code quality, protect branches or forbid some actions given specific situations. In this post I have talked about two hooks but there are much more such us pre-rebase, a hook that could stop a rebase if not desirable, or post-merge, a hook that could check whether after the merge there is new dependencies and reminds you to install them (or even install them). You can see a list of the hooks you can attach scripts to <a href="https://githooks.com/">here</a>.</p><p>Now we have to stop for a moment to think in what we could control to improve our workflow, how could we control it from a script and when to control it.</p><p>So, tell me, what do you already control or would like to control with git hooks?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc07908cd54" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/git-hooks-cc07908cd54">Git hooks</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Angular template to create your Virtual Curriculum Vitae]]></title>
            <link>https://levelup.gitconnected.com/an-angular-template-to-create-your-virtual-curriculum-vitae-587f8700247d?source=rss-7cedd3e36a35------2</link>
            <guid isPermaLink="false">https://medium.com/p/587f8700247d</guid>
            <category><![CDATA[app-engine]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Carlos Espino Timón]]></dc:creator>
            <pubDate>Tue, 25 Jun 2019 05:06:23 GMT</pubDate>
            <atom:updated>2020-01-08T10:03:23.342Z</atom:updated>
            <content:encoded><![CDATA[<p>For some time I have been thinking about making my own personal website, something like a virtual CV where I could talk about me, my experience, or my personal projects. Spoiler alert, <a href="https://carlos.espino.codes/">I did it</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ifZNxEixHA0ymOq2ow27A.png" /></figure><p>I started working in order to improve my frontend skills, and this little project could serve as training. However, as time passed I changed my mind. I realized that I could expand its potential, and share it as a template for others, so anyone could use my code to create their own virtual CV by just filling information in some files.</p><p>Sounds cool doesn’t it? Let me explain to you how can you do it, but first, let’s start by talking a little about the technology and how the app is structured.</p><p>The website is developed in Angular, an open-source web application framework developed by Google, and to be more specific, <strong>Angular 7</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/109/1*i8QlQY2ux0PWWzs36NR4_w.png" /></figure><p>As a Full Stack Developer, and in the latest projects, I have been working with Angular as the main tool for the frontend. Maybe saying this sounds like I should already have mastered the framework, but, between us, I will tell you the truth. I am more of a backend guy, so in this project I intended to do work more in the backend while my co-worker (a frontend guy) did the frontend things. I am not saying that I didn’t do anything in the front, I have created lots of components, services, interfaces, tests… but all the complex things like structuring the app in modules, routing, interceptors… was made by my co-worker so, I decided that it was time to learn how to do it so here I am.</p><h3>How is structured</h3><p>The app is divided into 7 modules (About, Training, Experience, Skills, Projects, Articles, and Contact), each module contains its own models, services, components and, as one of the most important features in order to create a module, a routing and a module file. I know that this is a really simple app and I could just have put everything in the same module and the app would have run smoothly. However, as I just wanted to practice and learn how to do it, I did it this way.</p><p>Separating your app in modules is neat, it helps you to organize the app and makes your code shareable and reusable (as the modules contains all the logic they need), but that’s not all, if you use lazy loading — a design pattern that loads the modules as needed — to load your modules, it will keep initial bundle sizes smaller, which in turn helps decrease load times, as it loads the modules just when they are needed, instead of when the app starts.</p><blockquote>By default, NgModules are eagerly loaded, which means that as soon as the app loads, so do all the NgModules, whether or not they are immediately necessary. For large apps with lots of routes, consider lazy loading — a design pattern that loads NgModules as needed. Lazy loading helps keep initial bundle sizes smaller, which in turn helps decrease load times.</blockquote><blockquote>Extracted from <a href="https://angular.io/guide/lazy-loading-ngmodules#lazy-loading-feature-modules">Angular guide</a>.</blockquote><p>If you want to learn how to do it, you can visit the <a href="https://angular.io/guide/lazy-loading-ngmodules">official documentation</a>.</p><p>As I mentioned at the beginning of the post, the main reason of this project changed to a shareable virtual CV, so let me tell you how can you do it.</p><h3>Would you like to use it as a template?</h3><p>After cloning the project, to use it as your virtual CV, you only need to change 3 things:</p><ol><li>The information:<br>In the vcv_client/src/assets folder, you will find all the JSON files that you have to modify in order to show your personal information. This is loaded into each module’s service as soon as the module is loaded.</li><li>The title:<br>If you don’t want my name in the browser tab (I don’t mind if you leave it there hehe), you have to go to the index.html and put whatever title you want to be displayed in the &lt;title&gt; tag.</li><li>The about-me section:<br>This is the area where you have to do the more by yourself, as you literally have to create your own about-me section.</li></ol><p>Regarding the styling, you have two possibilities, you can use the master branch as you template and use mine, or you can use the feature/cv_template, which has no styles applied and do all the fancy stuff by yourself.</p><p>With these changes, you are ready to go, you can deploy and be ready to start receiving visits :) But… I imagine that you would like to see your app before you deploy it, so let me explain to you how you could try it locally.</p><h3>Try the app locally</h3><p>In this section, I would like to talk about my development environment.</p><p>I don’t have much experience (barely 2 years), but I have realized that as you work in more projects, you end up having in your computer a lot of different versions of Java, Python, Angular… Sometimes it’s tedious to be selecting the exact version you want to use to be able to run the specific app properly.</p><p>That’s why I like to containerized my environment with <strong>Docker</strong> and orchestrate everything with <strong>docker-compose</strong>, then I just have to run a command and I have the app running in the environment I want without any dependency problem. What’s more, this is easily shareable with your co-workers helping the team to focus just on the development and facilitating the entry of new developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*hhhPz9USSywTI3g_x5S75g.png" /></figure><p>In the <a href="https://github.com/CarlosEspinoTimon/vcv">repository</a>, there is a folder named local_environment. In this folder you’ll find a <strong>Makefile</strong> that will help you communicate with the containers, a <strong>script</strong> that creates an “.env” file with your USER ID and GROUP ID (I’ll explain why we need this) and a <strong>docker-compose</strong> file that helps you run the container.</p><p>To run the app locally you have to be in the local_environment folder and run:</p><ol><li>make create-env</li><li>make build</li><li>make init</li></ol><p>The first two instructions are just for the first time.</p><p>The <em>make create-env</em> generates an .env file with your USER ID and GROUP ID. This variables are used in the docker-compose.yaml and then passed to the Dockerfile when building the image.</p><blockquote>By default, the user that runs everything inside the container is root, so if you create anything such as new components or services within the container, it will be created in your host file system as files owned by root. As we are passing the USER ID and GROUP ID of your user, while building the image we create a nonroot user inside the container that will run the app, this will allow you to create files that are going to be owner by your user in your file system.</blockquote><p>The make build builds the image from the Dockerfile.</p><p>The make init starts the service declared in the docker-compose.yaml sharing some ports (4200 for the app and 9876 for the tests) and volumes (sharing the code in your computer with the code inside the container). Once you run this command, you will start seeing the server logs, after the app finished compiling, you can go to <a href="http://localhost:4200/">your web browser</a> and see the app running.</p><p>If you need to generate a new component or install some dependency, you have to access the container and run the commands in it. You can access by running:</p><pre>make access-frontend</pre><p>Once you are in the container you can create the component or install a dependency as you would in a non-containerized environment.</p><h3>How to deploy the app in Google App Engine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1l92QtiwagE-vwYlxpsYiw.png" /></figure><p>I have prepared the project to be easily deployed in Google App Engine. Once you decide your app is ready to be deployed you just have to run the next command from the local_environmet folder (while the service is running):</p><pre>make build-prod</pre><p>This command builds the project and generates all the needed files to deploy in production. I changed the angular.json file to build the project inside the vcv_client/GAE_deployment directory, with this approach it can be easy to control the amount of files that are going to be uploaded, since Google App Engine does have a limit of files allowed per version (10.000). In the vcv_client/GAE_deployment folder you also will find an app.yaml.</p><blockquote>You configure your App Engine app’s settings in the app.yaml file. This file specifies how URL paths correspond to request handlers and static files. The app.yaml file also contains information about your app’s code, such as the runtime and the latest version identifier.</blockquote><blockquote>Extracted from <a href="https://cloud.google.com/appengine/docs/standard/python/config/appref">Google Cloud Docs</a>.</blockquote><p>Once you have generated the code, you can deploy the application. To do it, you have to go to the vcv_client/GAE_deployment folder and run the next command:</p><pre>gcloud app deploy</pre><blockquote><em>Remember that you have to have a project on Google Cloud and your Google Cloud SKD configured, you can do it with:</em></blockquote><blockquote>gcloud init</blockquote><p>You’ll have to wait until the upload is finished, once ended the terminal shall show you a message like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*xJvUyeh552zxpg5akaW6Ng.png" /></figure><p>You will be able to see your virtual CV in <a href="https://name_of_you_project.appspot.com/">https://NAME_OF_YOU_PROJECT.appspot.com</a></p><p>You can see the code in my repo:</p><p><a href="https://github.com/CarlosEspinoTimon/vcv">https://github.com/CarlosEspinoTimon/vcv</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=587f8700247d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/an-angular-template-to-create-your-virtual-curriculum-vitae-587f8700247d">An Angular template to create your Virtual Curriculum Vitae</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autolearning 1.0: App Engine Standard, Flask, Angular 6 and Beautiful Soup]]></title>
            <link>https://medium.com/@carlosespinotimon/autolearning-1-0-app-engine-standard-flask-angular-6-and-beautiful-soup-236551f23af?source=rss-7cedd3e36a35------2</link>
            <guid isPermaLink="false">https://medium.com/p/236551f23af</guid>
            <category><![CDATA[python-flask]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[angular-6]]></category>
            <category><![CDATA[scraper]]></category>
            <category><![CDATA[google-app-engine]]></category>
            <dc:creator><![CDATA[Carlos Espino Timón]]></dc:creator>
            <pubDate>Tue, 25 Sep 2018 04:26:18 GMT</pubDate>
            <atom:updated>2018-09-25T16:45:12.400Z</atom:updated>
            <content:encoded><![CDATA[<p>A little more than a year has passed since I finished my Computer Engineer degree and I have already worked for three companies. This is a big difference with my former studies, I am also a Technical Architect, however I wasn’t able to find a job in this area (well paid at least), so… as you can understand, now I am quite happy :)</p><p>As I said before, I have already worked for three tech companies and in five different projects with diverse technologies and architectures. To be honest, I have learnt a lot, nevertheless I am not in the position to choose in which project and technologies I want to work (for now), and that’s why I am here. I decided to create my first web app! For the past few weeks I have been working on my own in a personal project, just for the sake of learning and grow as a professional.</p><p>Let’s start talking about what is this app for and then the architecture and technologies implicated.</p><h3>I present you Cheaper shopping!</h3><p>Yes, I know, is not a great name. Naming is not one of my strengths but I think is very descriptive for what I want to offer so… I will leave it for the moment.</p><p>If you want to see the app running, you can see it <a href="https://shopping-list-215005.appspot.com/">here</a>.</p><p>As you can see, if you have already visit it, I want to create an app that helps people to save money in their grocery list. In the end, I want to give the opportunity to the user to choose how many supermarket is he willing to visit, and how far and then offer him the best combination of supermarkets and what to buy in each one to safe money. Sounds useful?</p><p>This the main functionality that I want to offer, however, as I have just started and I work only an hour everyday before going to work… This is not what the app does, right now the app only has products from one supermarket and just allows you to filter by category, subcategory and name, and then you can add products to a list and remove them. That’s it! But it’s enough to keep working :)</p><h3>Architecture and Technologies:</h3><p>In future posts I will talk about each part in detail, but mainly, this app has three main parts implicated:</p><p><strong>1.- The server:</strong></p><p>I am a fan of Python, it’s my favorite programming language, so I decided to build my server with <a href="http://flask.pocoo.org/">Flask</a>.</p><blockquote><em>Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. And before you ask: It’s BSD licensed!</em></blockquote><p>The server offers a REST API to communicate with the rest of the implicated parts.</p><p><strong>2.- The web client:</strong></p><p>I decided that the web client should be written in <a href="https://angular.io/">Angular</a> 6. As you can see in my app, I am not a Front End guy, I am more a Back End one, however I want to be able to do everything by myself so with the help of the <a href="https://material.angular.io/">Angular Material</a> library and <a href="https://getbootstrap.com/docs/4.0/getting-started/introduction/">Bootstrap</a> 4 I think that in the end, I will have something cool.</p><p><strong>3.- The web scrapers:</strong></p><p>The scrapers are written in Python and it uses the library <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">Beautiful Soup</a> 4 for pulling data out of the HTML pages I visit to obtain the prices.</p><p>The scrapers gather up all the info I need of the products. This info is sent to the server through a HTTP call. The server process the data and store it in an MySQL instance with the help of the ORM for Python <a href="https://www.sqlalchemy.org/">SQLAlchemy</a>. Why MySQL? because I simply want to learn, I have worked with NoSQL databases before and I want to work with SQL to be able to build my own opinion about both databases.</p><h3>Deployment:</h3><p>Once I had all the minimum functionalities implemented and set all the connections between each part involved, I just had to choose how and where to deploy my work. I decided to do it through <a href="https://cloud.google.com/appengine/docs/standard/">Google App Engine (GAE) Standard Environment</a>, which is one of the products that offers Google Cloud Platform (GCP), and the one that allows you to use their Platform as a Service (PaaS) and just deploy your code, ignoring a lot of complicated stuff you need to configure during deployment, such as scaling, GAE allows your app to scale automatically when needed.</p><p>All the magic of the GAE resides in the configuration file. In the app.yaml you can choose the runtime environment, tell the app which code to run, manage the handlers to redirect the traffic… You can see my app.yaml (and the rest of the code) <a href="https://github.com/CarlosEspinoTimon/shopping_list/blob/master/rest-server/app.yaml">here</a>.</p><p>This is the simplest way to deploy your app in GCP, you can concentrate all your efforts in the app. However, even that now I have the skeleton of my app and I could focus in the implementation of more functionalities, I would like to make it harder and try more complicated things. I want to deploy it in Google Compute Engine (GCE) and use the Google Infrastructure as a Service (IaaS), which is the opposite than GAE, and configure everything by myself, and then try to deploy it in Kubernetes, something in between GCE and GAE.</p><p>It sounds fun, doesn’t it? but don’t worry, I’ll share the entertainment and I’ll keep you posted ;)</p><p><a href="https://www.linkedin.com/in/carlos-espino-timon/">Carlos Espino Timón</a></p><p>Computer Engineer</p><p><a href="https://github.com/CarlosEspinoTimon/shopping_list">https://github.com/CarlosEspinoTimon/shopping_list</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=236551f23af" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>