Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / github_clone_using_token.sh
Created September 6, 2019 17:31
Clone a GitHub repository using a Personal Access Token
export GITHUB_USER=magickatt
export GITHUB_TOKEN=secret
export GITHUB_REPOSITORY=magickatt/ContainerisingLegacyApplicationsTalk
git clone https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
@magickatt
magickatt / helm_chart_validate_matrix.yml
Created February 24, 2023 15:06
GitHub Action to validate multiple Helm charts at once
name: Validate Helm charts
on:
push:
branches: [ main, master ]
pull_request:
jobs:
validate:
runs-on: ubuntu-latest
@magickatt
magickatt / eks_eip_userdata.sh
Created January 9, 2025 20:51
Assign a spare Elastic IP by tag to a new EKS node
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
# Find any unassociated Elastic IPs for this EKS cluster, and associate 1 to this node
allocate_eip () {
allocation_ids_string=$(aws ec2 describe-addresses --filters Name=tag:cluster,Values=${cluster} --query "Addresses[?NetworkInterfaceId == null ].AllocationId" --output text)
allocation_ids=($allocation_ids_string)
# Check if there is at least 1 Elastic IP free
if [ ${#allocation_ids[@]} -eq 0 ]; then
return 1
@magickatt
magickatt / configure_source_highlight.sh
Created December 10, 2024 15:23
Configure source-highlight syntax highlighting for less on macOS
#!/bin/bash
brew install source-highlight
# Tell less where source-highlight is installed
# https://www.gnu.org/software/src-highlite/source-highlight.html#Using-source_002dhighlight-with-less
export LESSOPEN="| $(brew list source-highlight | grep src-hilite-lesspipe.sh) %s"
export LESS=' -R '
@magickatt
magickatt / github_app_jwt.sh
Last active November 15, 2024 15:35
Generate GitHub App JWT and Token
#!/usr/bin/env bash
# Combination of generating the JWT and the token
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app#generating-a-json-web-token-jwt
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app#using-a-json-web-token-jwt-to-authenticate-as-a-github-app
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation
set -o pipefail
@magickatt
magickatt / ci.yml
Created November 8, 2024 15:45
Merge Golang unit and integration test code coverage using GitHub Actions
name: CI
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
@magickatt
magickatt / cobra_subcommand_usage.go
Last active November 8, 2024 15:35
Print usage for Cobra sub-commands
package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/you/your-project/cmd/testcmd"
"github.com/spf13/cobra"
)
@magickatt
magickatt / elasticmq.go
Created June 17, 2024 21:15
Use ElasticMQ with AWS SDK v2
ctx := context.TODO()
queueName := "something"
endpointURL := "http://localhost:9324"
messageBody := "test"
// Create a custom endpoint resolver for ElasticMQ
elasticmqResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
if service == sqs.ServiceID {
return aws.Endpoint{URL: endpointURL}, nil
}
@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"
}
@magickatt
magickatt / cloudbuild.yaml
Created August 10, 2021 15:31
Add deploy key to SSH agent forwarding for Docker build in Google Cloud Build
- name: 'gcr.io/cloud-builders/git'
secretEnv: ['SSH_KEY']
entrypoint: 'bash'
args:
- -c
- |
echo "$$SSH_KEY" >> /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
volumes:
- name: 'ssh'