Fully Remote Development with VS Code & Cloud9

Posted on Sat 04 January 2020 in development • Tagged with gcp, authorization, iam

I work from about 7 different machines, including 3 laptops, ipad, chromebook and a PC desktop. Usually this means keeping credentials, config, build dependencies and IDEs in sync across all 3--and the iPad & Chromebook just can't run my dev environment

I considered a few options to enable seamless work across devices

option pros cons
Keep a "dev" docker image that contains everything. fully-local dev only works on Desktop OSs. Inconsistency if you forget to push the image
Sync script fully-local dev Inconsistency across devices. Script mayhem
Code remotely via a VM Secure, consistent Traditionally, text-only

Solution

  1. Launch Cloud9 Environment on …
Continue reading

Build 100kB Docker Images from Scratch

Posted on Mon 06 May 2019 in docker • Tagged with docker, c, scratch

📓 The Gist

You may think your 100mB Alpine images are small--but how about 100kB? Smaller images ship more quickly, and contain fewer attack vectors. Moreover, by optimizing images, you discover and isolate exactly what is needed for your app to run.

Let's Optimize.

There are two key characteristics of scratch-based docker images: 1. The Dockerfile has two build stages: * a builder--which contains all of the build dependencies including source, libraries and tools and.. * a final image, containing the binary and any run-time dependencies (config files, certificates and dynamically linked libraries) 2. The final image is FROM scratch -- the empty docker …

Continue reading

Publish Free Static Websites With Firebase, Hugo and Google Cloud Builder -- Part 2

Posted on Tue 30 April 2019 in hosting • Tagged with gcp, firebase, hugo, google-cloud-builder, tutorial

In Part 1, we completed our development environment, including setting up Hugo and our repo.

Here we'll publish our site to Firebase Hosting, and create the CI tools on Google Cloud Build to build and publish upon push.

Open Your Cloud Shell

In Part 1, we enhanced our cloud shell with hugo and set up our repo. In Part two, we'll use it to create the builder and configure hosting.

See the Quickstart for complete instructions

Create a Firebase Site & Configure Your Project

First, authenticate your cli

:::bash
# --no-localhost let's us authenticate our cloud shell by code
$ firebase login …
Continue reading

Benchmarking Pihole : Pi Zero vs Pi 3b+

Posted on Tue 23 April 2019 in iot • Tagged with raspberrypi, go

Here's a benchmark comparing pi-hole running on a Pi Zero (with USB ethernet) vs a Pi 3b+.

tl;dr There was negligible performance difference for blocked domains, but a measurable difference in mean for forwarded + cacheable domains. Although the Pi 3b+ has a 11ms better mean response time for forwarded queries, the P95 for pi zero is better in both blocked and forwarded queries.

I would recommend using the Pi Zero.

Hypothesis

Prior to the experiment, I assumed that the pi zero would be 30-50% slower in all cases, and that stddev would be larger (worse & more erratic latencies).

Hardware …

Continue reading

PHP Dev Environment One-Liner

Posted on Wed 17 April 2019 in php • Tagged with docker

Here's the fastest way to get your PHP app running. No MAMP, WAMP, apache or any of that nonsense.

Moreover, it allows you to run multiple projects independently.

I'm assuming you have docker.

tl;dr

This runs the php docker image, mounts the current directory, and spins up a server on port 8086

$ docker run -v $(pwd):/www -it -p8086:8086  php:5.6-alpine sh -c "cd www; php -S 0.0.0.0:8086"

The Full Version

Create your index.php

$ cat > index.php
<html><body><h1><?php print("Hello World!") ?> </h1></body></html>
CTRL-D

Run the Server

$ docker …
Continue reading

Being Scientific with Gists : The Sharable Laboratory

Posted on Tue 09 April 2019 in productivity

Next time you create a post with code snippets--like here on dev.to or stackoverflow--consider sharing a working and buildable gist along with it. By doing so, others can clone, reproduce your results, and commit new variants much more easily.

With the process below, your gist becomes a sharable laboratory. Since the gist contains all of the code variants and test cases, any team member can create a variant and run the tests against all existing variants.

In the examples below, we were discussing performance differences between short Perl & Golang snippets, presumably doing the same thing. The original variant had …

Continue reading

Getting to Yes -- As Quickly as Possible

Posted on Fri 29 March 2019 in go • Tagged with devops, performance

There was a great discussion a year ago about how fast gnu's version of "yes" is. If you're unfamiliar, yes outputs y indefinitely.

yes |head -5
y
y
y
y
y

The key takeaway was that write is expensive and writing page-aligned buffers is much faster. The is true across languages, so let's see how to do it properly in go.

If you're shocked or impressed by the results, let's see you do it in your language -- post your results in the comments.

First, our benchmark C code from last-year's post.

/* yes.c - iteration 4 */
#define LEN 2
#define TOTAL …
Continue reading

GCP: Managing IAM Access Control Across Projects -- The Simpler Version

Posted on Mon 25 February 2019 in gcp • Tagged with gcp, authorization, iam

GCP resources are organized into projects -- all resource IDs and IAM principles are grouped under a project ID. This means that by default roles assigned to a principle (e.g. a user or service account) are scoped only to project resources. This can be tricky if say your images are in one project's storage bucket and your app is running in another

If you want to provide a service principle in one project access to resources in another , the approach is not obvious, nor is it well documented.

Below we'll talk about the most direct way, which works for projects …

Continue reading

Publish Free Static Websites With Firebase, Hugo and Google Cloud Builder -- Part 1

Posted on Fri 15 February 2019 in hosting • Tagged with gcp, firebase, hugo, google-cloud-builder, tutorial

Static site frameworks like Hugo allow you to manage content with Markdown and publish content via scalable hosting platforms like Firebase hosting. Uptime, performance and operations cost per user can't be beat -- you can easily hit millions of pageviews for less than $10/ month

In this tutorial we'll make a production-ready personal website site, that supports multiple collaborators, built using Hugo. Moreover, we'll publish with the free-to-start Firebase Hosting CDN, and build automatically using Google Cloud Builder.

Prerequisites

  1. A Google Cloud Platform Account & Project -- You can use the free tier
  2. A Firebase project -- also free
  3. Access to the Google Cloud …
Continue reading

Writing Custom Metrics to Stackdriver in Golang

Posted on Wed 13 February 2019 in golang • Tagged with gcp, stackdriver, monitoring, tutorial

Instrumentation is a critical part of any application. Along with system counters like cpu, heap, free disk, etc-- it's important to create application-level metrics to make sure health is measured closer to your customer's experience.

Example metrics could be user-registration, password-change, profile-change, etc. If you see a major spike or dip in these metrics, a wider problem could be indicated.

For this example a custom metric was needed, and no infrastructure was in place for harvesting it (e.g. collectd). Golang is handy for creating an easy-to-install daemon which performs the measurement and periodically harvests the data into stackdriver.

The …

Continue reading