Skip to content

Instantly share code, notes, and snippets.

@piihuynh
piihuynh / portainer.yml
Last active November 25, 2021 14:33
Portainer-CE swarm mode with Traefik
version: '3.2'
services:
agent:
image: portainer/agent:2.9.2
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
environment:
AGENT_CLUSTER_ADDR: tasks.agent
@piihuynh
piihuynh / sane-caching.nginx.conf
Created December 6, 2021 15:29 — forked from philipstanislaus/sane-caching.nginx.conf
Sample Nginx config with sane caching settings for modern web development
# Sample Nginx config with sane caching settings for modern web development
#
# Motivation:
# Modern web development often happens with developer tools open, e. g. the Chrome Dev Tools.
# These tools automatically deactivate all sorts of caching for you, so you always have a fresh
# and juicy version of your assets available.
# At some point, however, you want to show your work to testers, your boss or your client.
# After you implemented and deployed their feedback, they reload the testing page – and report
# the exact same issues as before! What happened? Of course, they did not have developer tools
# open, and of course, they did not empty their caches before navigating to your site.
@piihuynh
piihuynh / mysql-docker.sh
Last active December 20, 2021 23:30 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Backup with compression
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE | gzip > `date +%Y-%m-%d-%T%z`-NAME.sql.gz
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
# Restore from gzip
zcat 2018-11-14-backup.sql.gz | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@piihuynh
piihuynh / traefik-host.yml
Last active January 4, 2022 08:47
Traefik v2.5 Swarm mode with "host" mode
version: '3.7'
services:
traefik:
# Use the latest Traefik image
image: traefik:v2.5
ports:
# Listen on port 80, default for HTTP, necessary to redirect to HTTPS
- target: 80
@piihuynh
piihuynh / add-user-on-ubuntu.sh
Last active January 10, 2022 05:04
Add user with a generated pem on Ubuntu
#!/bin/sh -e
# Usages:
# wget -O - https://gist.githubusercontent.com/piihuynh/xxx/raw/yyy/add-user-on-ubuntu.sh | bash -s username
# bash -c "$(wget -qO - 'https://gist.githubusercontent.com/piihuynh/xxx/raw/587yyy/add-user-on-ubuntu.sh')" '' username
[ $EUID -ne 0 ] && echo "This script must be run as root" 1>&2 && exit 1
[ -z "$1" ] && echo "Please provide a username in 1st param" && exit 1
# Define username from param
@piihuynh
piihuynh / install-mariadb-10.6.sh
Last active January 10, 2022 09:09
Install MariaDB 10.6 programmatically on Ubuntu
#!/bin/sh -e
# Credit: https://gist.github.com/coderua/5592d95970038944d099, https://gist.github.com/Mins/4602864
# Usages:
# wget -O - https://gist.githubusercontent.com/piihuynh/xxx/raw/xxx/install-mariadb-10.6.sh | bash -s newpassword
# bash -c "$(wget -qO - 'https://gist.githubusercontent.com/piihuynh/xxx/raw/xxx/install-mariadb-10.6.sh')" '' newpassword
# Check the bash shell script is being run by root
if [[ $EUID -ne 0 ]]; then
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# =============================
# Install docker
# -----------------------------
# Option 1
# -----------------------------
# Install kernel extra's to enable docker aufs support