Skip to content

Instantly share code, notes, and snippets.

View kelvintaywl's full-sized avatar

Kelvin Tay kelvintaywl

View GitHub Profile
@kelvintaywl
kelvintaywl / config.yml
Created August 8, 2023 05:29
Sample Config checking approver is different from author
version: 2.1
commands:
# Requires:
# - CircleCI API token (via $CIRCLE_TOKEN env var)
# - curl & jq (assumes the executor will have curl and jq pre-installed)
validate-approval:
description: "Validate whether deployment was properly approved."
steps:
- run: |
@kelvintaywl
kelvintaywl / test.c
Created July 6, 2023 06:21
test core dumps
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Process is aborting\n");
abort();
printf("Control not reaching here\n");
return 0;
}
@kelvintaywl
kelvintaywl / Configure-Docker.ps1
Last active June 8, 2023 05:34
Configure Docker daemon with registry mirror in Windows
# Set your Docker registry mirror via the DOCKERHUB_REGISTRY_MIRROR env var.
$registryMirror = echo $Env:DOCKERHUB_REGISTRY_MIRROR
if (-Not $registryMirror) {
Write-Host "No registry mirror set. Exiting early."
exit
}
# Check if Docker service is running
$dockerService = Get-Service -Name Docker -ErrorAction SilentlyContinue
@kelvintaywl
kelvintaywl / calculate.sh
Created May 23, 2023 07:06
Bash script to print each job's duration for a given CircleCI workflow
# NOTE: This script requires:
# - curl
# - jq
# - your CircleCI API token (to be set via the $CIRCLE_TOKEN environment variable)
# Usage: sh ./calculate.sh <workflow ID>
get_job_numbers_in_workflow () {
echo "For Workflow ID ${1}:"
curl -s -H "Circle-Token: $CIRCLE_TOKEN" \
@kelvintaywl
kelvintaywl / preflight.yaml
Created May 17, 2023 04:00
Preflight Check for CircleCI Server (4.0.x)
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
name: circleci-server
spec:
analyzers:
- clusterVersion:
outcomes:
- fail:
when: "< 1.22.0"

Notes on Velero and CircleCI Server

Important

As per CircleCI Server 3.x and 4.x documentation, CircleCI Server uses Velero (and Restic) to manage backups.

CircleCI Server admins install Velero and Restic via the command:

# --use-restic will install Restic
@kelvintaywl
kelvintaywl / to_compare_server4x.md
Created April 13, 2023 06:57
Telegraf custom config

This output of the Telegraf custom config is from a Server 4.x setup where my telegraf.config.custom_config_file is set to empty string.

# parse and save Telegraf config as TOML
$ kubectl -n circleci get cm/telegraf-custom-config -o=yaml | yq '.data."telegraf_custom.conf"' > default.toml

# run through a TOML linter

$ docker run -i ghcr.io/pelletier/go-toml:v2 tomll < default.toml
[agent]

Finding diff in circleci/path-filtering Orb source code

# steps
$ circleci orb source circleci/path-filtering@0.1.3 > path-filter-013.yaml
$ circleci orb source circleci/path-filtering@0.1.4 > path-filter-014.yaml
$ git diff --no-index path-filter-013.yaml path-filter-014.yaml
@kelvintaywl
kelvintaywl / solutions.md
Last active November 2, 2022 08:25
Remote Docker and IP Ranges (Suggested Solutions)

Brief

This shows the decision tree on which solutions is possible, for customers facing the known limitation of IP ranges not working with Remote Docker on CircleCI.

This document assumes you want to

flowchart TD
    job[Your Job using Remote Docker & IP Ranges] --> only_docker{Is job only about building and/or pushing Docker images?}
 only_docker -- "NO (e.g., run E2E tests with built images)" --&gt; ip_ranges_needed_when_docker{Is IP ranges required when building and pushing the Docker image?}
import os
from time import sleep
import requests
from typing import Any
class CircleCI:
def __init__(self, token: str, project_username: str, project_reponame: str):
self._token = token
self._project = f'{project_username}/{project_reponame}'