Skip to content

Instantly share code, notes, and snippets.

View vincent-zurczak's full-sized avatar

Vincent Zurczak vincent-zurczak

View GitHub Profile
@vincent-zurczak
vincent-zurczak / values-subst.sh
Created February 29, 2024 19:14
Replace values by env vars (envsubst opposite)
#!/bin/bash
# 1. Let's assume we have a 'secrets.env' file that lists variables and their values.
#
# ENV_1=VALUE_1
# ENV_2=VALUE_2
# ENV_3=VALUE_3
#
# And we have a file that contains hard-coded values, e.g.
# my_content is VALUE_3
@vincent-zurczak
vincent-zurczak / backup-k8s-secrets.sh
Last active March 30, 2020 17:23
Backup K8s secrets (to store in some external vault, e.g. in case of corrupted cluster)
mkdir -p /tmp/backup
cd /tmp/backup
# Only backup "opaque" secrets
# (not those for service accounts, etc).
#
# To back up them all, use the following query:
# kubectl get secrets -o json | jq -r '.items[].metadata.name'
for secret in $(kubectl get secrets -o json | jq -r '.items[] | select(.type == "Opaque") | .metadata.name'); do
echo "Backing up ${secret}..."
@vincent-zurczak
vincent-zurczak / reminder-about-openstack.sh
Created November 22, 2019 17:31
Reminder about Openstack and cloud init
# Setup several SSH keys to be used with a VM
cat << EOF > /path/to/cloud-init.file
#cloud-config
ssh_authorized_keys:
- <public key 1>
- <public key 2>
EOF
# Create the VM (with the minimum set of options)
openstack server create \
@vincent-zurczak
vincent-zurczak / reminder-about-ova.sh
Created November 21, 2019 18:17
A quick reminder about how to prepare a VMWare (OVF) export to Openstack
#!/bin/sh
# Let's assume you have an OVF image exported from VMWare
# (the *.ovf descriptor, *.vmdk, *.mf and *.nvram files)
# that you want to deploy on Openstack.
# An OVA file is a TAR archive that wraps all this file structure.
BASE_NAME="sample"
tar -cf "${BASE_NAME}.ova" "${BASE_NAME}.ovf" "${BASE_NAME}.mf" "${BASE_NAME}-1.vmdk"
@vincent-zurczak
vincent-zurczak / reminder-about-tcpmon.sh
Created November 21, 2019 18:09
A short reminder about how to use TCPmon to capture traffic
#!/bin/sh
# Assuming we have an Elastic Search cluster secured by Nginx.
#################
# On the server.
#################
# Capture HTTP traffic to Nginx (listening on port 9200).
# Output the result in a PCAP file, readable with Wireshark.
@vincent-zurczak
vincent-zurczak / compose-graylog.yml
Last active July 30, 2021 17:32
Centralized Logging in K8s with Fluent Bit and Graylog
# Based on https://hub.docker.com/r/graylog/graylog/
# Date: dec. 2018
version: '2'
services:
# MongoDB: https://hub.docker.com/_/mongo/
mongo:
image: mongo:3
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/docker.html
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
@vincent-zurczak
vincent-zurczak / allInOne.groovy
Last active April 1, 2023 14:49
Shared Libraries for Jenkins Pipelines (build/reuse and control Docker images)
// In vars/allInOne.groovy (shared library that defines the generic pipeline)
def call(Map config) {
node {
def timeStamp = Calendar.getInstance().getTime().format('YYYYMMdd-hhmmss', TimeZone.getTimeZone('Europe/Paris'))
def buildId = "${config.imageVersion}-${timeStamp}"
stage('Checkout') {
echo "Checking out the sources..."
checkout scm
@vincent-zurczak
vincent-zurczak / download-batch-for-linux.sh
Last active November 27, 2017 21:45
Batch script to download Youtube videos from a listing file (one video per line)
#!/bin/bash
# Configuration
DL_DIR="/wherever/you/want"
INPUT="/wherever/is/your/file"
# We need "youtube-dl" (https://github.com/rg3/youtube-dl).
# We here download the best video quality.
# One Youtube address per line. Empty lines are ignored.
mkdir -p $DL_DIR && cd $DL_DIR
@vincent-zurczak
vincent-zurczak / Dockerfile
Created March 21, 2017 19:40
Create a Docker container with both kubectl and helm
# Based on https://github.com/wernight/docker-kubectl
# Both kubectl and helm are available when we launch the image (docker run -ti this-image).
# The best option would be mounting the ".kube/config" file as a volume.
FROM wernight/kubectl:1.5.3
# Install Helm
USER root
RUN cd /home \
&& curl https://storage.googleapis.com/kubernetes-helm/helm-v2.2.3-linux-amd64.tar.gz -o helm.tar.gz \
&& tar -xvf helm.tar.gz \
@vincent-zurczak
vincent-zurczak / JSonBindingUtils.java
Created August 24, 2016 18:26
Generating swagger.json files with Enunciate and custom objects mappers
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;