Skip to content

Commit 1c308b5

Browse files
authored
Merge pull request #2976 from xrstf/add-images-prowjob
🌱 Add images Prowjob
2 parents bc275d9 + f90b590 commit 1c308b5

File tree

5 files changed

+116
-12
lines changed

5 files changed

+116
-12
lines changed

.github/workflows/kcp-image.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ on:
1010
- 'release-*'
1111
tags:
1212
- 'v*'
13-
pull_request:
14-
branches:
15-
- main
16-
- 'release-*'
17-
paths-ignore:
18-
- "docs/**"
19-
- "**/*.md"
20-
- ".github/ISSUE_TEMPLATE/*"
21-
- ".github/workflows/docs-gen-and-push.yaml"
22-
- ".goreleaser.yaml"
2313

2414
jobs:
2515
build:

.prow.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ presubmits:
5353
memory: 4Gi
5454
cpu: 2
5555

56+
- name: pull-kcp-build-image
57+
always_run: true
58+
decorate: true
59+
clone_uri: "https://github.com/kcp-dev/kcp"
60+
labels:
61+
preset-goproxy: "true"
62+
spec:
63+
containers:
64+
- image: quay.io/containers/buildah:v1.30.0
65+
command:
66+
- hack/build-image.sh
67+
env:
68+
- name: DRY_RUN
69+
value: '1'
70+
# docker-in-docker needs privileged mode
71+
securityContext:
72+
privileged: true
73+
resources:
74+
requests:
75+
memory: 1Gi
76+
cpu: 1
77+
5678
- name: pull-kcp-test-unit
5779
always_run: true
5880
decorate: true

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
# Build the binary
18-
FROM --platform=${BUILDPLATFORM} golang:1.19 AS builder
18+
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.19 AS builder
1919
WORKDIR /workspace
2020

2121
# Install dependencies.

hack/build-image.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 The KCP Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
# make git available
20+
if ! [ -x "$(command -v git)" ]; then
21+
echo "Installing git ..."
22+
yum install -y git
23+
fi
24+
25+
# in CI, make use of the registry mirror to avoid getting rate limited
26+
if [ -n "${DOCKER_REGISTRY_MIRROR_ADDR:-}" ]; then
27+
# remove "http://" or "https://" prefix
28+
mirror="$(echo "$DOCKER_REGISTRY_MIRROR_ADDR" | awk -F// '{print $NF}')"
29+
30+
echo "Configuring registry mirror for docker.io ..."
31+
32+
cat <<EOF > /etc/containers/registries.conf.d/mirror.conf
33+
[[registry]]
34+
prefix = "docker.io"
35+
insecure = true
36+
location = "$mirror"
37+
EOF
38+
fi
39+
40+
repository=ghcr.io/kcp-dev/kcp
41+
architectures="amd64 arm64 ppc64le"
42+
43+
# when building locally, just tag with the current HEAD hash
44+
version="$(git rev-parse --short HEAD)"
45+
46+
# deduce the tag from the Prow job metadata
47+
if [ -n "${PULL_BASE_REF:-}" ]; then
48+
version="$(git tag --list "$PULL_BASE_REF")"
49+
50+
# if the base ref did not point to a tag, it's just a commit hash
51+
if [ -z "$version" ]; then
52+
version="$(git rev-parse --short "$PULL_BASE_REF")"
53+
fi
54+
fi
55+
56+
image="$repository:$version"
57+
echo "Building container image $image ..."
58+
59+
# build image for all architectures
60+
for arch in $architectures; do
61+
fullTag="$image-$arch"
62+
63+
echo "Building $version-$arch ..."
64+
buildah build-using-dockerfile \
65+
--file Dockerfile \
66+
--tag "$fullTag" \
67+
--arch "$arch" \
68+
--override-arch "$arch" \
69+
--build-arg "TARGETOS=linux" \
70+
--build-arg "TARGETARCH=$arch" \
71+
--format=docker \
72+
.
73+
done
74+
75+
echo "Creating manifest $image ..."
76+
buildah manifest create "$image"
77+
for arch in $architectures; do
78+
buildah manifest add "$image" "$image-$arch"
79+
done
80+
81+
# push manifest, except in presubmits
82+
if [ -z "${DRY_RUN:-}" ]; then
83+
echo "Logging into GHCR ..."
84+
buildah login --username "$KCP_GHCR_USERNAME" --password "$KCP_GHCR_PASSWORD" ghcr.io
85+
86+
echo "Pushing manifest and images ..."
87+
buildah manifest push --all "$image" "docker://$image"
88+
else
89+
echo "Not pushing images because \$DRY_RUN is set."
90+
fi
91+
92+
echo "Done."

hack/verify-go-versions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set -o pipefail
1919

2020
VERSION=$(grep "go 1." go.mod | sed 's/go //')
2121

22-
grep "FROM .* golang:" Dockerfile | { ! grep -v "${VERSION}"; } || { echo "Wrong go version in Dockerfile, expected ${VERSION}"; exit 1; }
22+
grep "FROM .* docker.io/golang:" Dockerfile | { ! grep -v "${VERSION}"; } || { echo "Wrong go version in Dockerfile, expected ${VERSION}"; exit 1; }
2323
grep -w "go-version:" .github/workflows/*.yaml | { ! grep -v "go-version: v${VERSION}"; } || { echo "Wrong go version in .github/workflows/*.yaml, expected ${VERSION}"; exit 1; }
2424

2525
shopt -s dotglob

0 commit comments

Comments
 (0)