Traefik 2 Docker Swarm Setup With Docker Socket Proxy and More

Traefik is an open-source router and load-balancer that sits in front of your web services. You can set it up to automatically encrypt your websites with SSL certificates. It’s also easy to add new web services to an existing Traefik cluster. image from the official Traefik website I discovered Traefik via Jakub Svehla’s post Building a Heroku-like infrastructure for $5 a month. He shows you how to use Docker to install a Traefik infrastructure on a cheap VPS like DigitalOcean.
Read more →

How to Deploy Eleventy to GitHub Pages With GitHub Actions

I recently discovered Eleventy, a modern static site generator that’s customizable and flexible, but without fuss. Eleventy uses JavaScript, but it’s not a JavaScript framework. It uses Node.js under the hood to transform templates into static (HTML, CSS) content. But those pages don’t contain any JavaScript. Eleventy was created to be a JavaScript alternative to Jekyll. It’s zero-config by default but has flexible configuration options. Eleventy works with your project’s existing directory structure.
Read more →

Friday Picks 062

Read more →

Friday Picks 057

Read more →

How to Deploy a Deno Docker Container to Heroku

The Zero To Mastery Deno Course deploys a Deno docker container to Amazon EC2. The EC2 instances cost money after you’ve exhausted your free 12 months. Plus, Amazon’s cloud services can be tricky. Sometimes, services spike. You quickly exceed your free tier, even for a simple toy app. Let’s deploy Deno to Heroku instead. Heroku’s free tier stays free regardless of usage. The free level is slow, because it will periodically stop to save resources.
Read more →

Friday Picks 055

Read more →

Tuesday Picks 001

Read more →

TIL: Docker Debugging and Exit Codes

Read more →

TIL: strongSwan using bypass-lan Plugin Can Fix Docker Routing

Let Docker access the internet by passing through the VPN connection strongSwan My host machine, a laptop running Manjaro Linux, is connected via VPN to the internet. I use strongSwan, the open-source IPsec-based VPN solution. IPsec with the IKEv2 protocol is fast and secure. Now, Docker doesn’t work. Networking issues are a common problem with VPN and Docker. You can piggyback your Docker container on the host network. That technique only works on Linux machines.
Read more →

Friday Picks 037

Read more →

TIL: Docker: chown Copies All Files

Docker builds containers via layers. All commands add another layer to the already existing image. What does that mean for changing file permissions via chown or chmod? Let’s say we build this image: FROMfrolvlad/alpine-miniconda3:python3.7 AS build## set working directoryWORKDIR/usr/src/app## copy codeCOPY ./code /codeCOPY ./notebooks /notebooks## add non-root userRUN addgroup –system user && \ adduser –system -G user user && \ chown -R user:user /usr/src/appAfter copying the code from the host machine to the container, we switch permissions for the working directory from root to user.
Read more →

AWS ECS - I’m Giving Up

The last fews day’s I’ve been learning how to deploy a Flask and React application to AWS. I’ve decided to shelf that project for now. As a hobby developer and learner I don’t need all the features that AWS offers. A setup with Load Balancer, RDS instances, etc. adds a lot of complexity which I have no use for. The plan for this month was to create a test-driven Python and React application.
Read more →

Learning Progress: Still Learning About Amazon ECR

Read more →

Learning Progress TIL: About Container Orchestration

Read more →

Run Docker nginx as Non-Root-User

How to run nginx as non-privileged user with Docker nginx is an open-source solution for web serving and reverse proxying your web application. You put it “in front” of your different services, and nginx can route the traffic to the correct url. That’s useful for micro-services, for example. Per default, nginx runs as root user. Why? Only root processes can listen to ports below 1024. The default port for web applications is usually 80 or 443.
Read more →

TIL: Bind Mounts

Read more →

Learning About Nodejs Graphql Microservices

I’m currently working on a few micro-services with Docker. The architecture looks promising to me, and I like to play with Docker containers. Lately I’ve been watching a few videos about Node.js/GraphQL Microservices by Better Coding Academy. The tutorial series assumes a lot of knowledge (JavaScript, Express, GraphQL, Docker). I would have liked more detailed explanations. But the videos are still useful for showing the architecture of an Express/GraphQL setup with micro-services.
Read more →

Setup a Postgres Database With Docker Compose

