Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / Dockerfile
Created August 10, 2021 15:36
Use forwarded SSH agent in Docker build
FROM python:3.9-buster
# Prevents issues with cloning private PIP packages from GitHub
RUN --mount=type=ssh mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts
RUN pip install --upgrade pip
RUN pip install pipenv
COPY . .
# Use the forwarded SSH agent when installing pip packages
@magickatt
magickatt / gist:bb7108d276bce430cf35
Created August 15, 2014 09:50
Example of how to use the Symfony Config component
<?php
// Load application-specific configuration
try {
$basepath = __DIR__ . '/config';
$configuration = Yaml::parse($basepath . '/config.yml');
} catch (\InvalidArgumentException $exception) {
exit("Are you sure the configuration files exist?");
}
@magickatt
magickatt / restart_namespace.sh
Created January 31, 2021 19:44
Restart all deployments in a k8s namespace
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo "Usage: restart_namespace \$NAMESPACE"
exit 1
fi
NAMESPACE=$1
echo "Restarting all deployments in $NAMESPACE..."
@magickatt
magickatt / check_ssl_validity.sh
Created January 4, 2021 20:05
Check at specified intervals whether an SSL certificate is valid
#!/bin/bash
URI=https://www.yahoo.com
INTERVAL_IN_SECONDS=0.5
RESULTS_PER_LINE=50
echo "Checking $URI at ${INTERVAL_IN_SECONDS}s intervals..."
check_uri () {
#!/bin/bash
# Random number between 1 and 10
WAIT=`shuf -i 1-10 -n 1`
# Subtract 1 from the random number, check if it is now 0
is_random_number_zero () {
let WAIT=WAIT-1
return $([[ "$WAIT" -eq "0" ]])
}
@magickatt
magickatt / cloud_iap_firewall_rule.tf
Last active October 22, 2020 14:52
Cloud IAP Terraform firewall rule for GKE
resource "google_compute_firewall" "allow_nodes_from_cloud_iap" {
name = "allow-gke-nodes-ssh-from-cloud-iap"
description = "Allow Cloud IAP to communicate with the the GKE nodes."
network = var.network
allow {
protocol = "tcp"
ports = ["22"]
}
apiVersion: networking.gke.io/v1beta2
kind: ManagedCertificate
metadata:
name: {{ .Values.domain | replace "." "-" }}
namespace: kise
spec:
domains:
- {{ .Values.domain }}
locals {
project_ids = [123456789012, 234567890123, 345678901234]
bucket_region = "us"
bucket_project = "something-123456"
bucket_name = "${local.bucket_region}.artifacts.${local.bucket_project}.appspot.com"
}
# Allow Cloud Build in every other project access to GCR images hosted in the central project
resource "google_storage_bucket_iam_member" "container_registry" {
for_each = var.project_ids
locals {
project_ids = [123456789012, 234567890123, 345678901234]
}
# Allow every other project access to GCE VM images in a central project
resource "google_project_iam_member" "image_user" {
for_each = local.project_ids
project = "tools-275721"
role = "roles/compute.imageUser"
@magickatt
magickatt / service_account.tf
Created May 19, 2020 19:43
Create Google Cloud Platform service account credentials JSON using Terraform
resource "google_service_account" "service_account" {
account_id = "test
display_name = "Test"
}
resource "google_service_account_key" "service_account" {
service_account_id = google_service_account.service_account.name
public_key_type = "TYPE_X509_PEM_FILE"
}