Skip to content

Instantly share code, notes, and snippets.

@oanhnn
Last active March 8, 2024 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oanhnn/2dc83be3417576cf3a17e1808e733fb2 to your computer and use it in GitHub Desktop.
Save oanhnn/2dc83be3417576cf3a17e1808e733fb2 to your computer and use it in GitHub Desktop.
Scripts for gitlab and gitlab runner
# Clear Gitlab runner cache (docker) weekly at 17:05 on Saturday (UTC)
5 17 * * 6 sudo /usr/share/gitlab-runner/clear-docker-cache prune-volumes >/dev/null 2>&1
#!/usr/bin/env python3
import time
import requests
project_id = '...'
token = '...'
server = 'gitlab.com'
print("Creating list of all jobs that currently have artifacts...")
# We skip the first page.
url = f"https://{server}/api/v4/projects/{project_id}/jobs?per_page=100&page=2"
while url:
print(f"Processing page: {url}")
response = requests.get(
url,
headers={
'private-token': token,
},
)
if response.status_code in [500, 429]:
print(f"Status {response.status_code}, retrying.")
time.sleep(10)
continue
response.raise_for_status()
response_json = response.json()
for job in response_json:
if job.get('artifacts_file', None) or job.get('artifacts', None):
job_id = job['id']
delete_response = requests.delete(
f"https://{server}/api/v4/projects/{project_id}/jobs/{job_id}/artifacts",
headers={
'private-token': token,
},
)
print(f"Processing job ID: {job_id} - status: {delete_response.status_code}")
url = response.links.get('next', {}).get('url', None)
#!/bin/bash
export MINIO_ROOT_USER="xxxx"
export MINIO_ROOT_PASSWORD="yyyy"
docker run -d \
-p 9000:9000 \
-p 9001:9001 \
-e MINIO_ROOT_USER \
-e MINIO_ROOT_PASSWORD \
-e MINIO_VOLUMES="/data" \ # -e MINIO_VOLUMES="/data-{1...4}" -e MINIO_SERVER_URL="" \
-v $(pwd)/data:/data \
--restart unless-stopped \
--name gitlab-runner-cache \
quay.io/minio/minio:latest server --console-address ":9001"
#!/bin/bash
docker run -d \
-e LOW_FREE_SPACE=30G \
-e EXPECTED_FREE_SPACE=50G \
-e LOW_FREE_FILES_COUNT=1048576 \
-e EXPECTED_FREE_FILES_COUNT=2097152 \
-e DEFAULT_TTL=10m \
-e USE_DF=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
--restart always \
--name=gitlab-runner-cleanup \
quay.io/gitlab/gitlab-runner-docker-cleanup
#!/bin/bash
runner_name=${1:-"gitlab-runner01"}
runner_url=${3:-"https://gitlab.example.com/"}
sudo gitlab-runner register \
--url $runner_url \
--name $runner_name \
--run-untagged \
--tag-list shared \
--executor docker \
--env LC_ALL=en_US.UTF-8 \
--cache-shared \
--docker-image alpine:latest \
--docker-privileged \
--docker-tlsverify \
--docker-volumes=/certs/client \
--docker-volumes=/cache \
--non-interactive
unset runner_url
unset runner_token
unset runner_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment