Debian Codegraph @

internal/librariangen/build-docker-and-test.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Copyright 2025 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # This script builds the librariangen Docker image and then runs a series of
17 # checks inside a container to verify that all dependencies are correctly
18 # installed and available in the PATH.
19
20 set -e # Exit immediately if a command exits with a non-zero status.
21
22 IMAGE_NAME="gcr.io/cloud-go-infra/librariangen:latest"
23
24 echoscip-shell system . . echo. "--- Building Docker Image ---"
25 docker build -t "$IMAGE_NAME" .
26 echoscip-shell system . . echo. "--- Docker Image Built Successfully ---"
27
28 echoscip-shell system . . echo. ""
29 echoscip-shell system . . echo. "--- Verifying Dependencies Inside Container ---"
30
31 # Create a temporary script to act as the test entrypoint.
32 # This script will check for the existence and version of all required tools.
33 catscip-shell system . . cat. > entrypoint-test.sh << EOF
34 #!/bin/bash
35 set -e
36
37 echo "--- Verifying librariangen binary ---"
38 if ! command -v librariangen &> /dev/null; then
39 echo "Error: librariangen not found in PATH."
40 exit 1
41 fi
42 echo "librariangen found."
43 echo "version: \$(librariangen --version)"
44
45 echo ""
46 echo "--- Verifying Go ---"
47 if ! command -v go &> /dev/null; then
48 echo "Error: go not found in PATH."
49 exit 1
50 fi
51 go version
52
53 echo ""
54 echo "--- Verifying protoc ---"
55 if ! command -v protoc &> /dev/null; then
56 echo "Error: protoc not found in PATH."
57 exit 1
58 fi
59 protoc --version
60
61 echo ""
62 echo "--- Verifying Go Plugins ---"
63 if ! command -v protoc-gen-go &> /dev/null; then
64 echo "Error: protoc-gen-go not found in PATH."
65 exit 1
66 fi
67 protoc-gen-go --version
68
69 if ! command -v protoc-gen-go-grpc &> /dev/null; then
70 echo "Error: protoc-gen-go-grpc not found in PATH."
71 exit 1
72 fi
73 protoc-gen-go-grpc --version
74
75 if ! command -v protoc-gen-go_gapic &> /dev/null; then
76 echo "Error: protoc-gen-go_gapic not found in PATH."
77 exit 1
78 fi
79 # The gapic generator does not have a --version flag, so we check for its presence.
80 echo "protoc-gen-go_gapic found."
81
82 echo ""
83 echo "--- Verifying Post-processor Tools ---"
84 if ! command -v goimports &> /dev/null; then
85 echo "Error: goimports not found in PATH."
86 exit 1
87 fi
88 echo "goimports found."
89
90 if ! command -v staticcheck &> /dev/null; then
91 echo "Error: staticcheck not found in PATH."
92 exit 1
93 fi
94 staticcheck --version
95
96 echo ""
97 echo "--- All Dependencies Verified Successfully ---"
98 EOF
99
100 chmodscip-shell system . . chmod. +x entrypoint-test.sh
101
102 # Run the container with the test script as the entrypoint.
103 # We mount the test script into the container and execute it.
104 docker run --rm --entrypoint /bin/bashscip-shell filesystem . . `/bin/bash`. -v "$(pwdscip-shell system . . pwd.)/entrypoint-test.sh:/entrypoint-test.sh" "$IMAGE_NAME" /entrypoint-test.shscip-shell filesystem . . `/entrypoint-test.sh`.
105
106 # Clean up the temporary test script.
107 rmscip-shell system . . rm. entrypoint-test.sh
108
109 echoscip-shell system . . echo. ""
110 echoscip-shell system . . echo. "--- Docker Image Verification Complete ---"