Skip to content
Open
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
9 changes: 3 additions & 6 deletions packages/bazel-bot/docker-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ RUN cargo build --release
FROM gcr.io/gapic-images/googleapis:prod
COPY --from=0 /jwt-cli/target/release/jwt /bin/jwt

# Install the github command line tool, and jq to parse json responses.
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt-get update \
# Upgrade packages to patch vulnerabilities.
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y gh jq \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


# Copy the source files from this directory.
COPY generate-googleapis-gen.sh /generate-googleapis-gen.sh
COPY install-credentials.sh /install-credentials.sh
Expand Down
6 changes: 0 additions & 6 deletions packages/bazel-bot/docker-image/container-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ commandTests:
- name: "git version"
command: ["git", "--version"]
expectedOutput: ["git version.*.*"]
- name: "gh version"
command: ["gh", "--version"]
expectedOutput: ["gh version.*"]
- name: "jq version"
command: ["jq", "--version"]
expectedOutput: ["jq-.*"]
- name: "jwt installed"
command: ["jwt", "--version"]
expectedOutput: ["jwt .*"]
2 changes: 1 addition & 1 deletion packages/bazel-bot/docker-image/docker-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RESPONSE=$(curl -X POST \
-H "Authorization: Bearer $JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations/$GITHUB_APP_INSTALLATION_ID/access_tokens)
GITHUB_TOKEN=$(echo "$RESPONSE" | jq -r .token)
GITHUB_TOKEN=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['token'])")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever. It looks like we are using a base image that must already include python so this seems fine. One alternative would be do so this completely with bash instead of an inlined script: GITHUB_TOKEN=$(echo "$RESPONSE" | grep -o '"token": *"[^"]*"' | cut -d'"' -f4)


git clone https://x-access-token:$GITHUB_TOKEN@github.com/googleapis/googleapis-gen.git ${TARGET_CLONE_ARGS}
git clone https://github.com/googleapis/googleapis.git ${SOURCE_CLONE_ARGS}
Expand Down
5 changes: 1 addition & 4 deletions packages/bazel-bot/docker-image/install-credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ GITHUB_TOKEN=$(curl -X POST \
-H "Authorization: Bearer $JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations/$GITHUB_APP_INSTALLATION_ID/access_tokens \
| jq -r .token)

# According to https://cli.github.com/manual/gh_auth_login
echo "$GITHUB_TOKEN" | gh auth login --with-token
| python3 -c "import sys, json; print(json.load(sys.stdin)['token'])")

# According to https://docs.github.com/en/developers/apps/authenticating-with-github-apps#http-based-git-access-by-an-installation
git -C "$GOOGLEAPIS_GEN" remote set-url origin \
Expand Down
Loading