A bootstrap for a microservice based on Flask with MongoDB

Starting a new project is a common task in microservices architecture. To do this it’s better to have a some template. I put my version to the flask-mongoengine-bootstrap repository. The key point are:

  • very basic, only flask, flask-mongoengine and structlog in requirements
  • configuration through environment variables
  • configured logging in JSON format
  • marking log records with request_id
  • possibility to run development version make dev and tests make test through docker
  • a template for Makefile
  • examples of model, api route and tests

If you’ll use it, do not forget to change SECRET_KEY.

Subscription to the blog updates

| Comments

This year I decided to spend some time on the blog marketing. I don’t know how to do it, but as a first step I’ve added a subscription to the monthly digest of updates. You can see it on the right.

I used MailChimp because:

  • it’s free up to 2,000 subscribers and 12,000 emails per month
  • there is a subscription form builder
  • there is an automatic campaign to send an email by schedule with the posts from RSS

The only problem was to choose an physical address, it’s a requirement for FTC’s CAN-SPAM Act. I don’t want to provide my home address or buy P.O. box for now, so I put my work address.

No-Cache headers in Flask

| Comments

The second line of “The Zen of Python” (try import this) says “Explicit is better than implicit.”. By default Flask response does not return any cache header and you can suppose that browsers will not cache, but some of them can decide for you. So it’s better to provide them, especially for API and it’s easy:

    def set_response_headers(response):
        response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        response.headers['Pragma'] = 'no-cache'
        response.headers['Expires'] = '0'
        return response

Problems with Gmail in default Postfix configuration

| Comments

Recently I moved some of the sites to a new hosting. The previous server had Ubuntu 12.04 with Exim4 and I forgot how to configure them.

On a new server I installed Postfix with Ansible:

    - name: Set up Postfix to relay mail
      debconf: name=postfix
               question='{{ item.question }}'
               value='{{ item.value }}'
               vtype='{{ item.vtype }}'
        - { question: 'postfix/mailname', value: '{{ ansible_fqdn }}', vtype: 'string' }
        - { question: 'postfix/main_mailer_type', value: 'Internet Site', vtype: 'string' }

After that I started to receive the next delivery reports from Gmail:

Alfred Workflow to add an email from Mail.app to Todoist inbox

| Comments

There is a way to add an email to Todoist by sending it to a special address, the only thing that annoing me, that it doesn’t keep a link to the message in Mail.app.

I created a simple Alfred workflow, which takes the selected messages in Mail.app, creates a Markdown links as [email subject](message://message_id) and send it to Todoist Inbox using its API.

You can find the details about installation and usage in sneawo/mailapp-to-todoist repository.

Socket.IO in Docker Swarm

| Comments

Socket.IO requires the sticky sessions, so when it’s runned in Docker Swarm environment, the Swarm load balancer can forward the request to any node where the service is launched and there will be the 400 errors. The solution is to limit the number of nodes for Socket.IO service to one or to use another load balancer like Traefik or HAProxy.

« 2/7 »