Skip to content

Commit f89db88

Browse files
committed
feat(wal-g): use wal-e replace to wal-g
1 parent cd3884d commit f89db88

14 files changed

Lines changed: 76 additions & 360 deletions

File tree

Dockerfile

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
FROM postgres:9.4-alpine
1+
FROM minio/mc:RELEASE.2018-11-06T01-12-20Z as mc
22

3-
ENV WALE_LOG_DESTINATION stderr
4-
ENV WALE_ENVDIR /etc/wal-e.d/env
5-
6-
RUN mkdir -p $WALE_ENVDIR \
7-
&& echo 'http://dl-cdn.alpinelinux.org/alpine/v3.5/main' >> /etc/apk/repositories \
8-
&& apk add --update --virtual .build-deps \
9-
git \
10-
build-base \
11-
libffi-dev \
12-
openssl-dev \
13-
python3-dev=3.5.6-r0 \
14-
linux-headers \
15-
&& apk add \
16-
lzo \
17-
pv \
18-
util-linux \
19-
ca-certificates \
20-
python3=3.5.6-r0 \
21-
&& pip3 install --upgrade pip setuptools \
22-
&& pip install --disable-pip-version-check --no-cache-dir \
23-
psycopg2-binary==2.7.6.1 \
24-
envdir==1.0.1 \
25-
wal-e[aws,azure,google,swift]==1.1.0 \
26-
gcloud==0.18.3 \
27-
oauth2client==4.1.3 \
28-
azure-storage==0.20.0 \
29-
&& apk del .build-deps \
30-
&& rm -rf /var/cache/apk/*
3+
FROM postgres:11-alpine
314

325
COPY rootfs /
6+
COPY --from=mc /usr/bin/mc /bin/mc
7+
8+
ENV PGDATA $PGDATA/$PG_MAJOR
9+
ENV WALG_ENVDIR /etc/wal-g.d/env
10+
ADD https://github.com/wal-g/wal-g/releases/download/v0.2.4/wal-g.linux-amd64.tar.gz /bin
3311

34-
ARG PATCH_CMD="python3 /patcher-script.py"
35-
RUN $PATCH_CMD file /bin/create_bucket /patcher-script.d/patch_boto_s3.py
36-
RUN $PATCH_CMD module wal_e.cmd /patcher-script.d/patch_boto_s3.py
37-
RUN $PATCH_CMD module wal_e.worker.worker_util /patcher-script.d/patch_wal_e_s3.py
12+
RUN mkdir -p $WALG_ENVDIR \
13+
&& tar -xvzf /bin/wal-g.linux-amd64.tar.gz -C /bin && rm /bin/wal-g.linux-amd64.tar.gz \
14+
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
15+
&& apk add --allow-untrusted glibc-2.28-r0.apk \
16+
&& rm glibc-2.28-r0.apk \
17+
&& apk add --no-cache jq python3 \
18+
&& pip3 install --upgrade pip setuptools \
19+
&& pip install envdir
3820

3921
CMD ["/docker-entrypoint.sh", "postgres"]
4022
EXPOSE 5432

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ test: test-style test-functional
3030
test-style:
3131
${DEV_ENV_CMD} shellcheck $(SHELL_SCRIPTS)
3232

33-
test-functional: test-functional-swift test-functional-minio
33+
test-functional: test-functional-minio
3434

3535
test-functional-minio:
3636
contrib/ci/test-minio.sh ${IMAGE}
3737

38-
test-functional-swift:
39-
contrib/ci/test-swift.sh ${IMAGE}
40-
4138
.PHONY: all docker-build docker-push test

contrib/ci/test-minio.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ create-postgres-creds
1818

1919
puts-step "creating fake minio credentials"
2020

21+
mkdir -p "${CURRENT_DIR}"/tmp/aws-user
22+
echo "us-east-1" > "${CURRENT_DIR}"/tmp/aws-user/region
23+
echo "database-bucket" > "${CURRENT_DIR}"/tmp/aws-user/database-bucket
2124
echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/accesskey
2225
echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/secretkey
2326

24-
echo $CURRENT_DIR
2527
# boot minio
28+
mkdir -p "${CURRENT_DIR}"/tmp/bin
29+
echo "ls /home/minio/*/*/basebackups_005" > "${CURRENT_DIR}"/tmp/bin/backups.sh
2630
MINIO_JOB=$(docker run -d \
27-
-v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/drycc/minio/user \
31+
-v "${CURRENT_DIR}"/tmp/bin:/tmp/bin \
32+
-v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/drycc/objectstore/creds \
2833
quay.io/drycc/minio:canary server /home/minio/)
2934