Adding a Postgres database to an existing service is fairly straightforward with docker-compose. Create a Dockerfile for your main service. For example, here’s a simple Docker container with Node: FROMnode:12.14.0-alpine3.9ENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install npm@latest -g –silentWORKDIR/opt/appCOPY package*.json /opt/app/RUN npm install –no-optional && npm cache clean –forceENV PATH /opt/app/node_modules/.bin:$PATHENV PATH=$PATH:/home/node/.npm-global/binARG NODE_ENV=production ENV NODE_ENV $NODE_ENVARG PORT=3000 ENV PORT $PORTEXPOSE$PORT 8229 8230COPY . .CMD ["npm", "run", "watch"]The Dockerfile starts from the official Node container, updates npm globally, installs the necessary packages, and runs an npm command (as root user in development mode).
Read more →

2019 Week 50: A Look Back

Read more →

Friday Picks 029

Read more →

Example Multi Stage Docker Build for React

I’m still trying to improve my Docker builds. Here’s an example for a multi-stage Docker build for React:

base imageFROMnode:12.13.1-alpine as compile-image## install global packagesENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install npm@latest -gRUN npm install pnpm react-scripts@3.3.0 -g## set working directory & give permissions to user nodeRUN mkdir -p /usr/src/app && chown node:node /usr/src/appWORKDIR/usr/src/app## switch to non-root user & install dependenciesUSERnodeCOPY package*.json /usr/src/app/COPY pnpm-lock.yaml /usr/src/app/pnpm-lock.yamlENV PATH /usr/src/app/node_modules/.bin:$PATHENV PATH=$PATH:/home/node/.npm-global/binRUN pnpm install## set environment to production, overwrite## with docker-composeARG NODE_ENV=production ENV NODE_ENV $NODE_ENV## create buildCOPY .

Read more →

Learning About Best Practices for Docker and Node

Today I’ve tried to update one of my Docker apps that uses React, Enzyme, and Jest. This lead me on a wild goose chase about react-test-renderer and best practices for Docker builds for Node.js. I’m still not sure where the problem is (Enzyme, maybe?). But I found three useful resources for Docker and Node.js: Docker and Node.js Best Practices Node + Docker Hello World, for Showing Good Defaults for Using Node.
Read more →

Wrangling With Docker

I’m currently wrangling with Docker. I’m working through some Docker courses on Udemy and Sitepoint. Plus, I’m reading articles on how to improve my Docker files. I like playing with tools like Docker and docker-compose. But they add a lot of complexity to an application. Here are some useful links and resources about Docker: Advanced multi-stage build patterns by Tõnis Tiigi 9 Common Dockerfile Mistakes by Jorge Silva Production-ready Docker packaging Docker for Node.
Read more →

Create a Multi-Stage Docker Build for Python Flask and Postgres

A few days ago, I created a Docker build for Flask with PostgreSQL (both with Alpine Linux and with Debian Linux). Installing psypcopg-2 binary (required for Postgres) requires you to build the package from source. Now the Docker image grows in size, as it still contains the build artifacts. The solution? Multi-stage Docker builds. Let’s say we have the following docker-compose.yml file. There are two services: a Flask API called users and a Postgres database called users-db.
Read more →

Install psycopg2-binary With Docker

How to build a Python app with PostgreSQL I’m currently setting up a Flask app with PostgreSQL and Docker. Like most examples you’ll find on the internet, the course I’m following uses Alpine Linux as a base image. Alpine’s selling point is the small image size. But Alpine uses a different C library, musl, instead of glibc. That’s one of the reasons why the website Pythonspeed recommends Debian Buster as the base image for Python (as of 2019).
Read more →

Docker NGinx 405 POST Not Allowed

Today it took me over one hour to debug an error with Docker and Nginx. Every time I tried to submit a form with a POST method, NGinx gave me a 405 error: “405 Not Allowed”. I originally thought that Nginx overrode React Router settings and tried to troubleshoot my production NGinx config. StackOverflow had some ideas: POST request not allowed - 405 Not Allowed - nginx, even with headers included.
Read more →

Remove Docker Containers And More

Read more →

Permission Denied When Installing NPM Packages With Docker

I have the following Dockerfile for a React app:

base image FROM node:11.12.0-alpine ## set working directory WORKDIR /usr/src/app ## add /usr/src/app/node_modules/.bin to $PATH ENV PATH /usr/src/app/node_modules/.bin:$PATH ## install and cache app dependencies COPY package.json /usr/src/app/package.json COPY package-lock.json /usr/src/app/package-lock.json RUN npm install react-scripts@3.0.1 -g –silent RUN chown -R node:node . USER node RUN npm ci ## start app CMD ["npm", "start"] After setting up the work directory I copy the package.

Read more →

Friday Picks 013

Read more →

Run Docker-compose as Root User: Python Coverage Permission Denied

I’m learning test-driven development with the course Microservices with Docker, Flask, and React. It’s been a lot of fun. I’ve also learned more about using Docker and docker-compose. The course uses Coverage.py for measuring Python code coverage. However, Coverage.py and Docker don’t play well with each other if you run the Docker container as a normal (non-root) user. PermissionError: [Errno 13] Permission denied: 'usr/src/app/.coverage' Here is the Dockerfile:

