Skip to content

Commit

Permalink
image: build dev and release image for all arch
Browse files Browse the repository at this point in the history
Fixed: #1521

Signed-off-by: Qi Feng Huo <[email protected]>
  • Loading branch information
Qi Feng Huo committed Oct 19, 2023
1 parent d8669ae commit c3d838b
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 16 deletions.
51 changes: 39 additions & 12 deletions .github/workflows/caa_build_and_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ jobs:
include:
- type: dev-amd64
arches: "linux/amd64"
- type: dev-s390x
arches: "linux/s390x"
- type: dev-ppc64le
arches: "linux/ppc64le"
#- type: dev-s390x
# arches: "linux/s390x"
#- type: dev-ppc64le
# arches: "linux/ppc64le"
- type: release-amd64
arches: "linux/amd64"
- type: release-s390x
arches: "linux/s390x"
- type: release-ppc64le
arches: "linux/ppc64le"
#- type: release-s390x
# arches: "linux/s390x"
#- type: release-ppc64le
# arches: "linux/ppc64le"
steps:
- name: Checkout the code
uses: actions/checkout@v3
Expand Down Expand Up @@ -106,6 +106,7 @@ jobs:
command: |
echo "Build and push dev image with libvirt"
ARCHES=${{matrix.arches}} RELEASE_BUILD=false DEV_TAGS=${{ inputs.dev_tags}} make image registry=${{ inputs.registry }}
hack/image-manifest.sh -w
- name: Build and push release image
if: ${{ startsWith(matrix.type, 'release-') }}
Expand All @@ -119,17 +120,43 @@ jobs:
command: |
echo "Build and push release image without libvirt"
ARCHES=${{matrix.arches}} RELEASE_BUILD=true RELEASE_TAGS=${{ inputs.release_tags}} make image registry=${{ inputs.registry }}
hack/image-manifest.sh -w
- name: Upload artifacts
if: ${{ startsWith(matrix.type, 'dev-') }}
uses: actions/upload-artifact@v3
with:
name: my-artifact
path: |
cloud-api-adaptor*.tar
commits.txt
- name: 'Generate release commits file'
if: ${{ contains(matrix.type, 'dev-amd64') }}
command: |
TODO
- name: 'Upload release commits file'
if: ${{ contains(matrix.type, 'dev-amd64') }}
uses: actions/upload-artifact@v3
with:
name: release-commits-artifact
path: commits.txt
retention-days: 7

manifest_job:
name: generate images manifest
runs-on: ubuntu-latest
needs: [build_push_job]
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Download release commits file
uses: actions/download-artifact@v3
with:
fetch-depth: 0
ref: "${{ inputs.git_ref }}"
name: my-artifact
path: |
cloud-api-adaptor*.tar
commits.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to quay Container Registry
Expand Down
8 changes: 4 additions & 4 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ name="cloud-api-adaptor"
release_build=${RELEASE_BUILD:-false}
version=${VERSION:-unknown}
commit=${COMMIT:-unknown}
memory_limit=${WITH_MEMORY_LIMIT:-""}

if [[ "$commit" = unknown ]]; then
commit=$(git rev-parse HEAD)
Expand Down Expand Up @@ -49,14 +48,15 @@ function build_caa_payload() {
build_type=release
fi

docker buildx build ${memory_limit} \
--platform "${supported_arches}" \
supported_arches_str=`echo "$supported_arches" | sed -r 's/\//-/g'`

docker buildx build --platform "${supported_arches}" \
--build-arg RELEASE_BUILD="${release_build}" \
--build-arg BUILD_TYPE="${build_type}" \
--build-arg VERSION="${version}" \
--build-arg COMMIT="${commit}" \
-f Dockerfile \
${tag_string} \
-o type=oci,dest=${name}-${build_type}-${supported_arches_str}.tar \
.
popd
}
Expand Down
72 changes: 72 additions & 0 deletions hack/image-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

script_dir=$(dirname "$(readlink -f "$0")")

registry="${registry:-quay.io/confidential-containers}"
name="cloud-api-adaptor"
commit=${COMMIT:-unknown}
commits_file="./commits.txt"
read_commit_hash=""

if [[ "$commit" = unknown ]]; then
commit=$(git rev-parse HEAD)
[[ -n "$(git status --porcelain --untracked-files=no)" ]] && commit+='-dirty'
fi

function generate_commit_hash_file() {
echo "generate_commit_hash_file"
pushd "${script_dir}/.."
echo "commit="$commit > $commits_file
popd
}

function get_commit_from_file() {
echo "get_commit_from_file"
pushd "${script_dir}/.."
if [[ -f $commits_file ]]; then
COMMIT_HASH_STR=$(cat $commits_file | grep commit)
read_commit_hash=${COMMIT_HASH_STR#"commit="}
else
echo "Did not find file: $commits_file"
popd
exit 99
fi
popd
}

function pull_images() {
release_tag_string="${registry}/${name}:${read_commit_hash}"
dev_tag_string="${registry}/${name}:dev-${read_commit_hash}"
}

function build_push_image_manifest() {
get_commit_from_file
if [[ -z $read_commit_hash ]]; then
echo "empty variale: read_commit_hash"
exit 99
fi

pull_images
}

# Get the options
while getopts ":rwm" option; do
case $option in
r) # read commit hash
get_commit_from_file
exit;;
w) # write commit hash
generate_commit_hash_file
exit;;
m) # generate image manifest
build_push_image_manifest
exit;;
\?) # Invalid option
echo "Error: Invalid option"
esac
done

0 comments on commit c3d838b

Please sign in to comment.