3035
# boot postgres, linking the minio container and setting DRYCC_MINIO_SERVICE_HOST and DRYCC_MINIO_SERVICE_PORT
@@ -44,12 +49,12 @@ check-postgres "${PG_JOB}"
4449

4550
# check if minio has the 5 backups
4651
puts-step "checking if minio has 5 backups"
47-
BACKUPS="$(docker exec "${MINIO_JOB}" ls /home/minio/dbwal/basebackups_005/ | grep json)"
52+
BACKUPS="$(docker exec "${MINIO_JOB}" sh /tmp/bin/backups.sh | grep json)"
4853
NUM_BACKUPS="$(echo "${BACKUPS}" | wc -w)"
4954
# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
5055
# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
51-
if [[ ! "${NUM_BACKUPS}" -eq "5" && ! "${NUM_BACKUPS}" -eq "6" ]]; then
52-
puts-error "did not find 5 or 6 base backups. 5 is the default, but 6 may exist if a backup is currently in progress (found $NUM_BACKUPS)"
56+
if [[ "${NUM_BACKUPS}" -lt "5" ]]; then
57+
puts-error "the number of backups is less than 5 (found $NUM_BACKUPS)"
5358
puts-error "${BACKUPS}"
5459
exit 1
5560
fi

contrib/ci/test-swift.sh

Lines changed: 0 additions & 80 deletions
This file was deleted.

contrib/ci/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ start-postgres() {
2828
export PG_JOB
2929
PG_JOB=$($1)
3030
# wait for postgres to boot
31-
puts-step "sleeping for 90s while postgres is booting..."
32-
sleep 90s
31+
puts-step "sleeping for 30s while postgres is booting..."
32+
sleep 30s
3333
}
3434

