Skip to content

Instantly share code, notes, and snippets.

@edr3x
Last active July 3, 2024 04:45
Show Gist options
  • Save edr3x/62c70d753f727c172f1012131f4a20bf to your computer and use it in GitHub Desktop.
Save edr3x/62c70d753f727c172f1012131f4a20bf to your computer and use it in GitHub Desktop.
Personal minimal config for new servers

Minimal setup on new servers for vim, bashrc and tmux.

curl -fsSL "https://gist.github.com/edr3x/62c70d753f727c172f1012131f4a20bf/raw/install.sh" | bash -e

Set up docker with traefik as reverse proxy

curl -fsSL "https://gist.github.com/edr3x/62c70d753f727c172f1012131f4a20bf/raw/setup.sh" | bash -e
alias x="exit"
alias c="clear"
# docker
alias dps="docker ps"
alias dcd="docker-compose down"
alias dcu="docker-compose up -d"
alias dcls="docker container ls | wc -l"
# TMUX
alias tls="tmux ls"
alias ta="tmux a"
alias tnew="tmux new -s"
alias tkl="tmux kill-server"
alias tk1="tmux kill-session -t"
export EDITOR=vim
PS1='\[\033[31m\]\w\[\033[0m\] \[\033[32m\]❯\[\033[0m\] '
curl -fsSL \
"https://gist.github.com/edr3x/62c70d753f727c172f1012131f4a20bf/raw/vimrc" -o ~/.vimrc \
"https://gist.github.com/edr3x/62c70d753f727c172f1012131f4a20bf/raw/tmux.conf" -o ~/.tmux.conf
curl -fsSL "https://gist.github.com/edr3x/62c70d753f727c172f1012131f4a20bf/raw/bashrc" >> ~/.bashrc
#!/usr/bin/env bash
# Function to install Docker if not already installed
install_docker() {
if ! command -v docker &> /dev/null; then
echo "Docker not found, installing..."
curl -sfL https://get.docker.com | bash -e
sudo usermod -aG docker $USER
else
echo "Docker is already installed."
fi
}
# Install Docker
install_docker
# Create Docker network if it doesn't exist
if ! docker network inspect app &> /dev/null; then
docker network create app
echo "Docker network 'app' created."
else
echo "Docker network 'app' already exists."
fi
USER_HOME=$(eval echo ~$USER)
echo "Setting up reverse proxy ....."
mkdir -p ops/traefik/config/
echo "
networks:
app:
external: true
services:
traefik:
image: traefik:v2.11
labels:
- \"traefik.http.routers.dashboard.rule=Host(\`traefik.domain.com\`) && (PathPrefix(\`/api\`) || PathPrefix(\`/dashboard\`))\"
- \"traefik.http.routers.dashboard.service=api@internal\"
ports:
- 80:80
- 443:443
volumes:
- ./config:/etc/traefik
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- app
restart: unless-stopped" > ops/traefik/compose.yaml
echo "
#!/bin/bash
cd $USER_HOME/ops/trafik
if [[ $1 ]]; then
docker compose down -v
exit 0
fi
mkdir -p config/certs
docker compose up --build --detach --scale traefik=1
" > ops/traefik/up.sh
echo "
global:
checkNewVersion: false
sendAnonymousUsage: false
# -- (Optional) Change Log Level and Format here...
# - loglevels [DEBUG, INFO, WARNING, ERROR, CRITICAL]
# - format [common, json, logfmt]
# log:
# level: ERROR
# format: common
# filePath: /var/log/traefik/traefik.log
# -- (Optional) Enable Accesslog and change Format here...
# - format [common, json, logfmt]
# accesslog:
# format: common
# filePath: /var/log/traefik/access.log
# -- (Optional) Enable API and Dashboard here, don't do in production
api:
dashboard: true
# insecure: true
# -- Change EntryPoints here...
entryPoints:
web:
address: :80
# -- (Optional) Redirect all HTTP to HTTPS
http:
redirections:
entryPoint:
to: websecure
scheme: https
websecure:
address: :443
# -- (Optional) Add custom Entrypoint
# custom:
# address: :8080
# -- Configure your CertificateResolver here...
certificatesResolvers:
staging:
acme:
email: your@mail.com
storage: /etc/traefik/certs/acme.json
caServer: \"https://acme-staging-v02.api.letsencrypt.org/directory\"
httpChallenge:
entryPoint: web
production:
acme:
email: your@mail.com
storage: /etc/traefik/certs/acme.json
caServer: \"https://acme-v02.api.letsencrypt.org/directory\"
httpChallenge:
entryPoint: web
# -- (Optional) Disable TLS Cert verification check
serversTransport:
insecureSkipVerify: true
# -- (Optional) Overwrite Default Certificates
# tls:
# stores:
# default:
# defaultCertificate:
# certFile: /etc/traefik/certs/cert.pem
# keyFile: /etc/traefik/certs/cert-key.pem
# -- (Optional) Disable TLS version 1.0 and 1.1
# options:
# default:
# minVersion: VersionTLS12
providers:
docker:
# -- (Optional) Enable this, if you want to expose all containers automatically
exposedByDefault: false
file:
directory: /etc/traefik
watch: true" > ops/traefik/config/traefik.yaml
echo "Setting up PostgreSQL ....."
mkdir -p ops/db/pg
echo "
networks:
app:
external: true
services:
pg:
image: docker.io/bitnami/postgresql:16-debian-11
networks:
- app
ports:
- '5432:5432'
volumes:
- './pg-vol:/bitnami/postgresql'
environment:
- POSTGRESQL_PASSWORD=Password123
volumes:
pg:
name: pg-vol
" > ops/db/pg/docker-compose.yaml
echo "
#!/usr/bin/env bash
cd $USER_HOME/ops/db/pg/
if [[ $1 ]]; then
docker compose down
exit 0
fi
mkdir -p pg-vol
sudo chown -R 1001 pg-vol
docker compose up --build --detach
" > ops/db/pg/up.sh
echo "
#!/usr/bin/env bash
username="postgres"
host="pg"
database="postgres"
docker compose exec -it -e PGPASSWORD="Password123" pg psql -U $username -h $host -d $database
" > ops/db/pg/exe.sh
echo "Setting up redis ..."
mkdir ops/db/redis
echo "
networks:
app:
external: true
services:
redis:
image: 'bitnami/redis:7.2-debian-11'
networks:
- app
ports:
- '5859:6379'
environment:
- REDIS_PASSWORD=UGFzc3dvcmRfMTIzCg
volumes:
- './redis-vol:/bitnami'
" > ops/db/redis/docker-compose.yaml
echo "
#!/bin/bash
cd $USER_HOME/ops/db/redis
if [[ $1 ]]; then
docker compose down
exit 0
fi
mkdir -p redis-vol
sudo chown -R 1001 redis-vol
docker compose up --build --detach
" > ops/db/redis/up.sh
mkdir -p ops/app/backend
mkdir -p ops/app/frontend
echo "
PORT=8080
" > ops/app/backend/.env
echo "
networks:
app:
external: true
services:
api:
image: docker.io/edr3x/test-api:latest
networks:
- app
env_file:
- ./.env
labels:
- \"traefik.enable=true\"
- \"traefik.http.services.api.loadbalancer.server.port=8080\"
- \"traefik.http.services.api.loadbalancer.server.scheme=http\"
- \"traefik.http.routers.api.entrypoints=websecure\"
- \"traefik.http.routers.api.tls.certresolver=production\"
- \"traefik.http.routers.api.rule=Host(\`api.domain.com\`)\"
" > ops/app/backend/docker-compose.yaml
echo "
#!/bin/bash
cd $USER_HOME/ops/app/backend
if [[ $1 ]]; then
docker compose down -v
exit 0
fi
docker compose up --build --detach --scale api=1
" > ops/app/backend/up.sh
echo "
#!/usr/bin/env bash
cd $USER_HOME/ops/app/backend
docker compose up --build --detach --remove-orphans
" > ops/app/deploy-backend.sh
echo "
networks:
app:
external: true
services:
web:
image: docker.io/edr3x/web:latest
restart: always
networks:
- app
labels:
- \"traefik.enable=true\"
- \"traefik.http.services.web.loadbalancer.server.port=3000\"
- \"traefik.http.services.web.loadbalancer.server.scheme=http\"
- \"traefik.http.routers.web.entrypoints=websecure\"
- \"traefik.http.routers.web.tls.certresolver=production\"
- \"traefik.http.routers.web.rule=Host(\`web.domain.com\`)\"
" > ops/app/frontend/docker-compose.yaml
echo "
#!/bin/bash
cd $USER_HOME/ops/app/frontend
if [[ $1 ]]; then
docker compose down -v
exit 0
fi
docker compose up --build --detach --scale cms=1
" > ops/app/frontend/up.sh
set-option -g prefix M-a
unbind-key M-a
bind-key M-a send-prefix
set -s escape-time 50
set -g base-index 1
set -g mouse on
set -g default-terminal "screen-256color"
set -g status-left-length 15
bind -n M-n next-window
bind -n M-p previous-window
# Optional
# decoration
bg=default
fg="#d3d3d3"
orange="#e78a4e"
highlight="#89DDFF"
wg_time="#[nobold]#[bg=${bg},fg=${orange}] %I:%M"
wg_date="#[bold]#[bg=${bg},fg=${highlight}] %d-%b"
set-option -g status-justify left
set-option -g renumber-windows on
set-option -g status-left-length 100
set-option -g status-right-length 150
set -g status-style "bg=${bg} fg=${fg}"
setw -g window-status-current-style fg=${orange},bg=${bg}
set -g window-status-separator ""
set -g window-status-format "#[nobold]#[bg=${bg},fg=${fg}] #W "
set -g window-status-current-format "#[nobold]#[bg=${bg},fg=${orange}] #W "
set -g status-left "#[bold]#[bg=${bg},fg=${highlight}] #S "
set -g status-right " ${wg_time} ${wg_date} "
set -g pane-border-style fg=${fg}
set -g pane-active-border-style fg=${fg}
set-window-option -g mode-style "bg=${orange} fg=#121212"
set -g message-style fg=${orange},bg=${bg}
set -g message-command-style fg=${orange},bg=${bg}
set nocompatible
syntax enable
set encoding=utf-8
set hidden
set nonumber
set noswapfile
set history=200
set synmaxcol=800
set notimeout
set ttimeout
set ttimeoutlen=100
set nowrap
set tabstop=2 shiftwidth=2
set expandtab
set backspace=indent,eol,start
set showcmd
set hlsearch
set incsearch
set ignorecase
set smartcase
set gdefault
set noswapfile
set backupskip=/tmp/*,/private/tmp/*"
if has("statusline") && !&cp
set laststatus=2
set statusline=%f\ %m\ %r
endif
nnoremap - :E<CR>
nnoremap <S-h> ^
nnoremap <S-l> $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment