Skip to content

Commit

Permalink
Merge pull request kubean-io#1229 from ErikJiang/update_spray_ci
Browse files Browse the repository at this point in the history
Modify Kubespray CI's rebuild logic for image building
  • Loading branch information
ErikJiang authored May 9, 2024
2 parents 0640787 + ad38aa7 commit deb64fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/call-build-imgs-for-spray.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
SPRAY_SHA=${INPUTS_SPRAY_REF}
fi
echo image_tag_short_sha=$(echo ${SPRAY_SHA} | cut -c 1-7) >> $GITHUB_OUTPUT
echo dockerfile_commit=$(git log -1 --pretty=format:"%H" build/images/kubespray/Dockerfile) >> $GITHUB_OUTPUT
build-kubespray-image:
needs: output-variable
Expand All @@ -51,7 +52,14 @@ jobs:
ghcr_token=$(curl https://ghcr.io/token\?scope\="repository:${{ inputs.REPO }}/kubespray:pull" | jq '.token' | tr -d '"')
skopeo list-tags --registry-token ${ghcr_token} docker://ghcr.io/${{ inputs.REPO }}/kubespray | jq '.Tags' | tr -d '[",]' > tags
if grep -q ${commit_short_sha} tags; then
echo "need_rebuild=false" >>$GITHUB_OUTPUT
late_img_dockerfile_commit=${{ needs.output-variable.outputs.dockerfile_commit }}
prev_img_dockerfile_commit=$(skopeo inspect docker://ghcr.io/${{ inputs.REPO }}/kubespray:${commit_short_sha} | jq '.Labels."io.kubean.dockerfile-commit"')
echo ">>>> late_img_dockerfile_commit: ${late_img_dockerfile_commit}"
echo ">>>> prev_img_dockerfile_commit: ${prev_img_dockerfile_commit}"
if [[ ${late_img_dockerfile_commit} == ${prev_img_dockerfile_commit} ]]; then
echo "The dockerfile of the image with the same tag has not changed, no need to rebuild"
echo "need_rebuild=false" >>$GITHUB_OUTPUT
fi
fi
- uses: actions/checkout@v3
Expand Down Expand Up @@ -83,6 +91,7 @@ jobs:
file: build/images/kubespray/Dockerfile
build-args: |
SPRAY_REF=${{ inputs.SPRAY_REF }}
DOCKERFILE_COMMIT=${{ needs.output-variable.outputs.dockerfile_commit }}
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
provenance: false
Expand Down
5 changes: 5 additions & 0 deletions build/images/kubespray/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ RUN ANSIBLE_CORE_VERSION=$( pip show -V ansible-core | grep Version: | awk '{pri
fi

FROM scratch

ARG DOCKERFILE_COMMIT

LABEL io.kubean.dockerfile-commit=${DOCKERFILE_COMMIT}

COPY --from=spray-build / /

ENV ANSIBLE_CONFIG=/kubespray/ansible.cfg
Expand Down

0 comments on commit deb64fe

Please sign in to comment.