-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(cdc): Prepare the self hosted environment for the Change Data Capture pipeline #938
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7b5074d
Set up pg_hba
fpacifici 66844f8
Download wal2json
fpacifici 57b2d1a
Fix symlink
fpacifici 47e95d6
Pin version when releasing
fpacifici dbc94c6
Change variable name
fpacifici d82b216
Fix script
fpacifici 8844e8d
Address review comments
fpacifici 9d2f8a7
Do not rely on having wget
fpacifici a31b8e1
Fix path
fpacifici 66d0b0c
Ensure the user can write
fpacifici 47906d9
Ensure the user can write
fpacifici 2f62595
Ensure the user can write
fpacifici b2a48a9
Try by redirecting output
fpacifici b10d57c
nit
fpacifici 9e3a60a
Change lib name
fpacifici a5488d4
Merge branch 'master' into feat/cdc_onprem
fpacifici File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| echo "${_group}Downloading and installing wal2json ..." | ||
|
|
||
| FILE_TO_USE="../postgres/wal2json/wal2json.so" | ||
| ARCH=$(uname -m) | ||
| FILE_NAME="wal2json-Linux-$ARCH-glibc.so" | ||
|
|
||
| DOCKER_CURL="docker run --rm curlimages/curl" | ||
|
|
||
| if [[ $WAL2JSON_VERSION == "latest" ]]; then | ||
| VERSION=$( | ||
| $DOCKER_CURL https://api.github.com/repos/getsentry/wal2json/releases/latest | | ||
| grep '"tag_name":' | | ||
| sed -E 's/.*"([^"]+)".*/\1/' | ||
| ) | ||
|
|
||
| if [[ ! $VERSION ]]; then | ||
| echo "Cannot find wal2json latest version" | ||
| exit 1 | ||
| fi | ||
| else | ||
| VERSION=$WAL2JSON_VERSION | ||
| fi | ||
|
|
||
| mkdir -p ../postgres/wal2json | ||
| if [ ! -f "../postgres/wal2json/$VERSION/$FILE_NAME" ]; then | ||
| mkdir -p "../postgres/wal2json/$VERSION" | ||
| $DOCKER_CURL -L \ | ||
| "https://github.com/getsentry/wal2json/releases/download/$VERSION/$FILE_NAME" \ | ||
| > "../postgres/wal2json/$VERSION/$FILE_NAME" | ||
chadwhitacre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cp "../postgres/wal2json/$VERSION/$FILE_NAME" "$FILE_TO_USE" | ||
| fi | ||
|
|
||
| echo "${_endgroup}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/bin/bash | ||
| # Initializes the pg_hba file with access permissions to the replication | ||
| # slots. | ||
|
|
||
| set -e | ||
|
|
||
| { echo "host replication all all trust"; } >> "$PGDATA/pg_hba.conf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/bin/bash | ||
| # This script replaces the default docker entrypoint for postgres in the | ||
| # development environment. | ||
| # Its job is to ensure postgres is properly configured to support the | ||
| # Change Data Capture pipeline (by setting access permissions and installing | ||
| # the replication plugin we use for CDC). Unfortunately the default | ||
| # Postgres image does not allow this level of configurability so we need | ||
| # to do it this way in order not to have to publish and maintain our own | ||
| # Postgres image. | ||
| # | ||
| # This then, at the end, transfers control to the default entrypoint. | ||
|
|
||
| set -e | ||
|
|
||
| prep_init_db() { | ||
| cp /opt/sentry/init_hba.sh /docker-entrypoint-initdb.d/init_hba.sh | ||
| } | ||
|
|
||
| cdc_setup_hba_conf() { | ||
| # Ensure pg-hba is properly configured to allow connections | ||
| # to the replication slots. | ||
|
|
||
| PG_HBA="$PGDATA/pg_hba.conf" | ||
| if [ ! -f "$PG_HBA" ]; then | ||
| echo "DB not initialized. Postgres will take care of pg_hba" | ||
| elif [ "$(grep -c -E "^host\s+replication" "$PGDATA"/pg_hba.conf)" != 0 ]; then | ||
| echo "Replication config already present in pg_hba. Not changing anything." | ||
| else | ||
| # Execute the same script we run on DB initialization | ||
| /opt/sentry/init_hba.sh | ||
| fi | ||
| } | ||
|
|
||
| bind_wal2json() { | ||
| # Copy the file in the right place | ||
| cp /opt/sentry/wal2json/wal2json.so `pg_config --pkglibdir`/wal2json.so | ||
| } | ||
|
|
||
| echo "Setting up Change Data Capture" | ||
|
|
||
| prep_init_db | ||
| if [ "$1" = 'postgres' ]; then | ||
chadwhitacre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cdc_setup_hba_conf | ||
| bind_wal2json | ||
| fi | ||
| exec /docker-entrypoint.sh "$@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.