Skip to content

Commit

Permalink
fix: up tests snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Mar 12, 2024
1 parent 31da749 commit 71cce10
Show file tree
Hide file tree
Showing 10 changed files with 2,403 additions and 533 deletions.
260 changes: 215 additions & 45 deletions packages/kontinuous/tests/__snapshots__/job-builds.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ metadata:
app.kubernetes.io/manifest-managed-by: kontinuous
app.kubernetes.io/manifest-created-by: kontinuous
spec:
backoffLimit: 1
backoffLimit: 0
activeDeadlineSeconds: 3600
ttlSecondsAfterFinished: 1800
template:
Expand Down Expand Up @@ -159,7 +159,7 @@ spec:
memory: \\"0\\"
containers:
- name: job
image: moby/buildkit:v0.11.6-rootless
image: moby/buildkit:v0.13.0-rootless
imagePullPolicy: IfNotPresent
envFrom:
- secretRef:
Expand All @@ -177,19 +177,68 @@ spec:
- >
set -e
if [ \\"\\" != \\"\\" ]; then
export CI_REGISTRY=\\"\\"
fi
buildctl_options_cache=\\"\\"
export IMAGE_NAME=/test-job-builds/app
buildctl_options_mtls=\\"\\"
export IMAGE_PATH=\\"\${CI_REGISTRY}\${IMAGE_NAME}\\"
buildctl_options_cache=\\"\\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-main \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-master \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-dev \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-develop \\\\
--import-cache type=registry,ref=$IMAGE_PATH:feature-branch-1 \\\\
\\"
buildkit_addr=tcp://buildkit-service.buildkit-service.svc:1234
# consistent hashing distribution
## setup consistent hashing variable
export pod_count='1'
export pod_hash_ref=\\"$IMAGE_NAME\\"
## get the pod number
pod_num=$(( 0x$(echo \\"$pod_hash_ref\\" | md5sum | cut -d ' ' -f 1 | head -c 15) ))
[ $pod_num -lt 0 ] && pod_num=$((pod_num * -1))
pod_num=$(( $pod_num % $pod_count ))
## rewrite addr
prefix_addr=\\"\${buildkit_addr%%.*}\\"
protocol=\\"\${prefix_addr%%://*}\\"
# protocol=kube-pod
subdomain=\\"\${prefix_addr#*//}\\"
buildctl_cmd=\\"buildctl \\\\
--addr tcp://buildkit-service.buildkit-service.svc:1234 \\\\
\\"
buildkit_addr=$(echo \\"$buildkit_addr\\" | sed \\"s|$prefix_addr|$protocol://$subdomain-$pod_num.$subdomain|\\")
# buildkit_addr=\\"tcp://test-buildkit-service.test-buildkit-service.svc:1235\\" # enable in debug to emulate service failure
buildctl_cmd=\\"buildctl --addr $buildkit_addr \\"
buildctl_options_mtls=\\"\\"
if [ -f /buildkit-certs/cert.pem ]; then
buildctl_options_mtls=\\"\\\\
Expand All @@ -205,25 +254,60 @@ spec:
echo \\"{\\\\\\"auths\\\\\\":{\\\\\\"$CI_REGISTRY\\\\\\":{\\\\\\"username\\\\\\":\\\\\\"$CI_REGISTRY_USER\\\\\\",\\\\\\"password\\\\\\":\\\\\\"$CI_REGISTRY_PASSWORD\\\\\\"}}}\\" > /home/user/.docker/config.json
export IMAGE_PATH=$CI_REGISTRY/test-job-builds/app
export LATEST_TAG=\\"\\"
if [ \\"false\\" = \\"true\\" ]; then
export LATEST_TAG=\\",$IMAGE_PATH:latest\\"
fi
$buildctl_cmd \\\\
$buildctl_options_mtls \\\\
build \\\\
--frontend dockerfile.v0 \\\\
--local context=/workspace/ \\\\
--local dockerfile=/workspace \\\\
--opt filename=./Dockerfile \\\\
--output type=image,\\\\\\"name=$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53,$IMAGE_PATH:feature-branch-1$LATEST_TAG\\\\\\",push=true \\\\
$buildctl_options_cache \\\\
--opt build-arg:\\"NEXT_PUBLIC_HASURA_URL=https://hasura-test-job-builds-feature-branch-1.dev.fabrique.social.gouv.fr/v1/graphql\\" \\\\
echo \\"$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53\\" >$KONTINUOUS_OUTPUT/IMAGE
runBuildkit() {
tempfile=$(mktemp -u)
pipe=$(mktemp -u)
mkfifo \\"$pipe\\"
tee \\"$tempfile\\" < \\"$pipe\\" &
$buildctl_cmd \\\\
$buildctl_options_mtls \\\\
build \\\\
--frontend dockerfile.v0 \\\\
--local context=/workspace/ \\\\
--local dockerfile=/workspace \\\\
--opt filename=./Dockerfile \\\\
--output type=image,\\\\\\"name=$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53,$IMAGE_PATH:feature-branch-1$LATEST_TAG\\\\\\",push=true \\\\
$buildctl_options_cache \\\\
--opt build-arg:\\"NEXT_PUBLIC_HASURA_URL=https://hasura-test-job-builds-feature-branch-1.dev.fabrique.social.gouv.fr/v1/graphql\\" \\\\
>\\"$pipe\\" 2>&1
return $?
}
set +e
runBuildkit
status=$?
set -e
if [ \\"$status\\" -ne 0 ]; then
echo \\"Command failed. Handling error...\\"
if grep -q -e \\"listing workers for Build: failed to list workers: Unavailable\\" $tempfile; then
echo \\"buildkit optimized service unavailable, fallback to local build\\"
buildctl_cmd=\\"buildctl-daemonless.sh\\"
buildctl_options_mtls=\\"\\"
runBuildkit
else
exit $status
fi
fi
echo \\"build succeeded.\\"
echo \\"$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53\\" >$KONTINUOUS_OUTPUT/IMAGE
resources:
limits:
cpu: \\"2\\"
Expand All @@ -234,6 +318,7 @@ spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: true
seccompProfile:
type: Unconfined
volumeMounts:
Expand Down Expand Up @@ -311,7 +396,7 @@ metadata:
app.kubernetes.io/manifest-managed-by: kontinuous
app.kubernetes.io/manifest-created-by: kontinuous
spec:
backoffLimit: 1
backoffLimit: 0
activeDeadlineSeconds: 3600
ttlSecondsAfterFinished: 1800
template:
Expand Down Expand Up @@ -360,7 +445,7 @@ spec:
memory: \\"0\\"
containers:
- name: job
image: moby/buildkit:v0.11.6-rootless
image: moby/buildkit:v0.13.0-rootless
imagePullPolicy: IfNotPresent
envFrom:
- secretRef:
Expand All @@ -378,19 +463,68 @@ spec:
- >
set -e
if [ \\"\\" != \\"\\" ]; then
export CI_REGISTRY=\\"\\"
fi
buildctl_options_cache=\\"\\"
export IMAGE_NAME=/test-job-builds/hasura
buildctl_options_mtls=\\"\\"
export IMAGE_PATH=\\"\${CI_REGISTRY}\${IMAGE_NAME}\\"
buildctl_options_cache=\\"\\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-main \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-master \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-dev \\\\
--import-cache type=registry,ref=$IMAGE_PATH:cache-develop \\\\
--import-cache type=registry,ref=$IMAGE_PATH:feature-branch-1 \\\\
\\"
buildkit_addr=tcp://buildkit-service.buildkit-service.svc:1234
# consistent hashing distribution
## setup consistent hashing variable
export pod_count='1'
export pod_hash_ref=\\"$IMAGE_NAME\\"
## get the pod number
pod_num=$(( 0x$(echo \\"$pod_hash_ref\\" | md5sum | cut -d ' ' -f 1 | head -c 15) ))
[ $pod_num -lt 0 ] && pod_num=$((pod_num * -1))
pod_num=$(( $pod_num % $pod_count ))
## rewrite addr
prefix_addr=\\"\${buildkit_addr%%.*}\\"
protocol=\\"\${prefix_addr%%://*}\\"
# protocol=kube-pod
subdomain=\\"\${prefix_addr#*//}\\"
buildctl_cmd=\\"buildctl \\\\
--addr tcp://buildkit-service.buildkit-service.svc:1234 \\\\
\\"
buildkit_addr=$(echo \\"$buildkit_addr\\" | sed \\"s|$prefix_addr|$protocol://$subdomain-$pod_num.$subdomain|\\")
# buildkit_addr=\\"tcp://test-buildkit-service.test-buildkit-service.svc:1235\\" # enable in debug to emulate service failure
buildctl_cmd=\\"buildctl --addr $buildkit_addr \\"
buildctl_options_mtls=\\"\\"
if [ -f /buildkit-certs/cert.pem ]; then
buildctl_options_mtls=\\"\\\\
Expand All @@ -406,24 +540,59 @@ spec:
echo \\"{\\\\\\"auths\\\\\\":{\\\\\\"$CI_REGISTRY\\\\\\":{\\\\\\"username\\\\\\":\\\\\\"$CI_REGISTRY_USER\\\\\\",\\\\\\"password\\\\\\":\\\\\\"$CI_REGISTRY_PASSWORD\\\\\\"}}}\\" > /home/user/.docker/config.json
export IMAGE_PATH=$CI_REGISTRY/test-job-builds/hasura
export LATEST_TAG=\\"\\"
if [ \\"false\\" = \\"true\\" ]; then
export LATEST_TAG=\\",$IMAGE_PATH:latest\\"
fi
$buildctl_cmd \\\\
$buildctl_options_mtls \\\\
build \\\\
--frontend dockerfile.v0 \\\\
--local context=/workspace//packages/hasura \\\\
--local dockerfile=/workspace/packages/hasura \\\\
--opt filename=./Dockerfile \\\\
--output type=image,\\\\\\"name=$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53,$IMAGE_PATH:feature-branch-1$LATEST_TAG\\\\\\",push=true \\\\
$buildctl_options_cache \\\\
echo \\"$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53\\" >$KONTINUOUS_OUTPUT/IMAGE
runBuildkit() {
tempfile=$(mktemp -u)
pipe=$(mktemp -u)
mkfifo \\"$pipe\\"
tee \\"$tempfile\\" < \\"$pipe\\" &
$buildctl_cmd \\\\
$buildctl_options_mtls \\\\
build \\\\
--frontend dockerfile.v0 \\\\
--local context=/workspace//packages/hasura \\\\
--local dockerfile=/workspace/packages/hasura \\\\
--opt filename=./Dockerfile \\\\
--output type=image,\\\\\\"name=$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53,$IMAGE_PATH:feature-branch-1$LATEST_TAG\\\\\\",push=true \\\\
$buildctl_options_cache \\\\
>\\"$pipe\\" 2>&1
return $?
}
set +e
runBuildkit
status=$?
set -e
if [ \\"$status\\" -ne 0 ]; then
echo \\"Command failed. Handling error...\\"
if grep -q -e \\"listing workers for Build: failed to list workers: Unavailable\\" $tempfile; then
echo \\"buildkit optimized service unavailable, fallback to local build\\"
buildctl_cmd=\\"buildctl-daemonless.sh\\"
buildctl_options_mtls=\\"\\"
runBuildkit
else
exit $status
fi
fi
echo \\"build succeeded.\\"
echo \\"$IMAGE_PATH:sha-ffac537e6cbbf934b08745a378932722df287a53\\" >$KONTINUOUS_OUTPUT/IMAGE
resources:
limits:
cpu: \\"2\\"
Expand All @@ -434,6 +603,7 @@ spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: true
seccompProfile:
type: Unconfined
volumeMounts:
Expand Down
Loading

0 comments on commit 71cce10

Please sign in to comment.