-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preprocessor: install multiple versions of CUE in docker image
WIP Preprocessor-No-Write-Cache: true Signed-off-by: Paul Jolly <[email protected]> Change-Id: Ie8f2da1cac137ce8c390b5c6d08dcb449c4ff78a Dispatch-Trailer: {"type":"trybot","CL":1177003,"patchset":3,"ref":"refs/changes/03/1177003/3","targetBranch":"alpha"}
- Loading branch information
Showing
11 changed files
with
300 additions
and
41 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
content/docs/howto/use-net-ipcidr-to-validate-ip-cidr-ranges/gen_cache.cue
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,18 +15,37 @@ RUN \ | |
export GOCACHE=/cache/gocache GOMODCACHE=/cache/gomodcache && \ | ||
go install -trimpath github.com/rogpeppe/go-internal/cmd/[email protected] | ||
|
||
RUN mkdir /cues | ||
|
||
RUN \ | ||
--mount=type=cache,target=/cache/gocache \ | ||
--mount=type=cache,target=/cache/gomodcache \ | ||
export GOCACHE=/cache/gocache GOMODCACHE=/cache/gomodcache && \ | ||
GOBIN=/cues/latest go install -trimpath cuelang.org/go/cmd/[email protected] | ||
|
||
RUN \ | ||
--mount=type=cache,target=/cache/gocache \ | ||
--mount=type=cache,target=/cache/gomodcache \ | ||
export GOCACHE=/cache/gocache GOMODCACHE=/cache/gomodcache && \ | ||
go install -trimpath cuelang.org/go/cmd/[email protected] | ||
GOBIN=/cues/prerelease go install -trimpath cuelang.org/go/cmd/[email protected] | ||
|
||
RUN \ | ||
--mount=type=cache,target=/cache/gocache \ | ||
--mount=type=cache,target=/cache/gomodcache \ | ||
export GOCACHE=/cache/gocache GOMODCACHE=/cache/gomodcache && \ | ||
GOBIN=/cues/tip go install -trimpath cuelang.org/go/cmd/[email protected] | ||
|
||
FROM golang:1.22.0 | ||
|
||
RUN mkdir -p /go/bin | ||
|
||
# TODO: make this more principled with respect to cue.versions | ||
ENV PATH="/cues/prerelease:${PATH}" | ||
|
||
ENV PATH="/go/bin:/usr/local/go/bin:${PATH}" | ||
ENV CUE_VERSION="v0.8.0-alpha.1" | ||
ENV CUELANG_CUE_LATEST="v0.7.1" | ||
ENV CUELANG_CUE_PRERELEASE="v0.8.0-alpha.1" | ||
ENV CUELANG_CUE_TIP="v0.8.0-alpha.1" | ||
|
||
WORKDIR / | ||
|
||
|
@@ -36,6 +55,8 @@ RUN chmod 755 /usr/bin/entrypoint.sh | |
RUN chown root:root /usr/bin/entrypoint.sh | ||
|
||
COPY --from=build /go/bin/testscript /go/bin | ||
COPY --from=build /go/bin/cue /go/bin | ||
COPY --from=build /cues/latest/cue /cues/latest/cue | ||
COPY --from=build /cues/prerelease/cue /cues/prerelease/cue | ||
COPY --from=build /cues/tip/cue /cues/tip/cue | ||
|
||
ENTRYPOINT ["/usr/bin/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2024 The CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
// The code below is copied and modified from the Go source as of | ||
// 9cc0f9cba2f2db97f5ba6c2c482bafaaa34c0381 | ||
// | ||
// Copyright 2010 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// expand replaces ${var} or $var in the string based on the mapping function | ||
// if the mapping function returns true. | ||
func expand(s string, mapping func(string) (bool, string)) string { | ||
var buf []byte | ||
// ${} is all ASCII, so bytes are fine for this operation. | ||
i := 0 | ||
for j := 0; j < len(s); j++ { | ||
if s[j] == '$' && j+1 < len(s) { | ||
if buf == nil { | ||
buf = make([]byte, 0, 2*len(s)) | ||
} | ||
buf = append(buf, s[i:j]...) | ||
name, w := getShellName(s[j+1:]) | ||
if name == "" && w > 0 { | ||
// Encountered invalid syntax; eat the | ||
// characters. | ||
} else if name == "" { | ||
// Valid syntax, but $ was not followed by a | ||
// name. Leave the dollar character untouched. | ||
buf = append(buf, s[j]) | ||
} else { | ||
mapped, repl := mapping(name) | ||
if mapped { | ||
buf = append(buf, repl...) | ||
} else { | ||
buf = append(buf, s[j:j+1+w]...) | ||
} | ||
} | ||
j += w | ||
i = j + 1 | ||
} | ||
} | ||
if buf == nil { | ||
return s | ||
} | ||
return string(buf) + s[i:] | ||
} | ||
|
||
// isShellSpecialVar reports whether the character identifies a special | ||
// shell variable such as $*. | ||
func isShellSpecialVar(c uint8) bool { | ||
switch c { | ||
case '*', '#', '$', '@', '!', '?', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// isAlphaNum reports whether the byte is an ASCII letter, number, or underscore. | ||
func isAlphaNum(c uint8) bool { | ||
return c == '_' || '0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' | ||
} | ||
|
||
// getShellName returns the name that begins the string and the number of bytes | ||
// consumed to extract it. If the name is enclosed in {}, it's part of a ${} | ||
// expansion and two more bytes are needed than the length of the name. | ||
func getShellName(s string) (string, int) { | ||
switch { | ||
case s[0] == '{': | ||
if len(s) > 2 && isShellSpecialVar(s[1]) && s[2] == '}' { | ||
return s[1:2], 3 | ||
} | ||
// Scan to closing brace | ||
for i := 1; i < len(s); i++ { | ||
if s[i] == '}' { | ||
if i == 1 { | ||
return "", 2 // Bad syntax; eat "${}" | ||
} | ||
return s[1:i], i + 1 | ||
} | ||
} | ||
return "", 1 // Bad syntax; eat "${" | ||
case isShellSpecialVar(s[0]): | ||
return s[0:1], 1 | ||
} | ||
// Scan alphanumerics. | ||
var i int | ||
for i = 0; i < len(s) && isAlphaNum(s[i]); i++ { | ||
} | ||
return s[:i], i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 The CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-quicktest/qt" | ||
) | ||
|
||
func TestExpand(t *testing.T) { | ||
mapping := func(s string) (bool, string) { | ||
switch s { | ||
case "BANANA": | ||
return true, "apple" | ||
default: | ||
return false, "" | ||
} | ||
} | ||
cases := []struct { | ||
name string | ||
input string | ||
want string | ||
}{ | ||
{ | ||
name: "entire string", | ||
input: "$BANANA", | ||
want: "apple", | ||
}, | ||
{ | ||
name: "double dollar", // nothing replace | ||
input: "$$BANANA", | ||
want: "$$BANANA", | ||
}, | ||
{ | ||
name: "braces", | ||
input: "${BANANA}", | ||
want: "apple", | ||
}, | ||
{ | ||
name: "another var", // left untouched | ||
input: "$SOMETHING", | ||
want: "$SOMETHING", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
got := expand(c.input, mapping) | ||
qt.Assert(t, qt.Equals(got, c.want)) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.