Skip to content

Instantly share code, notes, and snippets.

import * as requireYaml from "require-yml";
import * as set from "lodash.set";
import * as merge from "deepmerge";
import { load as parseYaml } from "js-yaml";
import { readFileSync } from "fs";
type StringMap = { [key: string]: string };
let config: any, configRootPath: string;
osher / the.getting-started.improfessional.Dockerfile
Created May 8, 2023 14:58
the getting-started Dockerfile you get for nodejs docker images
FROM node:lts
COPY . .
RUN npm i
EXPOSE 3000/tcp
CMD ["npm", "start"]
osher / node-service.multiphase.Dockerfile
Last active August 8, 2023 17:30
Example for the Dockerfile for node-services using an multi-phase build with optimized node-builder and node-runner.
FROM my-private-cr/node-builder:$TAG_NODE_BUILDER
COPY packge.json .
RUN npm i --production
FROM my-private-cr/node-runner:$TAG_NODE_RUNNER
COPY --from=0 /app /
COPY . /app/
RUN apk update --no-cache
osher / node-runner.Dockerfile
Created May 8, 2023 11:05
An example for a node-runner - a base image for the last step on a multi-phase build for node services
RUN apk update --no-cache \
&& apk upgrade --no-cache \
&& apk add --no-cache nodejs
RUN addgroup -S service \
&& adduser -S service -G service
osher / example.for.node-builder.Dockerfile
Last active May 8, 2023 12:45
A dockerfile to create a base image for building npm packages
RUN apk update --no-cache \
&& apk upgrade --no-cache \
&& apk add --no-cache \
build-base \
openssh \
FROM node:alpine-lts
COPY packge.json .
RUN npm i --production
FROM alpine
RUN apk update \
&& apk upgrade --no-cache \
&& apk add --no-cache nodejs \
&& rm -r /**/apk /**/**/apk
osher /
Last active November 18, 2023 19:54
The simplest sops demo - sops using age encryption
# This demo uses an alpine sandbox in a docker container in
# interactive mode. ran with:
# docker run --rm -it alpine
# if you run it on your own system:
# 1. you should use your own package manager instead of `apk`
# 2. expect the following left overs:
# - installed binaries (age, age-keygen, sops)
# - $HOME/.config/sops/age/keys.txt
# - demo files: source.env, encrypted.env, decrypted.env
osher / separated-concerns-frameworkless-http-server.js
Last active September 14, 2022 18:03
A "frameworkless" http-server - with separation of concerns
//code concern
const conf = () => { //config
views: { //config
status: 'i\'m alive', //config
greet: 'hello, %s', //config
help: 'supports: /greet or /status', //config
}, //config
web: { port: 3000 }, //config
}; //config
osher / mixed-concerns-frameworkless-http-server.js
Last active September 12, 2022 16:13
A "frameworkless" http-server - using naive code (mixed concerns)
//code concerns
console.log('starting greeter'); //binary+logging
require('http').createServer((req, res) => { //binary+app
const [action] = req.url.slice(1).match(/[^\/]+/); //route
switch(true) { //route
case action == 'status': //webCtrl
return res.end('i\'m alive'); //view+webCtrl
Consider the language did not provide us with `.indexOf` and we had to implement it ourselves.
Given that the factory is already implemented, how easy is it to add a new case.
Mind how hoisting helps keep the higher levels above, while implementation details are below.
const Should = require('should');
const SUT = require('./index-of');