mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2026-11-13 08:37:15 +00:00
feat: mysql-bkup v2 on bkupkit
MysQL backup and restore built on the shared bkupkit core: streaming end to end, with no dump held in memory or written to local disk.
This commit is contained in:
1 parent
ccb3fcdf26
commit
28de0d7b52
65 files changed
+3453
-3871
No files matched your search
+56
-39
@@ -1,47 +1,64 @@
|
||||
FROM golang:1.26.0 AS build
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG GO_IMAGE=golang:1.26.3-trixie
|
||||
ARG RUNTIME_IMAGE=debian:13.7-slim
|
||||
ARG MYSQL_IMAGE=mysql:8.4.13
|
||||
|
||||
FROM --platform=$BUILDPLATFORM ${GO_IMAGE} AS build
|
||||
WORKDIR /app
|
||||
ARG appVersion=""
|
||||
|
||||
# Copy the source code.
|
||||
COPY . .
|
||||
# Installs Go dependencies
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
ARG appVersion="development"
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN GOARM="${TARGETVARIANT#v}" CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||
go build -trimpath -ldflags="-s -w -X main.Version=${appVersion}" -o /out/mysql-bkup .
|
||||
|
||||
# Build
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/jkaninda/mysql-bkup/utils.Version=${appVersion}'" -o /app/mysql-bkup
|
||||
# Oracle MySQL client binaries, per architecture.
|
||||
FROM ${MYSQL_IMAGE} AS mysqlclient-amd64
|
||||
RUN mkdir -p /out && cp /usr/bin/mysql /usr/bin/mysqldump /out/
|
||||
FROM ${MYSQL_IMAGE} AS mysqlclient-arm64
|
||||
RUN mkdir -p /out && cp /usr/bin/mysql /usr/bin/mysqldump /out/
|
||||
FROM ${RUNTIME_IMAGE} AS mysqlclient-arm
|
||||
RUN mkdir -p /out
|
||||
FROM mysqlclient-${TARGETARCH} AS mysqlclient
|
||||
|
||||
FROM alpine:3.23.3
|
||||
FROM ${RUNTIME_IMAGE}
|
||||
ARG appVersion="development"
|
||||
ENV TZ=UTC
|
||||
ARG WORKDIR="/config"
|
||||
ARG BACKUPDIR="/backup"
|
||||
ARG BACKUP_TMP_DIR="/tmp/backup"
|
||||
ARG TEMPLATES_DIR="/config/templates"
|
||||
ARG appVersion=""
|
||||
ENV VERSION=${appVersion}
|
||||
LABEL org.opencontainers.image.title="mysql-bkup"
|
||||
LABEL org.opencontainers.image.description="A lightweight MySQL backup and restore tool"
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.authors="Jonas Kaninda <me@jonaskaninda.com>"
|
||||
LABEL org.opencontainers.image.version=${appVersion}
|
||||
LABEL org.opencontainers.image.source="https://github.com/jkaninda/mysql-bkup"
|
||||
LABEL org.opencontainers.image.title="mysql-bkup" \
|
||||
org.opencontainers.image.description="Back up and restore MySQL and MariaDB databases to local storage, S3, GCS, Azure, SFTP or FTP, with GPG or age encryption" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.authors="Jonas Kaninda <me@jkaninda.dev>" \
|
||||
org.opencontainers.image.version=${appVersion} \
|
||||
org.opencontainers.image.source="https://github.com/jkaninda/mysql-bkup"
|
||||
|
||||
RUN apk --update add --no-cache mysql-client mariadb-connector-c tzdata ca-certificates
|
||||
RUN mkdir -p $WORKDIR $BACKUPDIR $TEMPLATES_DIR $BACKUP_TMP_DIR && \
|
||||
chmod a+rw $WORKDIR $BACKUPDIR $BACKUP_TMP_DIR
|
||||
COPY --from=build /app/mysql-bkup /usr/local/bin/mysql-bkup
|
||||
COPY ./templates/* $TEMPLATES_DIR/
|
||||
RUN chmod +x /usr/local/bin/mysql-bkup && \
|
||||
ln -s /usr/local/bin/mysql-bkup /usr/local/bin/bkup
|
||||
|
||||
# Create backup script and make it executable
|
||||
RUN printf '#!/bin/sh\n/usr/local/bin/mysql-bkup backup "$@"' > /usr/local/bin/backup && \
|
||||
chmod +x /usr/local/bin/backup
|
||||
# Create restore script and make it executable
|
||||
RUN printf '#!/bin/sh\n/usr/local/bin/mysql-bkup restore "$@"' > /usr/local/bin/restore && \
|
||||
chmod +x /usr/local/bin/restore
|
||||
# Create migrate script and make it executable
|
||||
RUN printf '#!/bin/sh\n/usr/local/bin/mysql-bkup migrate "$@"' > /usr/local/bin/migrate && \
|
||||
chmod +x /usr/local/bin/migrate
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
mariadb-client-core libssl3t64 zlib1g libncurses6 libtinfo6 \
|
||||
tini tzdata ca-certificates \
|
||||
&& cd /tmp && apt-get download mariadb-client \
|
||||
&& dpkg-deb --fsys-tarfile mariadb-client_*.deb | tar -x -C / ./usr/bin/mariadb-dump \
|
||||
&& rm -f mariadb-client_*.deb \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR $WORKDIR
|
||||
ENTRYPOINT ["/usr/local/bin/mysql-bkup"]
|
||||
# /usr/local/bin comes first in PATH: mysql and mysqldump are Oracle's there,
|
||||
# while Debian's /usr/bin/mysql* are links to the MariaDB tools.
|
||||
COPY --from=mysqlclient /out/ /usr/local/bin/
|
||||
COPY --from=build /out/mysql-bkup /usr/local/bin/mysql-bkup
|
||||
|
||||
|
||||
RUN mkdir -p /config /backup /tmp/backup \
|
||||
&& chmod 1777 /backup /tmp/backup \
|
||||
&& ln -s /usr/local/bin/mysql-bkup /usr/local/bin/bkup \
|
||||
&& printf '#!/bin/sh\nexec /usr/local/bin/mysql-bkup backup "$@"\n' > /usr/local/bin/backup \
|
||||
&& printf '#!/bin/sh\nexec /usr/local/bin/mysql-bkup restore "$@"\n' > /usr/local/bin/restore \
|
||||
&& printf '#!/bin/sh\nexec /usr/local/bin/mysql-bkup migrate "$@"\n' > /usr/local/bin/migrate \
|
||||
&& chmod +x /usr/local/bin/backup /usr/local/bin/restore /usr/local/bin/migrate \
|
||||
&& (mysqldump --version 2>/dev/null || true) && mariadb-dump --version && mysql-bkup version
|
||||
|
||||
WORKDIR /config
|
||||
HEALTHCHECK --interval=1m --timeout=10s --start-period=1m CMD ["/usr/local/bin/mysql-bkup", "health"]
|
||||
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/mysql-bkup"]
|
||||
Reference in new issue
Block a user