forked from opencost/opencost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
151 lines (131 loc) · 4.85 KB
/
Copy pathjustfile
File metadata and controls
151 lines (131 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
commonenv := "CGO_ENABLED=0"
version := `./tools/image-tag`
commit := `git rev-parse --short HEAD`
default:
just --list
# format all Go code
fmt:
go fmt ./...
cd ./core && go fmt ./...
cd ./modules/collector-source && go fmt ./...
cd ./modules/prometheus-source && go fmt ./...
cd ./modules/pricing/basic && go fmt ./...
cd ./modules/pricing/public && go fmt ./...
# check if code is formatted
fmt-check:
#!/bin/sh
echo "Checking code formatting..."
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then \
echo "The following files are not formatted:"; \
echo "$unformatted"; \
echo ""; \
echo "Run 'just fmt' to format your code"; \
exit 1; \
fi
echo "All files are properly formatted"
# run core unit tests
test-core:
{{commonenv}} cd ./core && go test ./... -coverprofile=coverage.out
{{commonenv}} cd ./core && go vet ./...
# run prometheus-source unit tests
test-prometheus-source:
{{commonenv}} cd ./modules/prometheus-source && go test ./... -coverprofile=coverage.out
{{commonenv}} cd ./modules/prometheus-source && go vet ./...
# run collector-source unit tests
test-collector-source:
{{commonenv}} cd ./modules/collector-source && go test ./... -coverprofile=coverage.out
{{commonenv}} cd ./modules/collector-source && go vet ./...
# run the opencost unit tests
test-opencost:
{{commonenv}} go test ./... -coverprofile=coverage.out
{{commonenv}} go tool cover -html=coverage.out -o coverage.html
{{commonenv}} go vet ./...
# Run unit tests, merge coverage reports, remove old reports
test: test-core test-prometheus-source test-collector-source test-opencost
find . -name "coverage.out" -print0 | xargs -0 cat > coverage.new
find . -name "coverage.out" -delete
mv coverage.new coverage.out
# Run unit tests and integration tests
test-integration:
{{commonenv}} INTEGRATION=true go test ./... -coverprofile=coverage.out
# Compile a local binary
build-local:
cd ./cmd/costmodel && \
{{commonenv}} go build \
-ldflags \
"-X github.com/opencost/opencost/core/pkg/version.Version={{version}} \
-X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
-o ./costmodel
# Build multiarch binaries
build-binary VERSION=version:
cd ./cmd/costmodel && \
{{commonenv}} GOOS=linux GOARCH=amd64 go build \
-ldflags \
"-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
-X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
-o ./costmodel-amd64
cd ./cmd/costmodel && \
{{commonenv}} GOOS=linux GOARCH=arm64 go build \
-ldflags \
"-X github.com/opencost/opencost/core/pkg/version.Version={{VERSION}} \
-X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
-o ./costmodel-arm64
# Build and push a multi-arch image using Docker
build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
docker buildx build \
--rm \
--platform "linux/amd64" \
-f 'Dockerfile.cross' \
--build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
--build-arg version={{RELEASE_VERSION}} \
--build-arg commit={{commit}} \
--provenance=false \
-t {{IMAGE_TAG}}-amd64 \
--push \
.
docker buildx build \
--rm \
--platform "linux/arm64" \
-f 'Dockerfile.cross' \
--build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
--build-arg version={{RELEASE_VERSION}} \
--build-arg commit={{commit}} \
--provenance=false \
-t {{IMAGE_TAG}}-arm64 \
--push \
.
manifest-tool push from-args \
--platforms "linux/amd64,linux/arm64" \
--template {{IMAGE_TAG}}-ARCH \
--target {{IMAGE_TAG}}
# Build and push a multi-arch image using Podman
build-podman IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
podman build \
--rm \
--platform "linux/amd64" \
-f 'Dockerfile.cross' \
--build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
--build-arg version={{RELEASE_VERSION}} \
--build-arg commit={{commit}} \
-t {{IMAGE_TAG}}-amd64 \
.
podman push {{IMAGE_TAG}}-amd64
podman build \
--rm \
--platform "linux/arm64" \
-f 'Dockerfile.cross' \
--build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
--build-arg version={{RELEASE_VERSION}} \
--build-arg commit={{commit}} \
-t {{IMAGE_TAG}}-arm64 \
.
podman push {{IMAGE_TAG}}-arm64
podman manifest create {{IMAGE_TAG}} \
{{IMAGE_TAG}}-amd64 \
{{IMAGE_TAG}}-arm64
podman manifest push --all {{IMAGE_TAG}}
podman manifest rm {{IMAGE_TAG}}
validate-protobuf:
./generate.sh
git diff --exit-code