base image FROM python:3.

Read more →

Deploying Docker with Travis to Heroku Woes

Read more →

Learning TDD

I’m interested in learning test-driven development (and Domain-Driven Design, too). I find it a bit hard to find the right material to apply TDD in the context of building a full-stack web application. I’m familiar with building Node.js applications, and have a passing knowledge of NestJS. So far, the best material about TDD for back-end development seems to come with Python - either Flask or Django. While I’m not interested in learning yet another web framework, it seems that learning TDD for beginners comes with Python.
Read more →

MicroServices with Docker, Flask, and React

Today I reviewed my progress with the Microservices with Docker, Flask, and React by Michael Herman. I’m not familiar with Flask, but I wanted to learn how to build a microservices app with TDD. The testdriven.io course was the best course I could find which uses Docker, and React and teaches testing principles. The parts about Docker proved already useful. I used the setup to dockerize a simple Django app.
Read more →

Stop All Docker Containers

Read more →

Docker Compose, Postgres and Travis CI

Today I tried to set up a dockerized Flask app with Postgres database with Travis CI. It shouldn’t have been difficult because I followed a tutorial. Setup Here is the docker-compose.yml: version: '3.7' services: users: build: context: ./services/users dockerfile: Dockerfile volumes: - './services/users:/usr/src/app' ports: - 5001:5000 environment: - FLASK_ENV=development - APP_SETTINGS=project.config.DevelopmentConfig - DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev - DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test depends_on: - users-db users-db: build: context: ./services/users/project/db dockerfile: Dockerfile ports: - 5435:5432 environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres nginx: build: context: .
Read more →

Friday Picks 011

Read more →

React.js & Node.js App Deployment with Heroku

Read more →

Custom React Hook: Use AWS Amplify Auth

AWS Amplify offers an Authentication API that allows you to manage and store users. Here is an example for a custom React Hook with useReducer and useEffect that fetches the current user data from AWS Amplify: import { useReducer, useState, useEffect } from 'react' import { Auth, Hub } from 'aws-amplify' const amplifyAuthReducer = (state, action) => { switch (action.type) { case 'FETCH_USER_DATA_INIT': return { …state, isLoading: true, isError: false, } case 'FETCH_USER_DATA_SUCCESS': return { .
Read more →

AWS Amplify Serverless Function 403 Error CORS

A CORS Error? I’ve set up a serverless function and REST API endpoint to process payments via Stripe. Every time I try to use the function, I get a POST error with status code 403: XMLHttpRequest cannot load https://XXXXX.execute-api.us-west-2.amazonaws.com/YYYYY. No 'Access-Control-Allow-Origin' header is present on the requested resource. This looks like a CORS error. When you use the Amplify CLI tool to create your function, it delivers a sample Node.js/Express app.
Read more →

Authorization Rules in GraphQL and AWS Amplify

AWS Amplify provides a back-end service for your front-end or mobile app. It also offers build-in UI components and functions to integrate with their AWS services. It integrates well with JavaScript and offers a GraphQL endpoint. Additionally, AWS Amplify ships with an Authentication API. How can you allow users to read all data (see everything), but restrict their ability to modify data? For example, my GraphQL schema has a Product type:
Read more →

Friday Picks 004

Read more →

AWS Amplify: Resource is not in the state stackUpdateComplete

I updated my AWS Amplify API and added more nested layers to my GraphQL schema: $ amplify configure codegen $ amplify codegen statements $ amplify push I also wanted to update my S3 storage to add different permissions: $ aws amplify update storage $ amplify push But this fails with Resource is not in the state stackUpdateComplete. My solution: $ amplify update auth Choose the option “Yes, use default configuration” (uses the Cognito Identitypool).
Read more →

AWS Amplify

Today I started working with AWS Amplify and React. I bought a Udemy course, and use it as a learning aid. Setting up AWS Amplify with JavaScript proved to be frictionless. Creating a new GraphQL back-end API took me 5 minutes. The Udemy course holds your hand and provides a gentle introduction into AWS Amplify. I’m pleasingly surprised. But as someone with an affinity for back-end work, the lack of control bothers me a bit.
Read more →

Run PostgreSQL in a Docker Container

I try to learn something new every day, and I find it surprising what cool things you can do with technology. Today I learned that you could run a PostgreSQL database in a docker container. I was doing a Phoenix tutorial by Alvise Susmel. The article shows you how to create a Phoenix app which can handle user uploads and is an interesting piece in itself. But I also like the idea of running the database in Docker for local development.
Read more →