Skip to content

Commit

Permalink
chore: add protoc-gen script to releng (2.x) (#23697)
Browse files Browse the repository at this point in the history
* chore: add protoc-gen script to releng

* chore: break cross-container-tag into separate variable

* fix: call GNUMakefile "generate-sources" target instead

This also does a better job at mounting the root directory
in the docker container.
  • Loading branch information
bnpfeife authored and jsternberg committed Sep 13, 2022
1 parent b51fefd commit 1c6fbf9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ orbs:
aws-s3: circleci/aws-s3@2.0.0
terraform: circleci/terraform@2.1.0

parameters:
cross-container-tag:
type: string
default: go1.18.5-81cd97477f9a6c9f2db03dc56f560bf54f8da8bb

executors:
cross-builder:
docker:
# NOTE: To upgrade the Go version, first push the upgrade to the cross-builder Dockerfile
# in the edge repo, then update the version here to match.
- image: quay.io/influxdb/cross-builder:go1.18.5-bc9c7f5b200055b18d50111c54d3aa59fc798d5f
- image: quay.io/influxdb/cross-builder:<< pipeline.parameters.cross-container-tag >>
resource_class: large
linux-amd64:
machine:
Expand Down
49 changes: 49 additions & 0 deletions releng/protoc-gen
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -o errexit \
-o nounset \
-o pipefail

ROOT="$(realpath "${BASH_SOURCE}")" # -> <project root>/releng/protoc-gen
ROOT="$(dirname "${ROOT}")" # -> <project root>/releng/
ROOT="$(dirname "${ROOT}")" # -> <project root>/

(
# Since this script is run outside of a docker container, it is
# possible that one (or more) of the following executables is
# not installed.
set -x
which docker
which sudo
which yq
) 1>/dev/null

CROSS_BUILDER_VERSION="$(yq -e eval '.parameters.cross-container-tag.default' "${ROOT}/.circleci/config.yml")"

# Updating ownership within the container requires both the "UID" and "GID"
# of the current user. Since the current user does not exist within the
# container, "${USER}:" cannot be supplied to `chown`.
USER_UID="$(id -u)"
USER_GID="$(id -g)"

read -d '' DOCKERSCRIPT <<EOF || true
set -o errexit \
-o nounset \
-o pipefail
touch /tmp/timestamp
git config --global --add safe.directory /project
pushd /project
make generate-sources
# If the previous command generated a new file, it will have "root:root"
# ownership. This becomes an annoyance to work with (i.e git complains
# when checking out branches). To circumvent this issue, update all
# new files to the correct ownership.
find . -newer /tmp/timestamp -exec chown -v "${USER_UID}:${USER_GID}" "{}" \\\;
EOF

sudo docker run --rm -it -v "${ROOT}:/project" "quay.io/influxdb/cross-builder:${CROSS_BUILDER_VERSION}" bash -c "${DOCKERSCRIPT}"

0 comments on commit 1c6fbf9

Please sign in to comment.