Skip to content

Instantly share code, notes, and snippets.

View dreampuf's full-sized avatar

Dreampuf dreampuf

View GitHub Profile
@dreampuf
dreampuf / build_node_exporter.sh
Created August 7, 2019 15:45
Build a Node Exporter RPM package
# Extract Node Exporter RPM package
# Download the official tar package
# https://prometheus.io/download/#node_exporter
VERSION=${VERSION:-0.18.1}
URL=https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz
FILENAME=${URL##*/}
ROOT_PATH=$PWD/pkg
APP_ROOT_PATH=$ROOT_PATH/opt/node_exporter
ITERATION=${ITERATION:-1}
@dreampuf
dreampuf / instructions.sh
Created April 8, 2019 19:50
How to enable admission-pulgins in kubernetes of docker-desktop
# Install docker and kubernetes first
# Helpful link: https://www.docker.com/products/docker-desktop
# Then you need to get into the virtual machine by (it may change in the future, but the path should be similar)
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
# Change the line in /etc/kubernetes/manifests/kube-apiserver.yaml
# - --enable-admission-plugins=Initializers,NodeRestriction
# to
# - --enable-admission-plugins=Initializers,NodeRestriction,ValidatingAdmissionWebhook,MutatingAdmissionWebhook
@dreampuf
dreampuf / readme.md
Last active March 19, 2024 19:24
How to use Amazon ECR as service in GitlabCI jobs

Source: https://gitlab.com/gitlab-org/gitlab-runner/issues/1583#note_93170156

OK, I've experimented a lot getting this going with the docker+machine executor (specifically with the amazonec2 driver, which I suspect is quite common for people looking at this thread!), it may also be helpful to others when debugging what's going on for them.

docker+machine is interesting because it has several relevant contexts (i.e. a file system and environment variables), which I shall refer to as:

  • "runner": what is running the gitlab-runner binary - in my case this is an ECS-managed docker container for the gitlab/gitlab-runner image on docker hub, but it could the systemd service configuration if you're running directly on the machine.
  • "job host": the docker-machine created machine (e.g. EC2 instance) that runs the docker daemon
  • "job container": the docker container for the image specified in the project .gitlab-ci.yaml (or the default in config.toml)
@dreampuf
dreampuf / gateway_hook.sh
Created December 4, 2018 19:28
Add a posthook to prometheus pushgateway
# cat simple_posthook.sh
#/usr/bin/bash
PUSHGATEWAY_SERVER=_YOUR_PUSHGATEWAY_SERVER_ADDRESS_WITH_PORT
JOB_NAME=_YOUR_JOB_NAME
while true; do
echo -e "HTTP/1.1 200 OK\n\n# $(date)" | nc -l 0.0.0.0 9092 &> /dev/null;
sleep 3;
curl -s "http://${PUSHGATEWAY_SERVER}/metrics" | sed -ne "s/push_time_seconds{instance=\"\([[:alnum:].]*\)\",job=\"${JOB_NAME}\".*/\1/p" | xargs -I INSNAME curl -X DELETE http://${PUSHGATEWAY_SERVER}/metrics/job/${JOB_NAME}/instance/INSNAME &> /dev/null;
done
@dreampuf
dreampuf / cronjob_state_convert.py
Created November 27, 2018 16:59
Convert cronjob file to SaltStack state
import re
cronjob_content = """ PAST YOUR CRONJOB HERE """
cronjob_regex = re.compile(r'^([^#]\S*?) (\S+) (\S+) (\S+) (\S+)\s+(.+)$')
for n, (minute, hour, daymonth, month, dayweek, exp) in enumerate([i.groups() for i in map(cronjob_regex.search, d.splitlines()) if i], 1):
print "cronjob-%02d:" % n
print " cronjob.present:"
for k, v in {"minute": minute, "hour": hour, "daymonth": daymonth, "month": month, "dayweek": dayweek}.items():
if v != "*":
@dreampuf
dreampuf / main_test.go
Created November 8, 2018 22:15
How to handle sub process gently in Golang
package main
import (
"bufio"
"bytes"
"context"
"io"
"log"
"os/exec"
"strings"
@dreampuf
dreampuf / Dockerfile
Created September 28, 2018 16:33
Pingfedera docker build
from nimmis/java-centos:oracle-8-jre
ENV JAVA_HOME /usr/java/default
WORKDIR /opt
RUN yum install -y which tar nmap-ncat
ADD pf-install-9.1.2.sh /opt/pf-install.sh
RUN chmod +x /opt/pf-install.sh
RUN /opt/pf-install.sh
ENTRYPOINT ["sh", "-c", "/usr/local/pingfederate-1/bin/run.sh"]
@dreampuf
dreampuf / remote_ingest.sh
Created September 28, 2018 16:30
Docker Image Repository Ingest
token=$(curl -s -H "Authorization: Basic $(echo -n "USERNAME:PASSWORD" | base64)" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:sebp/elk:pull" | jq -r ".token")
configsha=$(curl -s -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer ${token}" https://registry-1.docker.io/v2/sebp/elk/manifests/latest | jq -r .config.digest)
curl -sL -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer ${token}" https://registry-1.docker.io/v2/sebp/elk/blobs/sha256:4b52312ebe8d44f438eeecf08da2b4460250bd574642cc124bc5eaac4f1ebfc5 | jq
@dreampuf
dreampuf / go_installation.sh
Last active September 13, 2020 02:55
How to install golang 1.11 in CentOS5
# details in: https://golang.org/doc/install/source
# a patch for centos 5 build: https://github.com/golang/go/issues/24980#issuecomment-384193598
export GOROOT="/usr/local/go"
export PATH="$GOROOT/bin:$PATH"
mkdir /usr/local/go ~/go
curl -L https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz | tar xf - -C /usr/local/go
cd /usr/local/go/src
./make.bash
curl -L https://dl.google.com/go/go1.11.src.tar.gz | tar xf - -C ~/go
@dreampuf
dreampuf / Dockerfile
Created August 21, 2018 20:00
Pingfederate Container
from nimmis/java-centos:oracle-8-jre
ENV JAVA_HOME /usr/java/default
WORKDIR /opt
RUN yum install -y which tar nmap-ncat
ADD pf-install-9.1.2.sh /opt/pf-install.sh
RUN chmod +x /opt/pf-install.sh
RUN /opt/pf-install.sh // You need to run it manually
ENTRYPOINT ["sh", "-c", "/usr/local/pingfederate-1/bin/run.sh"]