From a68dc3771d285e426b98b79160da74aa915b0761 Mon Sep 17 00:00:00 2001 From: Jonathan Hawk Date: Thu, 22 Aug 2024 14:27:25 -0400 Subject: [PATCH] feat: add REPLACE_SUBJECT and REPLACE_TARGET environment variables --- .github/workflows/release.yml | 4 +++- Dockerfile | 2 +- README.md | 13 ++++++++++++- run.sh | 6 +++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9d762c..6b58093 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,6 +20,7 @@ jobs: - "linux/amd64" - "linux/arm64" alpine_version: + - "3.20" - "3.19" - "3.18" - "3.17" @@ -85,6 +86,7 @@ jobs: fail-fast: false matrix: alpine_version: + - "3.20" - "3.19" - "3.18" - "3.17" @@ -113,7 +115,7 @@ jobs: with: images: ${{ env.REGISTRY_IMAGE }} tags: | - type=raw,value=latest,enabled=${{ matrix.alpine_version == '3.19' }} + type=raw,value=latest,enabled=${{ matrix.alpine_version == '3.20' }} type=raw,value=${{ env.IMAGE_VERSION }}-alpine-${{ matrix.alpine_version }} type=raw,value=${{ env.IMAGE_VERSION }}-alpine-${{ env.ALPINE_FULL_VERSION }} diff --git a/Dockerfile b/Dockerfile index 39d4a8c..fb9bf42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG ALPINE_VERSION=3.19 +ARG ALPINE_VERSION=3.20 FROM alpine:${ALPINE_VERSION} RUN apk add --no-cache mysql-client python3 py3-pip coreutils jq aws-cli diff --git a/README.md b/README.md index fe91b0b..6c0ddcd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,16 @@ An Alpine-based Docker image for producing a file with `mysqldump` and uploading it to Amazon S3. -There are tags for Alpine 3.19, 3.18, and 3.17. Both `linux/amd64` and `linux/arm64`. +There are tags for Alpine 3.20, 3.19, 3.18, and 3.17. This image is available on both the `linux/amd64` and `linux/arm64` platforms. + +```bash +# The latest tag will always point to the most recent version of Alpine. +docker pull @mindgrub/mysqldump-to-s3:latest +docker pull @mindgrub/mysqldump-to-s3:1-alpine-3.20 + +# Pull other versions or architectures. +docker pull --platform linux/arm64 @mindgrub/mysqldump-to-s3:1-alpine-3.18 +``` ## Environment Variables @@ -18,6 +27,8 @@ There are tags for Alpine 3.19, 3.18, and 3.17. Both `linux/amd64` and `linux/ar - `MYSQLDUMP_OPTS` – Optional. Additional command line options to provide to `mysqldump`. - `REQUESTOR` – Optional. The email address of the user who requested this dump to be stored in the S3 metadata. - `SFN_TASK_TOKEN` – Optional. A Step Functions [Task Token](https://docs.aws.amazon.com/step-functions/latest/apireference/API_GetActivityTask.html#StepFunctions-GetActivityTask-response-taskToken). If present, this token will be used to call [`SendTaskHeartbeat`](https://docs.aws.amazon.com/step-functions/latest/apireference/API_SendTaskHeartbeat.html) and [`SendTaskSuccess`](https://docs.aws.amazon.com/step-functions/latest/apireference/API_SendTaskSuccess.html). The task output sent to `SendTaskSuccess` will consist of a JSON object with a single property: `uri` (containing the S3 URI of the database dump). +- `REPLACE_SUBJECT` – Optional. A [Basic Regular Expression (BRE)](https://www.gnu.org/software/sed/manual/html_node/BRE-syntax.html) used to locate strings for replacement (e.g. DEFINER statements). +- `REPLACE_TARGET` – Optional. Text that replaces all instances of the subject. - `MYSQL_NET_BUFFER_LENGTH` – _[Deprecated]_ Optional. The `net_buffer_length` setting for `mysqldump`. ### AWS Permissions diff --git a/run.sh b/run.sh index 1c5bcd6..920cb84 100755 --- a/run.sh +++ b/run.sh @@ -29,7 +29,11 @@ fi set -- "$@" "$DB_NAME" mysqldump_opts=$(printf ' %s' "$@") echo "About to export mysql://$DB_HOST/$DB_NAME to $destination" -eval "mysqldump $mysqldump_opts" | gzip > "$destination" +if [ -n "$REPLACE_SUBJECT" ] && [ -n "$REPLACE_TARGET" ]; then + eval "mysqldump $mysqldump_opts" | sed "s/$REPLACE_SUBJECT/$REPLACE_TARGET/g" | gzip > "$destination" +else + eval "mysqldump $mysqldump_opts" | gzip > "$destination" +fi echo "Export to $destination completed" # Send heartbeat