-
Notifications
You must be signed in to change notification settings - Fork 586
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
WIP: testing docker linter #911
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.19.13-bookworm | ||
|
||
RUN apt-get update && apt-get install -y git | ||
ENV GOCACHE=/tmp/build/.cache | ||
ENV GOMODCACHE=/tmp/build/.modcache | ||
|
||
COPY . /tmp/tools | ||
|
||
RUN cd /tmp \ | ||
&& mkdir -p /tmp/build/.cache \ | ||
&& mkdir -p /tmp/build/.modcache \ | ||
&& cd /tmp/tools \ | ||
&& go install -trimpath github.com/golangci/golangci-lint/cmd/[email protected] \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here, re pinning the version in a |
||
&& chmod -R 777 /tmp/build/ \ | ||
&& git config --global --add safe.directory /build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We added this line when we didn't know what the actual issue was and it's more of an ugly hack. The "better" solution would be this environment variable: https://github.com/lightninglabs/pool/blob/master/tools/Dockerfile#L6 So just We should probably update this in other projects too to make things more consistent (and to avoid us copying the "hacky" version to new projects). |
||
|
||
WORKDIR /build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if the Dockerfile contains only the specified Go version | ||
check_go_version() { | ||
local dockerfile="$1" | ||
local required_go_version="$2" | ||
|
||
# Use grep to find lines with 'FROM golang:' | ||
local go_lines=$(grep -i '^FROM golang:' "$dockerfile") | ||
|
||
# Check if all lines have the required Go version | ||
if echo "$go_lines" | grep -q -v "$required_go_version"; then | ||
echo "Error: $dockerfile does not use Go version $required_go_version exclusively." | ||
exit 1 | ||
else | ||
echo "$dockerfile is using Go version $required_go_version." | ||
fi | ||
} | ||
|
||
# Check if the target Go version argument is provided | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 <target_go_version>" | ||
exit 1 | ||
fi | ||
|
||
target_go_version="$1" | ||
|
||
# We find target files using the 'find' command in conjunction with the 'read' | ||
# command. We exclude some directories from the search. | ||
# | ||
# We use the 'read' command to help ensure that we correctly handle filenames | ||
# with spaces, newlines, and special characters. The '-print0' option in 'find' | ||
# outputs filenames separated by a null character. This allows the 'read' | ||
# command in the while loop to accurately distinguish each filename. The | ||
# 'target_files' array is then populated, preserving the integrity of each | ||
# filename. This approach ensures safe handling of filenames, regardless of | ||
# their complexity. | ||
while IFS= read -r -d '' file; do | ||
target_files+=("$file") | ||
done < <(find . \ | ||
-path ./vendor -prune -o \ | ||
-type f \ | ||
\( -name "*.Dockerfile" -o -name "Dockerfile" \) \ | ||
-print0 \ | ||
) | ||
|
||
# Check for the expected Go version in each file. | ||
for file in "${target_files[@]}"; do | ||
check_go_version "$file" "$target_go_version" | ||
done | ||
|
||
|
||
echo "All Dockerfiles pass the Go version check for Go version $target_go_version." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if the YAML file contains the specified Go version after 'GO_VERSION:' | ||
check_go_version() { | ||
local yamlfile="$1" | ||
local required_go_version="$2" | ||
|
||
# Use grep to find lines with 'GO_VERSION:' | ||
local go_lines=$(grep -i 'GO_VERSION:' "$yamlfile" || true) # Ignore grep exit status | ||
|
||
# Check if any lines specify the Go version | ||
if [ -n "$go_lines" ]; then | ||
# Extract the Go version from the file's lines. Example matching strings: | ||
# GO_VERSION: "1.21.0" | ||
# GO_VERSION: '1.21.0' | ||
# GO_VERSION: 1.21.0 | ||
# GO_VERSION:1.21.0 | ||
# GO_VERSION:1.21.0 | ||
local extracted_go_version=$(echo "$go_lines" | sed -n 's/^[[:space:]]*GO_VERSION:[[:space:]]*\(['\''"]\?\)\?\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(['\''"]\?\)\?/\2/p') | ||
|
||
# Check if the extracted Go version matches the required version | ||
if [ "$extracted_go_version" != "$required_go_version" ]; then | ||
echo "Error: $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'." | ||
exit 1 | ||
else | ||
echo "$yamlfile specifies Go version $required_go_version." | ||
fi | ||
fi | ||
} | ||
|
||
# Check if the target Go version argument is provided | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 <target_go_version>" | ||
exit 1 | ||
fi | ||
|
||
target_go_version="$1" | ||
|
||
# We find target files using the 'find' command in conjunction with the 'read' | ||
# command. We exclude some directories from the search. | ||
# | ||
# We use the 'read' command to help ensure that we correctly handle filenames | ||
# with spaces, newlines, and special characters. The '-print0' option in 'find' | ||
# outputs filenames separated by a null character. This allows the 'read' | ||
# command in the while loop to accurately distinguish each filename. The | ||
# 'target_files' array is then populated, preserving the integrity of each | ||
# filename. This approach ensures safe handling of filenames, regardless of | ||
# their complexity. | ||
while IFS= read -r -d '' file; do | ||
target_files+=("$file") | ||
done < <(find . \ | ||
-path ./vendor -prune -o \ | ||
-type f \ | ||
\( -name "*.yaml" -o -name "*.yml" \) \ | ||
-print0 \ | ||
) | ||
|
||
# Check for the expected Go version in each file. | ||
for file in "${target_files[@]}"; do | ||
check_go_version "$file" "$target_go_version" | ||
done | ||
|
||
echo "All YAML files pass the Go version check for Go version $target_go_version." |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,10 @@ func (m *mockChainClient) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, | |
return nil, nil | ||
} | ||
|
||
func (m *mockChainClient) GetBlockHeight(*chainhash.Hash) (int32, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same method needs to be added to the |
||
return 0, nil | ||
} | ||
|
||
func (m *mockChainClient) IsCurrent() bool { | ||
return false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
LINT_COMMIT
below is now unused.It would also be nice if we could remove the
GOACC_COMMIT
andGOIMPORTS_COMMIT
values as well by creating ago.mod
file in thetools
directory that pins these versions, then just install them from thetools
directory as we do here: https://github.com/lightninglabs/taproot-assets/blob/main/Makefile#L79