Skip to content

Commit

Permalink
Add pgbackrest-bash-completion script
Browse files Browse the repository at this point in the history
  • Loading branch information
woblerr authored Mar 21, 2021
1 parent 8727489 commit 7397695
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
pgbackrest_version: ["2.29", "2.30", "2.31", "2.32" ]
env:
latest_version: "2.32"
pgbackrest_completion_version: "v0.2"
steps:
- uses: actions/checkout@v2

Expand All @@ -21,10 +22,11 @@ jobs:
- name: Build pgbackrest images
run: |
docker build --rm -f Dockerfile --build-arg BACKREST_VERSION=${TAG} --build-arg REPO_BUILD_TAG=${REPO_TAG} -t pgbackrest:${TAG} .
docker build --rm -f Dockerfile --build-arg BACKREST_VERSION=${TAG} --build-arg REPO_BUILD_TAG=${REPO_TAG} --build-arg BACKREST_COMPLETION_VERSION=${COMPL_TAG} -t pgbackrest:${TAG} .
env:
TAG: ${{ matrix.pgbackrest_version }}
REPO_TAG: ${{ steps.vars.outputs.repo_tag }}
COMPL_TAG: ${{ env.pgbackrest_completion_version }}

- name: Test pgbackrest images
run: |
Expand Down
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:20.04 AS builder

ARG BACKREST_VERSION
ARG BACKREST_COMPLETION_VERSION

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
Expand All @@ -19,13 +20,17 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN wget https://github.com/pgbackrest/pgbackrest/archive/release/${BACKREST_VERSION}.tar.gz -O /tmp/${BACKREST_VERSION}.tar.gz \
&& tar -xzf /tmp/${BACKREST_VERSION}.tar.gz -C /tmp \
RUN wget https://github.com/pgbackrest/pgbackrest/archive/release/${BACKREST_VERSION}.tar.gz -O /tmp/pgbackrest-${BACKREST_VERSION}.tar.gz \
&& tar -xzf /tmp/pgbackrest-${BACKREST_VERSION}.tar.gz -C /tmp \
&& mv /tmp/pgbackrest-release-${BACKREST_VERSION} /tmp/pgbackrest-release \
&& cd /tmp/pgbackrest-release/src \
&& ./configure \
&& make

RUN wget https://github.com/woblerr/pgbackrest-bash-completion/archive/${BACKREST_COMPLETION_VERSION}.tar.gz -O /tmp/pgbackrest-bash-completion-${BACKREST_COMPLETION_VERSION}.tar.gz \
&& tar -xzf /tmp/pgbackrest-bash-completion-${BACKREST_COMPLETION_VERSION}.tar.gz -C /tmp \
&& mv /tmp/pgbackrest-bash-completion-$(echo ${BACKREST_COMPLETION_VERSION} | tr -d v) /tmp/pgbackrest-bash-completion

FROM ubuntu:20.04

ARG REPO_BUILD_TAG
Expand All @@ -52,6 +57,7 @@ COPY files/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh \
&& groupadd --gid ${BACKREST_GID} ${BACKREST_GROUP} \
&& useradd --uid ${BACKREST_UID} --gid ${BACKREST_GID} -m ${BACKREST_USER} \
&& mkdir -p -m 755 /etc/bash_completion.d \
&& mkdir -p -m 755 /var/log/pgbackrest \
&& mkdir -p -m 755 /etc/pgbackrest/conf.d \
&& touch /etc/pgbackrest/pgbackrest.conf \
Expand All @@ -62,7 +68,9 @@ RUN chmod +x /entrypoint.sh \
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone

LABEL \
COPY --from=builder /tmp/pgbackrest-bash-completion/pgbackrest-completion.sh /etc/bash_completion.d

LABEL \
org.opencontainers.image.version="${REPO_BUILD_TAG}" \
org.opencontainers.image.source="https://github.com/woblerr/docker-pgbackrest"

Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
BACKREST_VERSIONS = 2.29 2.30 2.31 2.32
TAG?=2.32
BACKREST_COMP_VERSION?=v0.2

all: $(BACKREST_VERSIONS)

.PHONY: $(BACKREST_VERSIONS)
$(BACKREST_VERSIONS):
@echo "Build pgbackrest:$@ docker image"
docker build --pull -f Dockerfile --build-arg BACKREST_VERSION=$@ -t pgbackrest:$@ .
docker build --pull -f Dockerfile --build-arg BACKREST_VERSION=$@ -build-arg BACKREST_COMPLETION_VERSION=$(BACKREST_COMP_VERSION) -t pgbackrest:$@ .
docker run pgbackrest:$@

.PHONY: build_version
build_version:
@echo "Build pgbackrest:$(TAG) docker image"
docker build --pull -f Dockerfile --build-arg BACKREST_VERSION=$(TAG) -t pgbackrest:$(TAG) .
docker build --pull -f Dockerfile --build-arg BACKREST_VERSION=$(TAG) --build-arg BACKREST_COMPLETION_VERSION=$(BACKREST_COMP_VERSION) -t pgbackrest:$(TAG) .
docker run pgbackrest:$(TAG)
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ docker pull ghcr.io/woblerr/pgbackrest:tag

## Run

You will need to mount the necessary directories or files inside the container (or use this image to build your own on top of it)
You will need to mount the necessary directories or files inside the container (or use this image to build your own on top of it).

### Simple

Expand All @@ -49,6 +49,8 @@ docker run --rm pgbackrest:2.32 pgbackrest help

### Injecting inside

The image contains [pgbackrest-bash-completion](https://github.com/woblerr/pgbackrest-bash-completion) script. You can complete `pgbackrest` commands by pressing tab key.

```bash
docker run --rm -it pgbackrest:2.32 bash

Expand Down Expand Up @@ -112,5 +114,5 @@ docker build -f Dockerfile --build-arg BACKREST_VERSION=2.32 -t pgbackrest:2.32
or

```bash
make build TAG=2.32
make build_version TAG=2.32
```
3 changes: 3 additions & 0 deletions files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ if [ "${uid}" = "0" ]; then
if [ "${BACKREST_USER}" != "pgbackrest" ] || [ "${BACKREST_UID}" != "2001" ]; then
usermod -g ${BACKREST_GID} -l ${BACKREST_USER} -u ${BACKREST_UID} -m -d /home/${BACKREST_USER} pgbackrest
fi
# Correct user:group
chown -R ${BACKREST_USER}:${BACKREST_GROUP} /var/log/pgbackrest /etc/pgbackrest
# pgBackRest completion
echo "source /etc/bash_completion.d/pgbackrest-completion.sh" >> /home/${BACKREST_USER}/.bashrc
exec gosu ${BACKREST_USER} "$@"
else
exec "$@"
Expand Down

0 comments on commit 7397695

Please sign in to comment.