Skip to content

Commit

Permalink
try building outside ctx (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Feb 19, 2024
1 parent c5a52c6 commit e651fb6
Show file tree
Hide file tree
Showing 7 changed files with 1,462 additions and 38 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ FROM golang:1.21 as build
ARG TESTS_ROOT

WORKDIR /go/src
COPY . /tests
COPY . .

RUN CGO_ENABLED=0 cd /tests && go test -c ./...
RUN echo $(pwd)
RUN ls -lah
WORKDIR /go/src/${TESTS_ROOT}
RUN echo $(pwd)
RUN ls -lah
RUN cd /go/src/${TESTS_ROOT} && CGO_ENABLED=0 go test -c ./...

FROM debian
ARG TESTS_ROOT

COPY --from=build /tests .
COPY --from=build /go/src/${TESTS_ROOT} .
RUN apt-get update && apt-get install -y ca-certificates
ENTRYPOINT /bin/bash
7 changes: 4 additions & 3 deletions build_test_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -o pipefail
set +e

# Check if required parameters are provided
if [ "$#" -ne 5 ]; then
echo "Usage: $0 DOCKERFILE_PATH TESTS_ROOT_PATH IMAGE_TAG ECR_REGISTRY_NAME ECR_REGISTRY_REPO_NAME"
if [ "$#" -ne 6 ]; then
echo "Usage: $0 DOCKERFILE_PATH TESTS_ROOT_PATH IMAGE_TAG ECR_REGISTRY_NAME ECR_REGISTRY_REPO_NAME DOCKER_CMD_EXEC_PATH"
exit 1
fi

Expand All @@ -14,9 +14,10 @@ TESTS_ROOT_PATH="$2"
IMAGE_TAG="$3"
ECR_REGISTRY_NAME="$4"
ECR_REGISTRY_REPO_NAME="$5"
DOCKER_CMD_EXEC_PATH="$6"

# Build Docker image
docker build --platform linux/amd64 -t "$IMAGE_TAG" -f "$DOCKERFILE_PATH" --build-arg TESTS_ROOT="$TESTS_ROOT_PATH" "$TESTS_ROOT_PATH"
cd "$DOCKER_CMD_EXEC_PATH" && docker build --platform linux/amd64 -t "$IMAGE_TAG" -f "$DOCKERFILE_PATH" --build-arg TESTS_ROOT="$TESTS_ROOT_PATH" .

# Authenticate Docker with ECR
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin "$ECR_REGISTRY_NAME"
Expand Down
48 changes: 20 additions & 28 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -49,6 +50,7 @@ type ClusterConfig struct {
Namespace string
KeepJobs bool
UpdateImage bool
DockerCmdExecPath string
DockerfilePath string
BuildScriptPath string
BuildCtxPath string
Expand Down Expand Up @@ -87,29 +89,21 @@ func (m *ClusterConfig) Defaults() error {
}
if m.ChartPath == "" {
log.Info().Msg("Using default embedded chart")
f, err := os.CreateTemp(".", defaultArchiveName)
//nolint
defer f.Close()
if err != nil {
return err
}
if _, err := f.Write(defaultChart); err != nil {
if err := os.WriteFile(defaultArchiveName, defaultChart, os.ModePerm); err != nil {
return err
}
m.tmpHelmFilePath, m.ChartPath = f.Name(), f.Name()
m.tmpHelmFilePath, m.ChartPath = defaultArchiveName, defaultArchiveName
}
if m.DockerfilePath == "" {
log.Info().Msg("Using default Dockerfile")
f, err := os.CreateTemp(".", defaultDockerfilePath)
//nolint
defer f.Close()
if err != nil {
log.Info().Msg("Using default embedded Dockerfile")
if err := os.WriteFile(defaultDockerfilePath, DefaultDockerfile, os.ModePerm); err != nil {
return err
}
if _, err := f.Write(DefaultDockerfile); err != nil {
p, err := filepath.Abs(defaultDockerfilePath)
if err != nil {
return err
}
m.DockerfilePath = f.Name()
m.DockerfilePath = p
}
if m.BuildScriptPath == "" {
log.Info().Msg("Using default build script")
Expand Down Expand Up @@ -181,19 +175,17 @@ func (m *ClusterProfile) buildAndPushImage() error {
if err != nil {
return err
}
if err := ExecCmd(
fmt.Sprintf("%s %s %s %s %s %s",
m.cfg.BuildScriptPath,
m.cfg.DockerfilePath,
m.cfg.BuildCtxPath,
tag,
registry,
repo,
),
); err != nil {
return err
}
return nil
cmd := fmt.Sprintf("%s %s %s %s %s %s %s",
m.cfg.BuildScriptPath,
m.cfg.DockerfilePath,
m.cfg.BuildCtxPath,
tag,
registry,
repo,
m.cfg.DockerCmdExecPath,
)
log.Info().Str("Cmd", cmd).Msg("Building docker")
return ExecCmd(cmd)
}

func (m *ClusterProfile) deployHelm(testName string) error {
Expand Down
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ These vars are required to rebuild default layout and update an image
```
Turn off `UpdateImage` if you want to skip the build

By default, we are going one dir up from the cluster entrypoint script and building all:
```
DockerCmdExecPath: "..",
BuildCtxPath: ".",
```
`BuildCtxPath` is relative to `DockerCmdExecPath`

If for some reason you don't like this layout or can't build like `go test -c ./...`, or you would like to customize your builds then you need to customize default [Dockerfile](../Dockerfile) and [build_script](../build_test_image.sh) and reference them in [cluster_entrypoint](zcluster/cluster_test.go)
```
DockerfilePath: "",
BuildScriptPath: "",
```


### Deployment

Default helm chart is [here](../charts/wasp)
Expand Down
193 changes: 193 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
module github.com/smartcontractkit/wasp-tests

go 1.21

require (
github.com/K-Phoen/grabana v0.22.1
github.com/go-resty/resty/v2 v2.11.0
github.com/rs/zerolog v1.32.0
github.com/smartcontractkit/wasp v0.4.4-0.20240218132337-09104882c61f
github.com/stretchr/testify v1.8.4
go.uber.org/ratelimit v0.3.0
nhooyr.io/websocket v1.8.10
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/K-Phoen/sdk v0.12.4 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.44.321 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/strfmt v0.21.7 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/status v1.1.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grafana/dskit v0.0.0-20231120170505-765e343eda4f // indirect
github.com/grafana/gomemcache v0.0.0-20231023152154-6947259a0586 // indirect
github.com/grafana/loki v1.6.2-0.20231215164305-b51b7d7b5503 // indirect
github.com/grafana/loki/pkg/push v0.0.0-20231124142027-e52380921608 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/hashicorp/consul/api v1.25.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/alertmanager v0.26.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/prometheus v0.47.2-0.20231010075449-4b9c19fe5510 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sercand/kuberesolver/v5 v5.1.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
go.mongodb.org/mongo-driver v1.12.0 // indirect
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015 // indirect
go.opentelemetry.io/collector/semconv v0.81.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.1 // indirect
k8s.io/apimachinery v0.28.1 // indirect
k8s.io/client-go v0.28.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

0 comments on commit e651fb6

Please sign in to comment.