Merge pull request #53 from e0ne/ubuntu-kargs #154
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Fork Docker CI | |
on: | |
push: | |
branches: | |
- network-operator-* | |
tags: | |
- network-operator-* | |
jobs: | |
determine_docker_registry_and_tag: | |
runs-on: ubuntu-latest | |
env: | |
REGISTRY_INTERNAL: nvcr.io/nvstaging/mellanox | |
REGISTRY_PUBLIC: nvcr.io/nvidia/mellanox | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: . | |
- if: github.ref_type == 'branch' | |
name: Determine docker registry and tag (when git branch) | |
run: | | |
echo DOCKER_REGISTRY=$REGISTRY_INTERNAL >> $GITHUB_ENV | |
echo DOCKER_TAG=$(git rev-parse --short HEAD) >> $GITHUB_ENV # short git commit hash | |
- if: github.ref_type == 'tag' | |
name: Determine docker registry and tag (when git tag) | |
run: | | |
echo DOCKER_REGISTRY=$(echo ${{ github.ref_name }} | sed 's/network-operator-//' | grep -q '-' && echo $REGISTRY_INTERNAL || echo $REGISTRY_PUBLIC) >> $GITHUB_ENV # use public registry only when release tag has no '-beta*' or '-rc*' suffix | |
echo DOCKER_TAG=${{ github.ref_name }} >> $GITHUB_ENV | |
- name: Store docker registry and tag for following jobs | |
id: store-docker-registry-and-tag | |
run: | | |
echo DOCKER_REGISTRY=$DOCKER_REGISTRY >> $GITHUB_OUTPUT | |
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_OUTPUT | |
outputs: | |
docker_registry: ${{ steps.store-docker-registry-and-tag.outputs.DOCKER_REGISTRY }} | |
docker_tag: ${{ steps.store-docker-registry-and-tag.outputs.DOCKER_TAG }} | |
build_and_push_images: | |
needs: determine_docker_registry_and_tag | |
runs-on: ubuntu-latest | |
env: | |
BUILD_PLATFORMS: linux/amd64,linux/arm64,linux/ppc64le | |
DOCKER_REGISTRY: ${{ needs.determine_docker_registry_and_tag.outputs.docker_registry }} | |
DOCKER_TAG: ${{ needs.determine_docker_registry_and_tag.outputs.docker_tag }} | |
strategy: | |
matrix: | |
include: | |
- component: operator | |
image_name: sriov-network-operator | |
dockerfile: Dockerfile | |
- component: config-daemon | |
image_name: sriov-network-operator-config-daemon | |
dockerfile: Dockerfile.sriov-network-config-daemon | |
- component: webhook | |
image_name: sriov-network-operator-webhook | |
dockerfile: Dockerfile.webhook | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ secrets.NVCR_USERNAME }} | |
password: ${{ secrets.NVCR_TOKEN }} | |
- uses: docker/build-push-action@v4 | |
with: | |
platforms: ${{ env.BUILD_PLATFORMS }} | |
context: . | |
file: ${{ matrix.dockerfile }} | |
tags: ${{ env.DOCKER_REGISTRY }}/${{ matrix.image_name }}:${{ env.DOCKER_TAG }} | |
push: true | |
update_network_operator_values: | |
needs: | |
- determine_docker_registry_and_tag | |
- build_and_push_images | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_REGISTRY: ${{ needs.determine_docker_registry_and_tag.outputs.docker_registry }} | |
DOCKER_TAG: ${{ needs.determine_docker_registry_and_tag.outputs.docker_tag }} | |
GH_TOKEN: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
path: sriov-network-operator-fork | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} | |
repository: ${{ github.repository_owner }}/network-operator | |
path: network-opertor-fork | |
- name: Determine base branch | |
run: | | |
echo "BASE_BRANCH=${{ contains(env.DOCKER_TAG, 'beta') && 'master' || env.DOCKER_TAG }}" >> $GITHUB_ENV | |
- name: Create PR to update image tags in network-operator values | |
run: | | |
cd network-opertor-fork | |
git config user.name nvidia-ci-cd | |
git config user.email [email protected] | |
git checkout -b feature/update-sriov-tags-to-$DOCKER_TAG | |
rm -rf deployment/network-operator/charts/sriov-network-operator/* | |
cp -r ../sriov-network-operator-fork/deployment/sriov-network-operator-chart/* deployment/network-operator/charts/sriov-network-operator/ | |
# we *don't* copy `Chart.yaml` with the files below, because network-operator's `Chart.yaml` refers to the SR-IOV chart name with a hardcoded version. | |
git checkout -- deployment/network-operator/charts/sriov-network-operator/Chart.yaml | |
yq -i e '.SriovNetworkOperator.repository |= "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i e '.SriovNetworkOperator.version |= "${{ env.DOCKER_TAG }}"' hack/release.yaml | |
yq -i e '.SriovConfigDaemon.repository |= "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i e '.SriovConfigDaemon.version |= "${{ env.DOCKER_TAG }}"' hack/release.yaml | |
yq -i e '.SriovNetworkOperatorWebhook.repository |= "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i e '.SriovNetworkOperatorWebhook.version |= "${{ env.DOCKER_TAG }}"' hack/release.yaml | |
make release-build | |
if ! git diff --color --unified=0 --exit-code; then | |
git add deployment/network-operator/charts/sriov-network-operator | |
git add -u | |
git commit -sam "cicd: update SR-IOV images tags to $DOCKER_TAG in chart values" | |
git push -f -u origin feature/update-sriov-tags-to-$DOCKER_TAG | |
gh pr create \ | |
--repo ${{ github.repository_owner }}/network-operator \ | |
--base $BASE_BRANCH \ | |
--head $(git branch --show-current) \ | |
--title "cicd: update SR-IOV images tags to $DOCKER_TAG in chart values" \ | |
--body "Created by the *${{ github.job }}* job." | |
fi |