diff --git a/config/.bin/compose.mw.yaml b/config/.bin/compose.mw.yaml new file mode 100644 index 00000000..2326af52 --- /dev/null +++ b/config/.bin/compose.mw.yaml @@ -0,0 +1,36 @@ +services: + postgres: + image: postgres:16 + container_name: the-postgres + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD= + - POSTGRES_HOST_AUTH_METHOD=trust + volumes: + - the-postgres:/var/lib/postgresql/data + ports: + - 5432:5432 + mysql: + image: mysql:8 + container_name: the-mysql + environment: + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + volumes: + - the-mysql:/var/lib/mysql + ports: + - 3306:3306 + redis: + image: redis:7 + container_name: the-redis + volumes: + - the-redis:/data + ports: + - 6379:6379 + +volumes: + the-postgres: + name: the-postgres + the-mysql: + name: the-mysql + the-redis: + name: the-redis diff --git a/config/.bin/mid b/config/.bin/mid deleted file mode 100755 index ff4d760e..00000000 --- a/config/.bin/mid +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# -# Operates all middlewares transparency - -set -eu -set -o pipefail - -usage() { - cat < [command] - -Available Midlewares: - pg (PostgreSQL) - redis (Redis) - datastore (Google Cloud Datastore) - pubsub (Google Cloud Pub/Sub) -EOF -} - -COMMAND="${1:-}" -shift || true - -if [ -z "$COMMAND" ]; then - usage - exit 0 -fi - -case $COMMAND in - pg|redis|datastore|pubsub) - mid-$COMMAND "$@" - exit 0 - ;; - - --version|-v) - version - exit 0 - ;; - - --help|-h) - usage - exit 0 - ;; - - *) - printutil error "Unknown command: $COMMAND" - usage - exit 1 - ;; -esac diff --git a/config/.bin/mid-datastore b/config/.bin/mid-datastore deleted file mode 100755 index 6d740749..00000000 --- a/config/.bin/mid-datastore +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env bash - -set -eu -set -o pipefail - -NAME=the-cloud-datastore -IMAGE=google/cloud-sdk - - -# Commands -#----------------------------------------------- -usage() { - cat < Stopping server" - docker stop $NAME -} - -server_start() { - echo "==> Starting server" - docker start $NAME 2>/dev/null || server_create -} - -server_rm() { - echo "==> Destroying server" - docker rm $NAME -} - -server_create() { - echo "==> Creating server" - docker run \ - -p 8011:8011 \ - --name $NAME \ - -v ~/docker/datastore:/opt/data \ - -e CLOUDSDK_CORE_PROJECT=mid-datastore \ - -d \ - $IMAGE \ - gcloud beta emulators datastore start --data-dir=/opt/data --host-port=0.0.0.0:8081 -} - -exec_logs() { - docker logs -f $NAME -} - -print_env() { - docker exec -it $NAME \ - gcloud beta emulators datastore env-init --data-dir=/opt/data -} - -exec_command() { - docker exec -it $NAME gcloud datastore "$@" -} - - -# Entrypoint -#----------------------------------------------- -COMMAND="${1:-}" -shift || true - -case "$COMMAND" in - s|start) server_start ;; - stop) server_stop ;; - rm) server_rm ;; - logs) exec_logs ;; - env) print_env;; - --help) usage;; - config) - docker exec -it $NAME gcloud config "$@" - ;; - auth) - docker exec -it $NAME gcloud auth "$@" - ;; - indexes|operations) - exec_command $COMMAND "$@" - ;; - cleanup-indexes|create-indexes|export|import) - exec_command $COMMAND "$@" - ;; - *) - printutil error "Unknown command: $COMMAND" - usage - exit 1 - ;; -esac diff --git a/config/.bin/mid-pg b/config/.bin/mid-pg deleted file mode 100755 index 5ca55594..00000000 --- a/config/.bin/mid-pg +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash - -set -eu -set -o pipefail - -NAME=the-postgres -IMAGE=postgres:14-alpine - - -# Commands -#----------------------------------------------- -usage() { - cat < /dev/null 2>&1 -} - -server_stop() { - echo "==> Stopping server" - docker stop $NAME -} - -server_start() { - echo "==> Starting server" - docker start $NAME 2>/dev/null || server_create - - echo "==> Waiting for ready" - while true; do - sleep 5 - if _ping; then - echo - echo "ready" - break - else - printf '.' - fi - done -} - -server_remove() { - echo "==> Destroying server" - docker rm $NAME -} - -server_create() { - echo "==> Creating server" - docker run \ - -p 5432:5432 \ - --name $NAME \ - -e POSTGRES_HOST_AUTH_METHOD=trust \ - -e POSTGRES_USER=$USER \ - -e POSTGRES_PASSWORD="" \ - -v ~/docker/postgres:/var/lib/postgresql/data \ - -d \ - $IMAGE -} - -exec_command() { - docker exec -it $NAME "$@" -} - -exec_psql() { - # exec_command psql --username=$USER "$@" - exec_command psql "$@" -} - -exec_createdb() { - exec_command createdb --username=$USER "$@" -} - -exec_dropdb() { - exec_command dropdb --username=$USER "$@" -} - -exec_logs() { - docker logs -f $NAME -} - -exec_status() { - if docker ps | grep $NAME > /dev/null; then - if _ping; then - echo 'ready' - else - echo 'not ready' - fi - else - echo 'not running' - fi -} - - -# Entrypoint -#----------------------------------------------- -COMMAND="${1:-}" -shift || true - -case "$COMMAND" in - s|start) server_start ;; - stop) server_stop ;; - rm) server_remove ;; - c|console|psql) exec_psql "$@" ;; - createdb) exec_createdb "$@" ;; - dropdb) exec_dropdb "$@" ;; - status) exec_status ;; - logs) exec_logs ;; - --help) usage;; - *) - printutil error "Unknown command: $COMMAND" - usage - exit 1 - ;; -esac diff --git a/config/.bin/mid-pubsub b/config/.bin/mid-pubsub deleted file mode 100755 index c02e24fd..00000000 --- a/config/.bin/mid-pubsub +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -set -eu -set -o pipefail - -NAME=the-cloud-pubsub -IMAGE=google/cloud-sdk - - -# Commands -#----------------------------------------------- -usage() { - cat < Stopping server" - docker stop $NAME -} - -server_start() { - echo "==> Starting server" - docker start $NAME 2>/dev/null || server_create -} - -server_rm() { - echo "==> Destroying server" - docker rm $NAME -} - -server_create() { - echo "==> Creating server" - docker run \ - -p 8085:8085 \ - --name $NAME \ - -v ~/docker/pubsub:/opt/data \ - -e CLOUDSDK_CORE_PROJECT=mid-pubsub \ - -d \ - $IMAGE \ - gcloud beta emulators pubsub start --data-dir=/opt/data --host-port=0.0.0.0:8085 -} - -exec_logs() { - docker logs -f $NAME -} - -print_env() { - docker exec -it $NAME \ - gcloud beta emulators pubsub env-init --data-dir=/opt/data -} - -exec_command() { - docker exec -it $NAME gcloud pubsub "$@" -} - - -# Entrypoint -#----------------------------------------------- -COMMAND="${1:-}" -shift || true - -case "$COMMAND" in - s|start) server_start ;; - stop) server_stop ;; - rm) server_rm ;; - logs) exec_logs ;; - env) print_env;; - --help) usage;; - config) - docker exec -it $NAME gcloud config "$@" - ;; - auth) - docker exec -it $NAME gcloud auth "$@" - ;; - *) - printutil error "Unknown command: $COMMAND" - usage - exit 1 - ;; -esac diff --git a/config/.bin/mid-redis b/config/.bin/mid-redis deleted file mode 100755 index 2a427006..00000000 --- a/config/.bin/mid-redis +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash - -set -eu -set -o pipefail - -NAME=the-redis -IMAGE=redis:7-alpine - - -# Commands -#----------------------------------------------- -usage() { - cat < Stopping server" - docker stop $NAME -} - -server_start() { - echo "==> Starting server" - docker start $NAME 2>/dev/null || server_create -} - -server_rm() { - echo "==> Destroying server" - docker rm $NAME -} - -server_create() { - echo "==> Creating server" - docker run \ - -p 6379:6379 \ - --name $NAME \ - -v ~/docker/redis:/data \ - -d \ - $IMAGE -} - -exec_command() { - docker exec -it $NAME "$@" -} - -exec_cli() { - exec_command redis-cli "$@" -} - -exec_logs() { - docker logs -f $NAME -} - - -# Entrypoint -#----------------------------------------------- -COMMAND="${1:-}" -shift || true - -case "$COMMAND" in - s|start) server_start ;; - stop) server_stop ;; - rm) server_rm ;; - c|console|cli) exec_cli "$@" ;; - logs) exec_logs ;; - --help) usage;; - *) - printutil error "Unknown command: $COMMAND" - usage - exit 1 - ;; -esac diff --git a/config/.config/zsh/legacy/aliases.zsh b/config/.config/zsh/legacy/aliases.zsh index d2705cd8..b5b1c542 100644 --- a/config/.config/zsh/legacy/aliases.zsh +++ b/config/.config/zsh/legacy/aliases.zsh @@ -22,7 +22,4 @@ fi alias ew='envchain wtd' -alias psql='mid pg psql' -alias createdb='mid pg createdb' -alias dropdb='mid pg dropdb' -alias redis-cli='mid redis exec redis-cli' +alias mw="docker compose -f /Users/izumin/.bin/compose.mw.yaml"