Skip to content

Commit b712a84

Browse files
xinredhatRoming22
authored andcommitted
PLNSRVCE-1096:Add CI to docker images
1 parent 8c91aec commit b712a84

File tree

3 files changed

+182
-5
lines changed

3 files changed

+182
-5
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: PipelineRun
4+
metadata:
5+
name: docker-images-test
6+
annotations:
7+
pipelinesascode.tekton.dev/on-event: "[pull_request, push]"
8+
pipelinesascode.tekton.dev/on-target-branch: "[refs/heads/*]"
9+
pipelinesascode.tekton.dev/task: "[git-clone, buildah]"
10+
pipelinesascode.tekton.dev/max-keep-runs: "5"
11+
spec:
12+
timeouts:
13+
pipeline: "0h20m0s"
14+
tasks: "0h5m0s"
15+
params:
16+
- name: repo_url
17+
value: "{{ repo_url }}"
18+
- name: revision
19+
value: "{{ revision }}"
20+
pipelineSpec:
21+
params:
22+
- name: repo_url
23+
- name: revision
24+
workspaces:
25+
- name: source
26+
tasks:
27+
- name: fetch-repository
28+
taskRef:
29+
name: git-clone
30+
workspaces:
31+
- name: output
32+
workspace: source
33+
params:
34+
- name: url
35+
value: $(params.repo_url)
36+
- name: revision
37+
value: $(params.revision)
38+
- name: build-images
39+
runAfter:
40+
- fetch-repository
41+
workspaces:
42+
- name: source
43+
workspace: source
44+
taskSpec:
45+
workspaces:
46+
- name: source
47+
volumes:
48+
- emptyDir: {}
49+
name: varlibcontainers
50+
steps:
51+
- name: test-build-images
52+
image: registry.redhat.io/ubi9/buildah@sha256:32dba51af7790d4f067ff0bc37e46a2f583f093106176a4e48573623d144a9dc
53+
imagePullPolicy: Always
54+
securityContext:
55+
capabilities:
56+
add:
57+
- SETFCAP
58+
volumeMounts:
59+
- mountPath: /var/lib/containers
60+
name: varlibcontainers
61+
workingDir: $(workspaces.source.path)
62+
script: |
63+
developer/hack/build-images-buildah.sh
64+
workspaces:
65+
- name: source
66+
volumeClaimTemplate:
67+
spec:
68+
accessModes:
69+
- ReadWriteOnce
70+
resources:
71+
requests:
72+
storage: 1Gi
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o pipefail
5+
set -x
6+
7+
SCRIPT_DIR="$(
8+
cd "$(dirname "$0")" >/dev/null
9+
pwd
10+
)"
11+
PROJECT_DIR="$(
12+
cd "$SCRIPT_DIR/../.." >/dev/null || exit 1
13+
pwd
14+
)"
15+
export PROJECT_DIR
16+
17+
parse_args() {
18+
mapfile -t DEFAULT_IMAGE_DIRS < <(
19+
find "$PROJECT_DIR" -type f -name Dockerfile -exec dirname {} \; |
20+
sed "s:$PROJECT_DIR/::" |
21+
grep --invert-match --extended-regexp "/developer/exploration/|.devcontainer" |
22+
sort
23+
)
24+
IMAGE_DIRS=()
25+
while [[ $# -gt 0 ]]; do
26+
case $1 in
27+
-i | --image)
28+
shift
29+
if [ ! -d "$1" ]; then
30+
echo "[ERROR] Directory does not exists: $1" >&2
31+
exit 1
32+
else
33+
if [ ! -e "$1/Dockerfile" ]; then
34+
echo "[ERROR] Dockerfile not found in '$1'" >&2
35+
exit 1
36+
fi
37+
fi
38+
IMAGE_DIRS+=("$1")
39+
;;
40+
-t | --tag)
41+
shift
42+
TAG="$1"
43+
;;
44+
-d | --debug)
45+
set -x
46+
DEBUG="--debug"
47+
export DEBUG
48+
;;
49+
-h | --help)
50+
usage
51+
exit 0
52+
;;
53+
*)
54+
echo "Unknown argument: $1"
55+
usage
56+
exit 1
57+
;;
58+
esac
59+
shift
60+
done
61+
}
62+
63+
init() {
64+
TAG=${TAG:-latest}
65+
if [ -z "${IMAGE_DIRS[*]}" ]; then
66+
IMAGE_DIRS=("${DEFAULT_IMAGE_DIRS[@]}")
67+
fi
68+
}
69+
70+
build_image() {
71+
echo "[$image_dir]"
72+
image_name=$(basename "$image_dir")
73+
# for debugging: if image_name != "devenv", then skip
74+
if [ "$image_name" != "devenv" ]; then
75+
return
76+
fi
77+
case "$image_name" in
78+
quay-upload|vulnerability-scan)
79+
context="$image_dir"
80+
;;
81+
*)
82+
context="$PROJECT_DIR"
83+
;;
84+
esac
85+
86+
buildah --storage-driver=vfs bud --format=oci \
87+
--log-level debug \
88+
--tls-verify=true --no-cache \
89+
-f "$image_dir/Dockerfile" --tag "$image_name:$TAG" "$context"
90+
echo
91+
}
92+
93+
main() {
94+
if [ -n "${DEBUG:-}" ]; then
95+
set -x
96+
fi
97+
parse_args "$@"
98+
init
99+
for image_dir in "${IMAGE_DIRS[@]}"; do
100+
build_image
101+
done
102+
}
103+
104+
if [ "${BASH_SOURCE[0]}" == "$0" ]; then
105+
main "$@"
106+
fi

developer/images/devenv/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ RUN set -x \
44
&& mkdir -p /tmp/image-build \
55
&& dnf install -y \
66
# gcc is needed when installing checkov's dependencies
7-
gcc-c++-13.1.1 \
8-
git-2.40.1 \
7+
gcc-c++-13.2.1 \
8+
git-2.41.0 \
99
openssl-3.0.9 \
1010
procps-ng-3.3.17 \
1111
# python3-devl is needed when installing checkov's dependencies
12-
python3-devel-3.11.3 \
12+
python3-devel-3.11.4 \
1313
rsync-3.2.7 \
1414
unzip-6.0 \
1515
which-2.21 \
1616
xz-5.4.1 \
1717
&& dnf clean all \
18-
&& sed -i -e "s:podman:root:" /etc/subuid /etc/subgid \
19-
&& podman system migrate
18+
&& sed -i -e "s:podman:root:" /etc/subuid /etc/subgid
2019
COPY shared /tmp/image-build/shared
2120
RUN /tmp/image-build/shared/hack/install.sh --debug --bin argocd,bitwarden,checkov,hadolint,jq,kind,kubectl,oc,shellcheck,tkn,yamllint,yq \
2221
&& rm -rf /tmp/image-build

0 commit comments

Comments
 (0)