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

prototype: mount local directory for build #3869

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions images/botreview/Containerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM docker.io/library/golang:1.20 as builder
WORKDIR /go/src/github.com/kubevirt/project-infra/
RUN mkdir -p /go/src/kubevirt/ && \
cd /go/src/kubevirt/ && \
git clone https://github.com/kubevirt/project-infra.git && \
cd project-infra/ && \
go mod vendor && \
env GOPROXY=off GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/botreview ./external-plugins/botreview/main.go
FROM quay.io/kubevirtci/golang:v20241213-57bd934 as builder
ENV GOPROXY=https://proxy.golang.org|direct \
GOFLAGS="-mod=vendor -ldflags=-extldflags=\"-static\"" \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
ENV GIMME_GO_VERSION=1.21.6
RUN if [ ! -d /project-infra ]; then git clone https://github.com/kubevirt/project-infra.git /project-infra; fi && \
cd /project-infra/ && \
/usr/local/bin/runner.sh /bin/sh -ce "env GOPROXY=off GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/botreview ./external-plugins/botreview/main.go"

FROM gcr.io/k8s-prow/git:v20240729-4f255edb07
COPY --from=builder /go/bin/botreview /usr/bin/botreview
Expand Down
27 changes: 22 additions & 5 deletions images/publish_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

main() {
local build_only
while getopts "bh" opt; do
local no_cache
local project_infra_dir="/home/prow/go/src/github.com/kubevirt/project-infra"
while getopts "bcp:h" opt; do
case "$opt" in
b)
build_only=true
;;
c)
no_cache=true
;;
p) project_infra_dir="$OPTARG"
;;
h)
help
exit 0
Expand Down Expand Up @@ -36,7 +43,7 @@ main() {
(
cd "$build_target"

build_image "$build_target" "$full_image_name"
build_image "$no_cache" "$build_target" "$full_image_name" "$project_infra_dir"
)
[[ $build_only ]] && return
publish_image "$full_image_name"
Expand All @@ -52,6 +59,7 @@ help() {
OPTIONS
-h Show this help message and exit.
-b Only build the image and exit. Do not publish the built image.
-p Local project-infra directory
EOF
}

Expand All @@ -63,9 +71,18 @@ get_image_tag() {
}

build_image() {
local build_target="${1:?}"
local image_name="${2:?}"
podman build . -t "$image_name" -t "$build_target"
local no_cache="${1:-}"
local build_target="${2:?}"
local image_name="${3:?}"
local project_infra_dir="${4:-}"
build_args=""
if [ -d "$project_infra_dir" ]; then
build_args="-v $project_infra_dir:/project-infra"
fi
if [ "$no_cache" = "true" ]; then
build_args="$build_args --no-cache"
fi
podman build $build_args . -t "$image_name" -t "$build_target"
}

publish_image() {
Expand Down