forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Fix dirty working copy on travis build and more
This commit combines a few changes to the build. Namely: 1. The travis build no longer works off a dirty working copy. The .dockerignore file was excluding the docs directory which caused the working copy to become dirty during the build process. While this isn't a huge issue it does make it harder to be confident about the state of the source that Travis binaries are built from. As part of this change, we remove the builder image in favour of running the golang image and volume mounting the working copy. This is avoids the copy that is quite expensive in the OPA repo. 2. In the recent build refactoring, the wasm development workflow was broken. Changes to the wasm library were not getting picked up automatically when running the wasm/rego tests. This commit fixes the makefile so that the wasm libary is rebuilt and the wasm blob is copied and regenerated each time the wasm/rego tests are run. Finally, this commit leans into modules a bit more removing the scheduler test dependency on GOPATH. Signed-off-by: Torin Sandall <[email protected]>
- Loading branch information
Showing
11 changed files
with
161 additions
and
114 deletions.
There are no files selected for viewing
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,6 +15,7 @@ site.tar.gz | |
policy.wasm | ||
.npm | ||
.gitbook | ||
.go | ||
|
||
# ci artifacts | ||
fuzzit | ||
|
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 |
---|---|---|
@@ -1,22 +1,19 @@ | ||
# Copyright 2019 The OPA Authors. All rights reserved. | ||
# Use of this source code is governed by an Apache2 | ||
# license that can be found in the LICENSE file. | ||
|
||
ARG VARIANT | ||
ARG BUILD_COMMIT | ||
# we cant use build-args in `COPY --from=...` below, so work around this | ||
# see: https://medium.com/@tonistiigi/advanced-multi-stage-build-patterns-6f741b852fae | ||
FROM build-${BUILD_COMMIT} AS copy-src | ||
|
||
FROM gcr.io/distroless/base${VARIANT} | ||
# make root (uid 0) default when not specified | ||
# Any non-zero number will do, and unfortunately a named user will not, as k8s | ||
# pod securityContext runAsNonRoot can't resolve the user ID: | ||
# https://github.com/kubernetes/kubernetes/issues/40958. Make root (uid 0) when | ||
# not specified. | ||
ARG USER=0 | ||
MAINTAINER Torin Sandall <[email protected]> | ||
COPY --from=copy-src /go/src/github.com/open-policy-agent/opa/opa_linux_amd64 /opa | ||
|
||
# Any non-zero number will do, and unfortunately a named user will not, | ||
# as k8s pod securityContext runAsNonRoot can't resolve the user ID: | ||
# https://github.com/kubernetes/kubernetes/issues/40958 | ||
USER ${USER} | ||
FROM gcr.io/distroless/base${VARIANT} | ||
|
||
MAINTAINER Torin Sandall <[email protected]> | ||
COPY opa_linux_amd64 /opa | ||
USER ${USER} | ||
ENTRYPOINT ["/opa"] | ||
CMD ["run"] |
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
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,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script executes the Wasm Rego test cases. The script uses Docker to run | ||
# the test generation progam and then again to run the test cases inside of a | ||
# Node JS container. The script cachces the test generation program build | ||
# results in the $PWD/.go directory so that it can be re-used across runs. The | ||
# volumes from the test generation container are shared with the Node JS | ||
# container to avoid copying the generated test cases more than necessary. | ||
|
||
set -ex | ||
|
||
GOVERSION=${GOVERSION:?"You must set the GOVERSION environment variable."} | ||
VERBOSE=${VERBOSE:-"0"} | ||
TESTGEN_CONTAINER_NAME="opa-wasm-testgen-container" | ||
TESTRUN_CONTAINER_NAME="opa-wasm-testrun-container" | ||
|
||
function main { | ||
trap interrupt SIGINT SIGTERM | ||
mkdir -p $PWD/.go/cache/go-build | ||
mkdir -p $PWD/.go/bin | ||
generate_testcases | ||
run_testcases | ||
} | ||
|
||
function interrupt { | ||
echo "caught interrupt: exiting" | ||
purge_testgen_container | ||
purge_testrun_container | ||
exit 1 | ||
} | ||
|
||
function purge_testgen_container { | ||
docker kill $TESTGEN_CONTAINER_NAME >/dev/null 2>&1 || true | ||
docker rm $TESTGEN_CONTAINER_NAME >/dev/null 2>&1 || true | ||
} | ||
|
||
function purge_testrun_container { | ||
docker kill $TESTRUN_CONTAINER_NAME >/dev/null 2>&1 || true | ||
docker rm $TESTRUN_CONTAINER_NAME >/dev/null 2>&1 || true | ||
} | ||
|
||
function generate_testcases { | ||
purge_testgen_container | ||
docker run \ | ||
--name $TESTGEN_CONTAINER_NAME \ | ||
-u $(id -u):$(id -g) \ | ||
-v $PWD/.go/bin:/go/bin \ | ||
-v $PWD:/src \ | ||
-e GOCACHE=/src/.go/cache \ | ||
-w /src \ | ||
golang:$GOVERSION \ | ||
sh -c 'make wasm-rego-testgen-install \ | ||
&& wasm-rego-testgen \ | ||
--input-dir=/src/test/wasm/assets \ | ||
--output=/src/.go/cache/testcases.tar.gz' | ||
} | ||
|
||
function run_testcases { | ||
# NOTE(tsandall): background the container because the interrupt trap does | ||
# not run otherwise. | ||
purge_testrun_container | ||
docker run \ | ||
--rm \ | ||
--name $TESTRUN_CONTAINER_NAME \ | ||
--volumes-from $TESTGEN_CONTAINER_NAME \ | ||
-e VERBOSE=$VERBOSE \ | ||
-w /scratch \ | ||
node:8 \ | ||
sh -c 'tar xzf \ | ||
/src/.go/cache/testcases.tar.gz \ | ||
&& node test.js opa.wasm' & | ||
wait $! | ||
} | ||
|
||
main |
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
File renamed without changes.
File renamed without changes.