Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add REPLACE_SUBJECT and REPLACE_TARGET environment variables #3

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- "linux/amd64"
- "linux/arm64"
alpine_version:
- "3.20"
- "3.19"
- "3.18"
- "3.17"
Expand Down Expand Up @@ -85,6 +86,7 @@ jobs:
fail-fast: false
matrix:
alpine_version:
- "3.20"
- "3.19"
- "3.18"
- "3.17"
Expand Down Expand Up @@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading