Skip to content

Instantly share code, notes, and snippets.

View drewyangdev's full-sized avatar
🎯
Focusing

Drew Yang drewyangdev

🎯
Focusing
View GitHub Profile
#!/bin/bash
export AWS_REGION=$1
export BUCKET_NAME=$2
export ORG_NAME=$3
export WORKFLOW_NAME=$4
export WORKER_CONTAINER_UID=$5
export WORKER_CONTAINER_GID=$6
echo "INFO :: Mount S3"
sed -i '/user_allow_other/s/^#//g' /etc/fuse.conf
[ ! -d "/mnt/s3/works/org/${ORG_NAME}/proj/${WORKFLOW_NAME}/inbox" ] && sudo mkdir -p /mnt/s3/works/org/${ORG_NAME}/proj/${WORKFLOW_NAME}/inbox
@drewyangdev
drewyangdev / dd_labels.yaml
Last active January 22, 2025 17:04
Set up Datadog agent and cloud-init-logger
labels:
com.datadoghq.ad.checks: '{"docker": {"instances": [{"host": "%%host%%", "port": 8081}]}}'
com.datadoghq.ad.tags: '["org:${ORG_NAME}", "project:${WORKFLOW_NAME}", "worker_type:${WORKER_DOCKER_SUBDIR}", "log_parser:${LOG_PARSER}"]'
com.datadoghq.ad.logs: >-
[{
"type": "docker",
"source": "${ORG_NAME}_${WORKFLOW_NAME}",
"service": "${WORKER_DOCKER_SUBDIR}_${APPLICATION}",
"log_processing_rules":[{
"type": "multi_line",
@drewyangdev
drewyangdev / amazon-cloudwatch-agent-cpu.json
Last active April 6, 2023 19:04
Set up AWS CloudWatch Agent on an EC2 instance
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"namespace": "$CONTRACT",
"aggregation_dimensions": [["InstanceType"]],
"append_dimensions": {
"InstanceId": "${aws:InstanceId}",
@drewyangdev
drewyangdev / gh_actions_context_check.yaml
Last active April 6, 2023 19:05
General Github Action context checking for debugging
name: github_actions_contect_check
on: [pull_request]
jobs:
context_check:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
@drewyangdev
drewyangdev / install_docker.sh
Last active April 6, 2023 19:05
Install docker
#!/bin/bash
## Recommend to mount a separate volume on /var/lib/docker to store all docker related stuff
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
@drewyangdev
drewyangdev / mount_efs.sh
Last active April 15, 2024 22:21
Mount EFS or EFS AccessPoint on an EC2 instance
#!/bin/bash
## e.g sudo bash mount_efs.sh xxx.xxx.xxx.xxx /mnt/xxx
export EFS_IP=$1 # EFS network section, private IP within subnet
export MOUNT_DIR=$2
if [ ! -d "$MOUNT_DIR" ]; then
mkdir -p $MOUNT_DIR
fi
mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport $EFS_IP:/ $MOUNT_DIR
df -Th
@drewyangdev
drewyangdev / cloud-init-debug-example.sh
Last active April 6, 2023 19:07
cloud-init template and re-run script for debugging
#!/bin/bash
sudo su
## 1. only debug runcmd
# edit /var/lib/cloud/instance/scripts/runcmd
cloud-init single --name scripts_user --frequency=always
## 2. re-generate runcmd from userdata
cloud-init single --name runcmd --frequency=always
@drewyangdev
drewyangdev / install_nvidia_driver.sh
Last active July 2, 2024 18:19
Nvidia Driver Install/Uninstall - deprecated
#!/bin/bash
# TODO - change nvidia driver installation input from DRIVER_VERSION to DRIVER_URL to fix "tesla" only
# TODO - add system user input to fix "ubuntu" only
############################################
## Nvidia driver version is determined by GPU architecture(instance type) and
## CUDA toolkit version that you want to use
## 1. Find the Nvidia architecture for your instance type: https://towardsdatascience.com/choosing-the-right-gpu-for-deep-learning-on-aws-d69c157d8c86
## Based on the Nvidia architecture,
@drewyangdev
drewyangdev / linux_gpt_volume.sh
Last active July 8, 2022 19:22
Deal with EC2 GPT volumes that can resize to more than 2TB
#!/bin/bash
## Use lsblk check device, usually e.g "/dev/xvdf", "/dev/nvme1n1"
## Partition will be "/dev/xvdf1", "/dev/nvme1n1p1"
## e.g sudo bash linux_gpt_volume.sh "/dev/nvme1n1" "/dev/nvme1n1p1" "/mnt/gpt-volume"
export DEVICE=$1
export PARTITION=$2
export MOUNT_DIR=$3
parted $DEVICE --script mklabel gpt
parted $DEVICE --script mkpart primary 2048s 100%
mkfs -t ext4 $PARTITION
@drewyangdev
drewyangdev / python_logger.py
Last active April 6, 2023 19:12
Python logger template
import os
import sys
import io
import logging
import logging.handlers
from distutils.util import strtobool
# get logger level
DEBUG = strtobool(os.getenv("DEBUG", "True"))
# set logger config