Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add containerized make commands. Resolves #6519 #6618

Closed
wants to merge 11 commits into from
Closed
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ scan-%:
.PHONY: codegen
codegen: types swagger docs manifests

.PHONY: codegen-container
codegen-container:
./hack/makecmd.sh codegen

.PHONY: types
types: pkg/apis/workflow/v1alpha1/generated.proto pkg/apis/workflow/v1alpha1/openapi_generated.go pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go

Expand Down
29 changes: 29 additions & 0 deletions hack/Dockerfile-tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:1.16-alpine

# upgrade grep fixes alpine busybox error
RUN apk add make bash git protoc protobuf-dev perl curl \
&& apk add --no-cache --upgrade grep

# install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN chmod u+x kubectl && mv kubectl /bin/kubectl

# cache mod dependencies
WORKDIR /go/src/github.com/argoproj/argo-workflows
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go mod vendor

# install go binaries in dockerfile - faster than at runtime
RUN go install -mod=vendor ./vendor/k8s.io/code-generator/cmd/go-to-protobuf
RUN go install -mod=vendor ./vendor/github.com/gogo/protobuf/protoc-gen-gogo
RUN go install -mod=vendor ./vendor/github.com/gogo/protobuf/protoc-gen-gogofast
RUN go install -mod=vendor ./vendor/golang.org/x/tools/cmd/goimports
RUN go install -mod=vendor ./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
RUN go install -mod=vendor ./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
RUN go install -mod=vendor ./vendor/k8s.io/kube-openapi/cmd/openapi-gen
RUN go install -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
45 changes: 45 additions & 0 deletions hack/makecmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

build_tools_image() {
docker build -t argo-wf-tools -f ./hack/Dockerfile-tools .
}

run_mounted_command() {
docker run \
-it \
--mount type=bind,source="$(pwd)",target=/go/src/github.com/argoproj/argo-workflows \
argo-wf-tools \
"$@"
}

prune_docker_images() {
docker image prune -f
}

prune_docker_containers() {
docker container prune -f
}

ensure_vendor() {
go mod vendor
}

for arg in "$@"
do
case $arg in
tools-image)
build_tools_image
;;
codegen)
ensure_vendor
build_tools_image
run_mounted_command make codegen
prune_docker_containers
prune_docker_images
;;
prune)
prune_docker_containers
prune_docker_images
;;
esac
done