From 73976950bd664bef7d8a5e58e7c38f2e02292173 Mon Sep 17 00:00:00 2001 From: Anton Kurochkin <45575813+woblerr@users.noreply.github.com> Date: Sun, 21 Mar 2021 23:54:17 +0300 Subject: [PATCH] Add pgbackrest-bash-completion script --- .github/workflows/build.yml | 4 +++- Dockerfile | 14 +++++++++++--- Makefile | 5 +++-- README.md | 6 ++++-- files/entrypoint.sh | 3 +++ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c6b5a8..7a0284f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: | diff --git a/Dockerfile b/Dockerfile index f057e04..bcadd19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 @@ -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 \ @@ -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" diff --git a/Makefile b/Makefile index 4f0a6c8..db316a0 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README.md b/README.md index 26837eb..e2d936d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 ``` diff --git a/files/entrypoint.sh b/files/entrypoint.sh index b6851a3..1aaaccc 100644 --- a/files/entrypoint.sh +++ b/files/entrypoint.sh @@ -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 "$@"