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

release-21.2: acceptance: run python, psql containers as current uid #81551

Merged
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
1 change: 1 addition & 0 deletions pkg/acceptance/compose/gss/docker-compose-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- ../../../../cockroach-linux-2.6.32-gnu-amd64:/cockroach/cockroach
python:
build: ./python
user: "${UID}:${GID}"
depends_on:
- cockroach
environment:
Expand Down
1 change: 1 addition & 0 deletions pkg/acceptance/compose/gss/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- ../../../../cockroach-linux-2.6.32-gnu-amd64:/cockroach/cockroach
psql:
build: ./psql
user: "${UID}:${GID}"
depends_on:
- cockroach
environment:
Expand Down
11 changes: 9 additions & 2 deletions pkg/acceptance/compose/gss/psql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ RUN GO111MODULE=off go get -d -t -tags gss_compose
RUN GO111MODULE=off go test -v -c -tags gss_compose -o gss.test

# Copy the test binary to an image with psql and krb installed.
FROM postgres:11.15
FROM postgres:11

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends \
ca-certificates \
curl \
krb5-user

COPY --from=builder /workspace/gss.test .

ENTRYPOINT ["/start.sh"]
RUN curl -fsSL "https://github.com/benesch/autouseradd/releases/download/1.3.0/autouseradd-1.3.0-amd64.tar.gz" -o autouseradd.tar.gz \
&& echo "442dae58b727a79f81368127fac141d7f95501ffa05f8c48943d27c4e807deb7 autouseradd.tar.gz" | sha256sum -c - \
&& tar xzf autouseradd.tar.gz --strip-components 1 \
&& rm autouseradd.tar.gz

ENTRYPOINT ["autouseradd", "--user", "roach", "--no-create-home", "/start.sh"]
2 changes: 1 addition & 1 deletion pkg/acceptance/compose/gss/psql/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ echo "Preparing SQL user ahead of test"
env \
PGSSLKEY=/certs/client.root.key \
PGSSLCERT=/certs/client.root.crt \
psql -c "ALTER USER root WITH PASSWORD rootpw"
psql -U root -c "ALTER USER root WITH PASSWORD rootpw"

echo "Running test"
./gss.test
8 changes: 7 additions & 1 deletion pkg/acceptance/compose/gss/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-k
echo "deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends \
curl \
krb5-user \
postgresql-client-11

RUN curl -fsSL "https://github.com/benesch/autouseradd/releases/download/1.3.0/autouseradd-1.3.0-amd64.tar.gz" -o autouseradd.tar.gz \
&& echo "442dae58b727a79f81368127fac141d7f95501ffa05f8c48943d27c4e807deb7 autouseradd.tar.gz" | sha256sum -c - \
&& tar xzf autouseradd.tar.gz --strip-components 1 \
&& rm autouseradd.tar.gz

RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

ENTRYPOINT ["/start.sh"]
ENTRYPOINT ["autouseradd", "--user", "roach", "--no-create-home", "/start.sh"]
11 changes: 11 additions & 0 deletions pkg/acceptance/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
)

Expand All @@ -32,6 +33,16 @@ func TestComposeFlyway(t *testing.T) {
}

func testCompose(t *testing.T, path string, exitCodeFrom string) {
uid := os.Getuid()
err := os.Setenv("UID", strconv.Itoa(uid))
if err != nil {
t.Fatalf(err.Error())
}
gid := os.Getgid()
err = os.Setenv("GID", strconv.Itoa(gid))
if err != nil {
t.Fatalf(err.Error())
}
cmd := exec.Command(
"docker-compose",
"--no-ansi",
Expand Down