Skip to content

Commit

Permalink
feat(apps/prod/tekton/configs): debug build for mac targets (#783)
Browse files Browse the repository at this point in the history
Current it in debug stage.

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo committed Nov 17, 2023
1 parent 3044909 commit 77f153f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
9 changes: 7 additions & 2 deletions apps/prod/tekton/configs/pipelines/push-build-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ spec:
- name: git-credentials
description: secret contains ssh private key in `id_rsa` key.
optional: true
- name: mac-ssh-credentials
description: secret contains ssh private key in `id_rsa` key for login mac
optional: true
tasks:
- name: checkout
taskRef:
Expand Down Expand Up @@ -88,7 +91,7 @@ spec:
# value: [release, debug]
params:
- name: os
value: linux
value: darwin
- name: arch
value: amd64
- name: profile
Expand All @@ -113,6 +116,8 @@ spec:
workspace: source
- name: dockerconfig
workspace: dockerconfig
- name: ssh-directory
workspace: mac-ssh-credentials
- name: build-images
taskRef:
# TODO: can we skaffold to make it simpler?
Expand All @@ -122,7 +127,7 @@ spec:
# TODO: currently matrix feature is not support in v0.32.x, we need upgrade the K8S cluster and then upgrade Tekton.
params:
- name: os
value: linux
value: darwin
- name: arch
value: amd64
- name: profile
Expand Down
54 changes: 53 additions & 1 deletion apps/prod/tekton/configs/tasks/pingcap-build-binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ spec:
description: Includes a docker `config.json`
mountPath: /root/.docker
optional: true
- name: ssh-directory
optional: true
description: ssh credential for remote building on mac.
results:
- description: The package artifacts
name: package-artifacts
Expand Down Expand Up @@ -62,9 +65,58 @@ spec:
cat /workspace/build-package-artifacts.sh
- name: build
image: "$(params.builder-image)"
env:
- name: WORKSPACE_SSH_DIRECTORY_BOUND
value: $(workspaces.ssh-directory.bound)
workingDir: $(workspaces.source.path)
# TODO: get the user and host by better way.
script: |
/workspace/build-package-artifacts.sh -b -a -w "$(params.release-dir)"
if ["$(params.os)" == "darwin"]; then
##### Build mac targets in tekton task (k8s pod) ####
# 0. got the go version(x.y) from the current container with `go version`.
go_bin_path="/usr/local/$(go version | cut -d ' ' -f 3 | cut -d '.' -f -2)/bin
# 1. select a mac idle mac machine, if all busy, random one with correct arch.
username=$(cat ~/.ssh/username)
host=$(cat ~/.ssh/host)
workspace_base_dir="/Users/pingcap/workspace"
# 1.1 Set ssh credentials
if [ "${WORKSPACE_SSH_DIRECTORY_BOUND}" = "true" ] ; then
cp -R "${WORKSPACE_SSH_DIRECTORY_PATH}" ~/.ssh
chmod 700 ~/.ssh
chmod -R 400 ~/.ssh/*
fi
# 2. login to the mac with ssh and then execute the shell.
# 2.1 create a randon workspace dir in the remote host:
remote_workspace_dir="${workspace_base_dir}/$(uuid)"
ssh ${username}@${host} "mkdir -p '$remote_workspace_dir'"
# 2.2 copy the build shell to the mac host by ssh.
scp /workspace/build-package-artifacts.sh ${username}@${host}:"$remote_workspace_dir/"
# 2.3 copy source codes from workspace `source` to the mac host by ssh.
scp -r $(workspaces.source.path) ${username}@${host}:"$remote_workspace_dir/"
remote_workspace_source_path="$remote_workspace_dir/$(basename $(workspaces.source.path))"
# 2.4 run the shell on the mac host by ssh.
ssh <root>@<host> -t "bash -lc '
PATH=${go_bin_path}:\$PATH;
cd remote_workspace_source_path;
${remote_workspace_dir}/build-package-artifacts.sh -b -a -w $(params.release-dir)
'"
# 2.5 copy the artifacts from the mac hosts to the workspace `source`.
scp -r ${username}@${host}:"$remote_workspace_dir/$(params.release-dir)" ./
# 3. clean the workspace dir(it will be a random name) on the ssh mac host.
ssh ${username}@${host} "rm -rf '$remote_workspace_dir'"
else
# Linux
/workspace/build-package-artifacts.sh -b -a -w "$(params.release-dir)"
fi
- name: publish
image: ghcr.io/pingcap-qe/ci/release-utils:v20231107-4086b32
workingDir: $(workspaces.source.path)
Expand Down
10 changes: 10 additions & 0 deletions apps/prod/tekton/configs/tasks/pingcap-build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ spec:
- name: generate
image: ghcr.io/pingcap-qe/ci/release-utils:v20231107-4086b32
script: |
if [ "$(params.os)" != "linux" ]; then
echo "target os is not linux, skip it."
exit 0
fi
git clone --depth=1 --branch=main https://github.com/PingCAP-QE/artifacts.git /workspace/artifacts
/workspace/artifacts/packages/scripts/gen-package-images-with-config.sh \
Expand All @@ -66,4 +71,9 @@ spec:
- name: KANIKO_EXECUTOR
value: /kaniko/executor
script: |
if [ "$(params.os)" != "linux" ]; then
echo "target os is not linux, skip it."
exit 0
fi
/workspace/build-package-images.sh "$(params.release-dir)" "$(params.tag)" ${KANIKO_EXECUTOR} "$(params.build)"
10 changes: 5 additions & 5 deletions apps/prod/tekton/configs/triggers/templates/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ resources:
- pingcap-qe/artifacts/push-pingcap-qe-artifacts.yaml
- pingcap-qe/artifacts/tag-create-pingcap-qe-artifacts.yaml
- pingcap/branch-create-product-components-hotfix.yaml
- pingcap/tidb/push.yaml
- pingcap/tiflash/push.yaml
- pingcap/tiflow/push.yaml
# - pingcap/tidb/push.yaml
# - pingcap/tiflash/push.yaml
# - pingcap/tiflow/push.yaml
- tikv/pd/push.yaml
- tikv/pd/tag-build.yaml
- tikv/tikv/push.yaml
# - tikv/pd/tag-build.yaml
# - tikv/tikv/push.yaml

3 changes: 3 additions & 0 deletions apps/prod/tekton/configs/triggers/templates/tikv/pd/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:
- name: dockerconfig
secret:
secretName: hub-pingcap-net-ee
- name: mac-ssh-credentials
secret:
secretName: mac-ssh-credentials
- name: source
volumeClaimTemplate:
spec:
Expand Down

0 comments on commit 77f153f

Please sign in to comment.