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 / 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'
@magickatt
magickatt / convert_namespace_to_subnamespace.sh
Last active April 19, 2024 21:25
Convert an existing namespace to a subnamespace using the Hierarchical Namespace Controller
PARENT_NAMESPACE=pizzeria
CHILD_NAMESPACE=pepperoni
$ kubectl annotate namespace $CHILD_NAMESPACE \
hnc.x-k8s.io/subnamespace-of=$PARENT_NAMESPACE
# namespace/pepperoni annotated
$ cat <<EOF | kubectl apply -f -
apiVersion: hnc.x-k8s.io/v1alpha2
@magickatt
magickatt / scheduled_deployment_restart.yaml
Last active April 15, 2024 20:39
Restart Kubernetes Deployment on a schedule using a CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: "restart-{{ $application.name }}"
namespace: "{{ $.Release.Namespace }}"
spec:
concurrencyPolicy: Forbid
schedule: "* * * * *" # crontab.guru
jobTemplate:
spec:
@magickatt
magickatt / latest_release.yml
Created January 18, 2024 20:43
Upload multi-architecture Go binaries to GitHub release
name: Latest Release
# Customise for the tag format you are using
on:
push:
tags:
- v*
# Required for the release action to upload artifacts
permissions:
@magickatt
magickatt / filebeat.yaml
Created November 23, 2020 18:55
Filebeat configuration to ignore Consul Connect container logs
filebeat.autodiscover:
providers:
- type: kubernetes
hints.enabled: true
hints.default_config.enabled: false
add_resource_metadata:
namespace:
enabled: true
processors:
- add_kubernetes_metadata:
@magickatt
magickatt / check_container_status.sh
Last active July 29, 2023 02:28
Use Bash to wait for container to start
#!/bin/bash
IMAGE_NAME=test-1
# 1-liner
until [ $(docker inspect -f "{{json .State.Status }}" $(docker ps -a -q --filter ancestor=$IMAGE_NAME --format="{{.ID}}" | head -n 1)) == '"running"' ]; do echo "Waiting for container to start..." && sleep 1; done
# More readable
CONTAINER_ID=$(docker ps --all --quiet --filter ancestor=$IMAGE_NAME --format="{{.ID}}" | head -n 1)
CONTAINER_STATUS=$(docker inspect --format "{{json .State.Status }}" $CONTAINER_ID)
until [ $CONTAINER_STATUS == '"running"' ]
@magickatt
magickatt / adopt_helm_deployment_pod_resources.sh
Created April 28, 2023 15:06
Adopt Deployment Pod resources into a Helm install
# Can use https://gist.github.com/magickatt/e7885f748c2ecd5bb88dd64828b30fbf
# to adopt the Deployment resources themselves
NAME=test
NAMESPACE=default
kubectl get -n $NAMESPACE deployment -o name \
| xargs -I % kubectl patch -n $NAMESPACE % -p \
'{"spec": {"template":{"metadata":{"annotations":{"meta.helm.sh/release-name": "$NAME"}}}}}'