3535
check-postgres() {

rootfs/bin/create_bucket

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,8 @@
1-
#!/usr/bin/env python3
2-
3-
import os
4-
5-
import boto.s3
6-
import json
7-
import swiftclient
8-
from boto import config as botoconfig
9-
from boto.exception import S3CreateError
10-
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
11-
from oauth2client.service_account import ServiceAccountCredentials
12-
from gcloud.storage.client import Client
13-
from gcloud import exceptions
14-
from azure.storage.blob import BlobService
15-
16-
def bucket_exists(conn, name):
17-
bucket = conn.lookup(name)
18-
if not bucket:
19-
return False
20-
return True
21-
22-
bucket_name = os.getenv('BUCKET_NAME')
23-
region = os.getenv('S3_REGION')
24-
25-
if os.getenv('DATABASE_STORAGE') == "s3":
26-
conn = boto.s3.connect_to_region(region)
27-
if not bucket_exists(conn, bucket_name):
28-
try:
29-
if region == "us-east-1":
30-
# use "US Standard" region. workaround for https://github.com/boto/boto3/issues/125
31-
conn.create_bucket(bucket_name)
32-
else:
33-
conn.create_bucket(bucket_name, location=region)
34-
# NOTE(bacongobbler): for versions prior to v2.9.0, the bucket is created in the default region.
35-
# if we got here, we need to propagate "us-east-1" into WALE_S3_ENDPOINT because the bucket
36-
# exists in a different region and we cannot find it.
37-
# TODO(bacongobbler): deprecate this once we drop support for v2.8.0 and lower
38-
except S3CreateError as err:
39-
if region != 'us-east-1':
40-
print('Failed to create bucket in {}. We are now assuming that the bucket was created in us-east-1.'.format(region))
41-
with open(os.path.join(os.environ['WALE_ENVDIR'], "WALE_S3_ENDPOINT"), "w+") as file:
42-
file.write('https+path://s3.amazonaws.com:443')
43-
else:
44-
raise
45-
46-
elif os.getenv('DATABASE_STORAGE') == "gcs":
47-
scopes = ['https://www.googleapis.com/auth/devstorage.full_control']
48-
credentials = ServiceAccountCredentials.from_json_keyfile_name(os.getenv('GOOGLE_APPLICATION_CREDENTIALS'), scopes=scopes)
49-
with open(os.getenv('GOOGLE_APPLICATION_CREDENTIALS')) as data_file:
50-
data = json.load(data_file)
51-
conn = Client(credentials=credentials, project=data['project_id'])
52-
exists = True
53-
try:
54-
conn.get_bucket(bucket_name)
55-
except exceptions.NotFound:
56-
exists = False
57-
except:
58-
raise
59-
if not exists:
60-
conn.create_bucket(bucket_name)
61-
62-
elif os.getenv('DATABASE_STORAGE') == "azure":
63-
conn = BlobService(account_name=os.getenv('WABS_ACCOUNT_NAME'), account_key=os.getenv('WABS_ACCESS_KEY'))
64-
#It doesn't throw an exception if the container exists by default(https://github.com/Azure/azure-storage-python/blob/master/azure/storage/blob/baseblobservice.py#L504).
65-
conn.create_container(bucket_name)
66-
67-
elif os.getenv('DATABASE_STORAGE') == "swift":
68-
conn = swiftclient.Connection(
69-
user=os.getenv('SWIFT_USER'),
70-
key=os.getenv('SWIFT_PASSWORD'),
71-
authurl=os.getenv('SWIFT_AUTHURL'),
72-
auth_version=os.getenv('SWIFT_AUTH_VERSION'),
73-
tenant_name=os.getenv('SWIFT_TENANT')
74-
)
75-
# swift also does not throw exception if container already exists.
76-
conn.put_container(os.getenv('BUCKET_NAME'))
77-
78-
else:
79-
if not botoconfig.has_section("s3"):
80-
botoconfig.add_section('s3')
81-
botoconfig.set('s3', 'use-sigv4', 'True')
82-
if not botoconfig.has_section("Boto"):
83-
botoconfig.add_section('Boto')
84-
botoconfig.set('Boto', 'is_secure', 'False')
85-
conn = S3Connection(
86-
host=os.getenv('S3_HOST'),
87-
port=int(os.getenv('S3_PORT')),
88-
calling_format=OrdinaryCallingFormat())
89-
# HACK(bacongobbler): allow boto to connect to minio by changing the region name for s3v4 auth
90-
conn.auth_region_name = os.getenv('S3_REGION')
91-
if not bucket_exists(conn, bucket_name):
92-
conn.create_bucket(bucket_name)
1+
#!/usr/bin/env bash
2+
3+
# shellcheck disable=SC1091
4+
source /bin/normalize_storage
5+
has_bucket=$(mc ls minio -json|jq -r '.key'|grep -w "${MINIO_BUCKET}")
6+
if [ ! -n "$has_bucket" ] ;then
7+
mc mb minio/"${MINIO_BUCKET}"
8+
fi

rootfs/bin/do_backup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ if [[ -f "$PGDATA/recovery.conf" ]] ; then
88
sleep 9
99
else
1010
# perform a backup
11-
envdir "$WALE_ENVDIR" wal-e backup-push "$PGDATA"
11+
envdir "$WALG_ENVDIR" wal-g backup-push "$PGDATA"
1212
# only retain the latest BACKUPS_TO_RETAIN backups
13-
envdir "$WALE_ENVDIR" wal-e delete --confirm retain "$BACKUPS_TO_RETAIN"
13+
envdir "$WALG_ENVDIR" wal-g delete --confirm retain "$BACKUPS_TO_RETAIN"
1414
echo "Backup has been completed."
1515
fi

rootfs/bin/normalize_storage

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env sh
2+
BUCKET_FILE="/var/run/secrets/drycc/objectstore/creds/database-bucket"
3+
ACCESS_KEY_FILE="/var/run/secrets/drycc/objectstore/creds/accesskey"
4+
SECRET_KEY_FILE="/var/run/secrets/drycc/objectstore/creds/secretkey"
5+
6+
if [ -f $BUCKET_FILE ]; then
7+
export MINIO_BUCKET=$(cat "$BUCKET_FILE")
8+
fi
9+
if [ -f $ACCESS_KEY_FILE ]; then
10+
export MINIO_ACCESS_KEY=$(cat "$ACCESS_KEY_FILE")
11+
fi
12+
if [ -f $SECRET_KEY_FILE ]; then
13+
export MINIO_SECRET_KEY=$(cat "$SECRET_KEY_FILE")
14+
fi
15+
16+
export MINIO_ENDPOINT=http://"${DRYCC_MINIO_SERVICE_HOST}:${DRYCC_MINIO_SERVICE_PORT}"
17+
18+
mc config host add minio "${MINIO_ENDPOINT}" "${MINIO_ACCESS_KEY}" "${MINIO_SECRET_KEY}"

0 commit comments

Comments
 (0)