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

ci: Add a toolchain workflow #1484

Merged
merged 1 commit into from
Feb 11, 2022
Merged
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
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -13,6 +13,11 @@ ARG CARGO_DENY_VERSION=0.11.1
RUN curl --proto '=https' --tlsv1.3 -vsSfL "https://github.com/EmbarkStudios/cargo-deny/releases/download/${CARGO_DENY_VERSION}/cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
| tar zvxf - --strip-components=1 -C /usr/local/bin "cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl/cargo-deny"

FROM docker.io/rust:${RUST_VERSION}-bullseye as yq
ARG YQ_VERSION=v4.2.0
RUN curl --proto '=https' --tlsv1.3 -vsSfLo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" \
&& chmod +x /usr/local/bin/yq

#
# Main image
#
@@ -57,6 +62,7 @@ ENV PATH=$HOME/.linkerd2/bin:$PATH
COPY --from=cargo-deny /usr/local/bin/cargo-deny /usr/local/bin/cargo-deny
COPY --from=k3d /usr/local/bin/k3d /usr/local/bin/k3d
COPY --from=kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=yq /usr/local/bin/yq /usr/local/bin/yq

ENTRYPOINT ["/usr/local/share/docker-init.sh"]
CMD ["sleep", "infinity"]
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkerd2-proxy",
"image": "ghcr.io/linkerd/dev-proxy:v6",
"image": "ghcr.io/linkerd/dev-proxy:v7",
// "dockerFile": "./Dockerfile",
"extensions": [
"matklad.rust-analyzer",
3 changes: 2 additions & 1 deletion .github/actions/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG BASE_IMAGE=rust:1.56.1-buster
ARG RUST_VERSION=1.56.1
ARG BASE_IMAGE=rust:${RUST_VERSION}-buster
FROM $BASE_IMAGE
WORKDIR /linkerd
RUN apt-get update && \
17 changes: 0 additions & 17 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -18,23 +18,6 @@ jobs:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- run: docker build .devcontainer

rust-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- run: |
versions=$(sed -nE 's|^ARG +RUST_VERSION=([^ #]+)|\1|p' .devcontainer/Dockerfile)
ex=0
if [ -z "$versions" ]; then
echo "::error file=.devcontainer/Dockerfile::No Rust versions specified in Dockerfile"
ex=1
fi
for mismatch in $(echo "$versions" | grep -vF "$(cat rust-toolchain)" || true) ; do
echo "::error file=.devcontainer/Dockerfile::Devcontainer uses incorrect rust version(s): $mismatch"
ex=$((ex + 1))
done
exit $ex
devcontainer-image:
runs-on: ubuntu-latest
steps:
60 changes: 60 additions & 0 deletions .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: rust-toolchain

on:
pull_request:
paths:
- rust-toolchain
- "**Dockerfile"
- ".github/workflows/*"
- ".github/**/Dockerfile"

permissions:
contents: read

env:
YQ_VERSION: v4.2.0

jobs:
dockerfiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- run: |
VERSION="$(cat rust-toolchain)"
ex=0
for f in $(find . -name Dockerfile -and -not -path './.github/actions/release-tag-meta/*'); do
versions=$(sed -nE 's/^ARG RUST_VERSION=([^ ]+)/\1/p' $f)
if [ -z "$versions" ]; then
echo "::error file=$f::$f missing 'RUST_VERSION' argument"
ex=$((ex + 1))
fi
for mismatch in $(echo "$version" | grep -vF "$VERSION" || true) ; do
echo "::error file=$f::$f uses incorrect rust version(s): $mismatch"
ex=$((ex + 1))
done
done
exit $ex
workflows:
runs-on: ubuntu-latest
steps:
Copy link
Member

Choose a reason for hiding this comment

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

Might be a silly question but would the yq action simplify anything here?

mikefarah/yq#844 (comment)

I guess it might not be as easy to check the result if we used the action as opposed to doing it in bash during code checkout?

Copy link
Member Author

@olix0r olix0r Feb 11, 2022

Choose a reason for hiding this comment

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

We could perhaps use it to replace the curl/chmod, but it's basically the same thing.

In general I think the curl is simpler and more explicit--less wondering what random code might be running in the action

- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- run: |
curl --proto '=https' --tlsv1.3 -vsSfLo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" \
&& chmod +x /usr/local/bin/yq
- run: |
VERSION="$(cat rust-toolchain)"
ex=0
for f in $(find .github/workflows -name '*.yml') ; do
echo "# $f"
for image in $(yq eval '.jobs[].container.image' $f) ; do
if [[ "$image" =~ "^docker://(docker.io/library/)?rust:" ]]; then
v="${${image##*rust:}%%-*}"
if [[ "$v" != "$VERSION" ]]; then
echo "::warning file=$f::$f uses incorrect rust version: $v"
ex=$((ex + 1))
fi
fi
done
done
exit $ex
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
# :; docker buildx build . --load

# Please make changes via update-rust-version.sh
ARG RUST_IMAGE=rust:1.56.1-buster
ARG RUST_VERSION=1.56.1
ARG RUST_IMAGE=rust:${RUST_VERSION}-buster

# Use an arbitrary ~recent edge release image to get the proxy
# identity-initializing and linkerd-await wrappers.
4 changes: 2 additions & 2 deletions update-rust-version.sh
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$' ; then
fi

echo "$VERSION" > rust-toolchain
find . -name Dockerfile\* \
-exec sed -i'' -Ee "s|rust:[0-9]+\.[0-9]+\.[0-9]+|rust:$VERSION|" '{}' \;
find . -name Dockerfile \
-exec sed -i'' -Ee "s|RUST_VERSION=[0-9]+\.[0-9]+\.[0-9]+|RUST_VERSION=$VERSION|" '{}' \;
find .github -name \*.yml \
-exec sed -i'' -Ee "s|rust:[0-9]+\.[0-9]+\.[0-9]+|rust:$VERSION|" '{}' \;