Docker Debugging: RUN Statements

Debugging failing Docker image builds can be tricky. Sometimes, you are given helpful enough error messages to resolve the issue swiftly. Oftentimes, though, you get messages like the following.

The command '/bin/sh -c ./ &&     ./ &&     ./' returned a non-zero code: 1

When you have a RUN statement that runs several commands, it can be difficult to tell which one failed and for what reason. Rather than guessing, the following steps will help you debug this situation more effectively.

  • Comment out the failing RUN statement and everything below it
  • Build the image
  • Run the container with bash
  • Run each command in the RUN statement sequentially
  • When you get to one that fails, investigate
Continue reading Docker Debugging: RUN Statements

Creating a Static HTTP Server with Rust – Part 2

In this series, we are creating a basic static HTTP 1.0 server with Rust. If you haven’t seen Part 1 yet, go do that first. At the end of Part 2, our server will do the following:

  • Read and serve files from a predefined directory on the host server
  • Generate appropriate HTTP responses to incoming requests
  • Log information about the response to standard output
Continue reading Creating a Static HTTP Server with Rust – Part 2

Creating a Static HTTP Server with Rust – Part 1

In this series, we will create a basic static HTTP 1.0 server with Rust. At the end of Part 1 of this tutorial, our server will do the following:

  • Listen for and handle TCP connections on a specific port
  • Accept HTTP 1.0 GET requests
  • Parse and validate requests for further use
  • Log incoming requests

We will avoid using libraries that make this trivial (i.e. the http crate) and focus on the fundamentals of how a server works. Let’s get started.

Continue reading Creating a Static HTTP Server with Rust – Part 1

Docker Compose in Production

Docker Compose facilitates the deployment of Dockerized applications. A series of Docker commands and arguments to start your application become a single command; docker-compose up. Such an invaluable tool makes deploying in both development and production environments a breeze. However, applications are generally run and configured much differently in production than in development. In this post, we will explore ways to separate your development and production configurations while keeping things DRY and maintaining the simplicity of Docker Compose commands.

Continue reading Docker Compose in Production

Avoid Memory Issues with Django’s bulk_create

When inserting a large number of objects into the database with Django, your first thought should be to use bulk_create. It is much more efficient than calling create for each object, and it generally only results in a single query. However, when dealing with tens of thousands, hundreds of thousands, or even more objects, you may run into out of memory errors.

Continue reading Avoid Memory Issues with Django’s bulk_create

Write Better Unit Tests

Writing unit tests is not just a formality. Unit tests are as important to an application as the code that runs it. Without them, code is fragile. A twentieth parameter is added to a common function, with yet another conditional added to the end, as backwards compatibility must be maintained and regressions must be avoided. The same bug is fixed for the fifth time this month. The codebase devolves into a house of cards, where even senior developers can’t make significant changes with confidence. To avoid this dystopian future, start writing unit tests for your code with diligence. In this post, we will outline a basic set of guidelines for writing them that will allow you to improve the stability, reliability, and maintainability of your application.

Continue reading Write Better Unit Tests

Using JavaScript’s Fetch with a REST API

If you are at all familiar with modern JavaScript, you have probably heard of, or used, Fetch; a function that allows you to make asynchronous HTTP requests. It leverages ES6 promises to make it easy to define asynchronous behavior. Fetch and promises can be tricky to work with and understand, especially if you are new to them. In this post, we will get a basic understanding of each of them, then discover how we can create a collection of wrappers to make sending requests to a traditional REST API a breeze.

Continue reading Using JavaScript’s Fetch with a REST API

Tips for Testing Django Views

Views are probably the most essential part of a Django application. They provide an interface to your application for users or other external applications. It only makes sense that these need to be well-tested. At first, it can seem difficult and/or tedious to write unit tests for them. However, by decoupling your business logic from your views, testing business logic and view logic separately, and tracking code coverage, you can be confident in the reliability and accuracy of your application’s views.

Continue reading Tips for Testing Django Views

Rust Dependency Management with Cargo

This past week, I started learning Rust. While I have enjoyed learning about Rust’s clever approach to system programming, I have to say that I found its dependency management a bit confusing at first. Today, I will share my new understanding of this with you, whether you are a new, experienced, or aspiring Rustacean.

Continue reading Rust Dependency Management with Cargo

Automate Docker Image Versioning with Jenkins

Versioning your Docker images is a good practice that will make them easier to deal with, whether they are used only privately or are offered to the public. With each iteration of an image, regression is always a possibility. To prevent the disruption of services for yourself and others, it is always a good idea to maintain a stable versioning system. By using semantic versioning, we are able to categorize our iterations clearly and allow the subscriber to choose which they want.

Continue reading Automate Docker Image Versioning with Jenkins