Skip to content

Commit

Permalink
Merge pull request #88 from ErikJiang/update_spray_img_ci
Browse files Browse the repository at this point in the history
Integrate image build ci
  • Loading branch information
ErikJiang authored Aug 25, 2022
2 parents e4d6fc3 + 902e23e commit 485ac87
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 97 deletions.
26 changes: 14 additions & 12 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<!--
Thanks for sending a pull request! Here are some tips for you:
# todo
* make sure your commit is signed off
-->

**What type of PR is this?**
> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:
>
> /kind api-change
> /kind bug
> /kind cleanup
> /kind design
> /kind documentation
> /kind failing-test
> /kind feature
> /kind flake
<!--
Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:
/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
-->

**What this PR does / why we need it**:

Expand All @@ -29,4 +32,3 @@ Fixes #

**Special notes for your reviewer**:

**make sure your commit is signed off**
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
env:
KUKEAN_OPERATOR_IMAGE_NAME: kubean-operator
KUBESPRAY_IMAGE_NAME: kubespray
SPRAY_JOB_IMAGE_NAME: spray-job
KUBESPRAY_TAG: master
- 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'

jobs:
get-spray-ref:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.get_ref.outputs.sha }}
steps:
- name: Get kubespray latest commit sha
id: get_ref
run: |
COMMIT_SHA=`git ls-remote https://github.com/kubernetes-sigs/kubespray.git HEAD | awk '{ print $1}'`
echo ::set-output name=sha::${COMMIT_SHA}
call-offline-build:
uses: ./.github/workflows/call-offline-build.yaml
needs: get-spray-ref
with:
spray_ref: ${{ needs.get-spray-ref.outputs.sha }}

call-os-pkgs-build:
uses: ./.github/workflows/call-os-pkgs-build.yaml

call-images-build:
uses: ./.github/workflows/call-images-build.yaml
secrets: inherit
needs: get-spray-ref
with:
spray_ref: ${{ needs.get-spray-ref.outputs.sha }}

call-os-pkgs-build:
uses: ./.github/workflows/call-os-pkgs-build.yaml


charts:
needs: [call-images-build,call-offline-build]
Expand Down
98 changes: 61 additions & 37 deletions .github/workflows/call-images-build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: build-image

on: workflow_call
on:
workflow_call:
inputs:
spray_ref:
required: true
type: string

env:
KUKEAN_OPERATOR_IMAGE_NAME: kubean-operator
SPRAY_JOB_IMAGE_NAME: spray-job
KUBESPRAY_TAG: master
ONLINE_REGISTER: ghcr.io
BUILD_PLATFORM: linux/amd64,linux/arm64

jobs:
build-push:
Expand All @@ -15,44 +19,64 @@ jobs:
contents: read

steps:
- name: Set env
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
echo "SPRAY_SHA_SHORT=$(echo ${{ inputs.spray_ref }} | cut -c 1-7)" >> ${GITHUB_ENV}
- name: Echo env
run: |
echo "REPO: ${{ env.REPO }}"
echo "SPRAY_SHA_SHORT: ${{ env.SPRAY_SHA_SHORT }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/checkout@v3
with:
repository: kubernetes-sigs/kubespray
ref: ${{ inputs.spray_ref }}
path: ./kubespray

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: kubean-operator Build image
run: docker build . --file ./build/images/$KUKEAN_OPERATOR_IMAGE_NAME/Dockerfile --tag $KUKEAN_OPERATOR_IMAGE_NAME
- name: kubespray base image build
uses: docker/[email protected]
with:
context: ./
file: ./build/images/kubespray/Dockerfile
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
platforms: ${{ env.BUILD_PLATFORM }}
tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/kubespray:${{ env.SPRAY_SHA_SHORT }}

- name: kubean-operator Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$KUKEAN_OPERATOR_IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(git describe --tags --abbrev=8 --dirty)
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $KUKEAN_OPERATOR_IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $KUKEAN_OPERATOR_IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
- name: spray-job Build image
run: docker build . --file ./build/images/$SPRAY_JOB_IMAGE_NAME/Dockerfile --tag $SPRAY_JOB_IMAGE_NAME --build-arg spray_tag=$KUBESPRAY_TAG

- name: spray-job Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$SPRAY_JOB_IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(git describe --tags --abbrev=8 --dirty)
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $SPRAY_JOB_IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $SPRAY_JOB_IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
- name: spray-job image build
uses: docker/[email protected]
with:
context: ./
file: ./build/images/spray-job/Dockerfile
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
platforms: ${{ env.BUILD_PLATFORM }}
tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/spray-job:${{ github.ref_name }}
build-args: |
SPRAY_TAG=${{ env.SPRAY_SHA_SHORT }}
REPO=${{ env.REPO }}
- name: kubean-operator image build
uses: docker/[email protected]
with:
context: ./
file: ./build/images/kubean-operator/Dockerfile
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
platforms: ${{ env.BUILD_PLATFORM }}
tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/kubean-operator:${{ github.ref_name }}
19 changes: 15 additions & 4 deletions .github/workflows/call-offline-build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
name: Offline Build CI

on: workflow_call
on:
workflow_call:
inputs:
spray_ref:
required: true
type: string

jobs:
offline-build:
runs-on: ubuntu-latest
steps:
- name: Set env
run: echo "SPRAY_SHA_SHORT=$(echo ${{ inputs.spray_ref }} | cut -c 1-7)" >> ${GITHUB_ENV}

- name: Echo env
run: echo ${SPRAY_SHA_SHORT}

- name: git clone kubean repo
uses: actions/checkout@v3
with:
Expand All @@ -15,16 +26,16 @@ jobs:
uses: actions/checkout@v3
with:
repository: kubernetes-sigs/kubespray
ref: ${{ env.KUBESPRAY_TAG }}
ref: ${{ inputs.spray_ref }}
path: ./kubespray

- name: install yq tool
uses: mikefarah/[email protected]

- name: generate ComponentsVersion & OfflineVersion files
run: |
KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${{ env.KUBESPRAY_TAG }} bash artifacts/manage_version_cr.sh create_componentsversion
KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${{ env.KUBESPRAY_TAG }} bash artifacts/manage_version_cr.sh create_offlineversion
KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${SPRAY_SHA_SHORT} bash artifacts/manage_version_cr.sh create_componentsversion
KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${SPRAY_SHA_SHORT} bash artifacts/manage_version_cr.sh create_offlineversion
- name: preparing the python environment
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/call-os-pkgs-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2.0.0

- name: Build OS packages to local
uses: docker/build-push-action@v3
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/spray-image-build.yaml

This file was deleted.

6 changes: 4 additions & 2 deletions build/images/spray-job/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG spray_tag=master
FROM ghcr.io/kubean-io/kubean/kubespray:$spray_tag
ARG SPRAY_TAG=master
ARG REPO=kubean-io/kubean

FROM ghcr.io/${REPO}/kubespray:${SPRAY_TAG}

WORKDIR /kubespray

Expand Down

0 comments on commit 485ac87

Please sign in to comment.