diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..27c8c41 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +dist +logs +docs +.env +.env.* +profiles.json +.znf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..97930d9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Builds the dbclone CLI. The image carries only the static binary and the docker CLI: +# every dump and restore still runs inside your local mongo/mysql containers. +FROM golang:1.26-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +ARG VERSION=docker +RUN CGO_ENABLED=0 go build -ldflags "-s -w -X main.version=${VERSION}" -o /dbclone . + +FROM alpine:3.21 +RUN apk add --no-cache docker-cli +COPY --from=build /dbclone /usr/local/bin/dbclone +WORKDIR /work +ENTRYPOINT ["dbclone"] diff --git a/README.md b/README.md index 9ae2dab..ab08476 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,25 @@ go install github.com/phuthuycoding/dbclone@latest # any OS with Go or download a binary from [Releases](https://github.com/phuthuycoding/dbclone/releases) (linux / macOS / windows, amd64 / arm64). +### Or run everything with Docker Compose + +No Go, no binary: the repo's [`compose.yaml`](compose.yaml) starts local MongoDB and MySQL from +the official images, already carrying the root credentials dbclone expects, and builds the CLI +into a small image that talks to them over the Docker socket. + +```bash +git clone https://github.com/phuthuycoding/dbclone && cd dbclone +docker compose up -d # mongodb + mysql +docker compose run --rm dbclone -check # ✓ Docker, ✓ mongo, ✓ mysql +docker compose run --rm dbclone # add profiles, pick FROM / TO / databases +docker compose run --rm dbclone -from staging -only mongo:shop -yes +``` + +Profiles persist in the `dbclone-config` volume; logs land in `./logs`. Override ports or +names with `DBCLONE_MONGO_PORT`, `DBCLONE_MYSQL_PORT`, `DBCLONE_MONGO_CONTAINER`, +`DBCLONE_MYSQL_CONTAINER`, and the local root password with `DBCLONE_LOCAL_PASSWORD` +(default `dbclone`; it only guards the databases on your machine). + ## Usage ```bash diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..f70db26 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,57 @@ +# Everything dbclone needs, with nothing installed on the host but Docker: +# +# docker compose up -d # local MongoDB + MySQL from the official images +# docker compose run --rm dbclone # the CLI itself, talking to them over the Docker socket +# +# Ports, container names and the local root password can be overridden from the +# environment (DBCLONE_MONGO_PORT, DBCLONE_MYSQL_PORT, DBCLONE_MONGO_CONTAINER, +# DBCLONE_MYSQL_CONTAINER, DBCLONE_LOCAL_PASSWORD). The password only guards databases +# on your own machine; dbclone reads it from the containers and never asks for it. + +services: + mongodb: + image: mongo:7 + container_name: ${DBCLONE_MONGO_CONTAINER:-mongodb} + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: ${DBCLONE_LOCAL_PASSWORD:-dbclone} + ports: + - "${DBCLONE_MONGO_PORT:-27017}:27017" + volumes: + - mongodb-data:/data/db + restart: unless-stopped + + mysql: + image: mysql:8.4 + container_name: ${DBCLONE_MYSQL_CONTAINER:-mysql} + environment: + MYSQL_ROOT_PASSWORD: ${DBCLONE_LOCAL_PASSWORD:-dbclone} + ports: + - "${DBCLONE_MYSQL_PORT:-3306}:3306" + volumes: + - mysql-data:/var/lib/mysql + restart: unless-stopped + + # Not started by `up`; run it on demand: docker compose run --rm dbclone [flags] + dbclone: + build: . + image: dbclone:local + profiles: [cli] + environment: + DBCLONE_MONGO_CONTAINER: ${DBCLONE_MONGO_CONTAINER:-mongodb} + DBCLONE_MYSQL_CONTAINER: ${DBCLONE_MYSQL_CONTAINER:-mysql} + volumes: + - /var/run/docker.sock:/var/run/docker.sock # dbclone runs `docker exec` into the two containers above + - dbclone-config:/root/.config/dbclone # profiles.json (mode 0600) survives between runs + - ./logs:/work/logs # per-run tool output lands next to this file + working_dir: /work + stdin_open: true + tty: true + depends_on: + - mongodb + - mysql + +volumes: + mongodb-data: + mysql-data: + dbclone-config: diff --git a/docs/launch/reddit.md b/docs/launch/reddit.md index e6b8e85..43f0e08 100644 --- a/docs/launch/reddit.md +++ b/docs/launch/reddit.md @@ -51,8 +51,9 @@ genuinely answers someone's question. ## r/selfhosted — ONLY in the "New Project Megathread" until 2027-01-02 (rule 6, verified) -Comment, Fri 2026-10-16: 3 lines. Rule 2 wants "production ready and have docs" — point at -the README flag table and `-check`. Wednesday exception (rule 5) allows tool posts with the +Comment, Fri 2026-10-16: 3 lines. Lead with `docker compose up -d && docker compose run --rm dbclone` +(nothing but Docker on the host — the self-hosted angle). Rule 2 wants "production ready and +have docs" — point at the README flag table and `-check`. Wednesday exception (rule 5) allows tool posts with the right flair; still a 3-month-old project is megathread-only, so wait. ## r/commandline — NOT before 2026-11-02 (rule 5: no projects newer than 30 days, verified)