From 424d3fca0f05a3e9b34f141c3ef68bc28465a965 Mon Sep 17 00:00:00 2001 From: Kinara Shah Date: Wed, 15 Feb 2023 14:55:37 -0800 Subject: [PATCH] add github action and scripts to facilitate build process --- .github/workflows/ci.yml | 30 ++++++++++++++++ .github/workflows/release.yml | 64 +++++++++++++++++++++++++++++++++++ .gitignore | 3 +- Dockerfile.dapper | 19 +++++++++++ scripts/build | 39 +++++++++++++++++++++ scripts/ci | 7 ++++ scripts/entry | 11 ++++++ scripts/version | 20 +++++++++++ 8 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile.dapper create mode 100755 scripts/build create mode 100755 scripts/ci create mode 100755 scripts/entry create mode 100755 scripts/version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000000..d2e6934e9c47b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: Dapper CI on PR +run-name: CI on ${{ github.event_name }} + +on: + pull_request: + push: + branches: + - '*' + +jobs: + validate: + runs-on: ubuntu-latest + container: + image: rancher/dapper:v0.6.0 + permissions: + contents: read + steps: + - name: Fix the not-a-git-repository issue + run: | + apk -U add git + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + - name: Checkout code + uses: actions/checkout@v4 + + - name: build with Dapper + run: dapper ci + + - name: LS the bin + run: ls -lR output/bin \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000000..f43d73d018de3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,64 @@ +name: Release When Tagged +run-name: Release ${{ github.ref_name }} + +on: + push: + tags: '*' + +jobs: + validate: + runs-on: ubuntu-latest + container: + image: rancher/dapper:v0.6.0 + permissions: + contents: read + steps: + - name: Check For Alpha / RC in Release + if: contains(github.ref_name, 'rc') || contains(github.ref_name, 'alpha') + uses: actions/github-script@v7 + with: + script: | + core.setFailed('No RCs or Alphas are released in this repo. Skipping release...') + + - name: Fix the not-a-git-repository issue + run: | + apk -U add git + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: build with Dapper + run: dapper ci + + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + with: + name: kubernetes-build + path: output/bin + if-no-files-found: error + overwrite: true + + create-release: + runs-on: ubuntu-latest + needs: + - validate + permissions: + contents: write # needed for creating the GH release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download assets + uses: actions/download-artifact@v4 + + - name: Create GH Release + run: | + gh release create ${{ github.ref_name }} --verify-tag --generate-notes kubernetes-build/* diff --git a/.gitignore b/.gitignore index c1915d7a1544f..0df35dce576a9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,8 @@ __* # This is where the result of the go build goes /output*/ /_output*/ -/_output +/_output/ +Dockerfile.dapper?* # Emacs save files *~ diff --git a/Dockerfile.dapper b/Dockerfile.dapper new file mode 100644 index 0000000000000..d1ab61c15fe89 --- /dev/null +++ b/Dockerfile.dapper @@ -0,0 +1,19 @@ +FROM registry.suse.com/bci/golang:1.22 + +ARG DAPPER_HOST_ARCH +ARG DEBIAN_FRONTEND=noninteractive +ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} + +RUN zypper install -y -f docker rsync awk +COPY --from=docker/buildx-bin:0.10.2 /buildx /usr/libexec/docker/cli-plugins/docker-buildx + +ENV DAPPER_SOURCE /go/src/github.com/rancher/kubernetes/ +ENV DAPPER_RUN_ARGS --privileged -v /var/lib/docker +ENV DAPPER_OUTPUT ./output/bin +ENV DAPPER_DOCKER_SOCKET true +ENV DAPPER_ENV TAG REPO GOOS CROSS DRONE_TAG +ENV HOME ${DAPPER_SOURCE} +WORKDIR ${DAPPER_SOURCE} +ENTRYPOINT ["./scripts/entry"] +CMD ["ci"] + diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000000000..45187aed4214f --- /dev/null +++ b/scripts/build @@ -0,0 +1,39 @@ +#!/bin/bash +set -e + +source $(dirname $0)/version + +cd $(dirname $0)/.. + +OS_ARCH_LINUX="arm64 amd64" +KUBE_BUILD_PLATFORMS="linux/arm64 linux/amd64" +K8S_BASE="k8s.io/component-base" + +mkdir -p output/bin +if [ -n "$VERSION" ]; then + TAG=$VERSION +fi + +buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ') +GOLDFLAGS=" + -X ${K8S_BASE}/version.gitVersion=${TAG} + -X ${K8S_BASE}/version.gitCommit=${COMMIT} + -X ${K8S_BASE}/version.gitTreeState=${GIT_TREE_STATE} + -X ${K8S_BASE}/version.buildDate=${buildDate} +" + +build/run.sh make kubelet KUBE_BUILD_PLATFORMS="${KUBE_BUILD_PLATFORMS}" + +for ARCH in ${OS_ARCH_LINUX}; do + mv _output/dockerized/bin/linux/$ARCH/kubelet . + if [ $ARCH = "amd64" ]; then + ./kubelet --version + fi + tar -cvzf output/bin/kubelet-$TAG-$ARCH.tar.gz kubelet && rm kubelet +done + +sha256sum output/bin/* > output/bin/sha256sum.txt + +rm -rf _output/ + +echo Built ${TAG} diff --git a/scripts/ci b/scripts/ci new file mode 100755 index 0000000000000..9c9c87e9b3f43 --- /dev/null +++ b/scripts/ci @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +cd $(dirname $0) + +./build + diff --git a/scripts/entry b/scripts/entry new file mode 100755 index 0000000000000..78fb567905b77 --- /dev/null +++ b/scripts/entry @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +mkdir -p bin dist +if [ -e ./scripts/$1 ]; then + ./scripts/"$@" +else + exec "$@" +fi + +chown -R $DAPPER_UID:$DAPPER_GID . diff --git a/scripts/version b/scripts/version new file mode 100755 index 0000000000000..5ab2b2305aa8c --- /dev/null +++ b/scripts/version @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + DIRTY="-dirty" +fi + +COMMIT=$(git rev-parse HEAD) +GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} + +if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then + VERSION=$GIT_TAG + GIT_TREE_STATE=clean +else + VERSION="${COMMIT}${DIRTY}" + GIT_TREE_STATE=dirty +fi + +if [ -z "$ARCH" ]; then + ARCH=amd64 +fi