Merge pull request #70 from rollandf/nvstaging #194
Workflow file for this run
This file contains hidden or 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-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: . | |
- if: github.ref_type == 'branch' | |
name: Determine docker tag (when git branch) | |
run: | | |
echo DOCKER_TAG=$(git rev-parse --short HEAD) | tee -a $GITHUB_ENV # short git commit hash | |
- if: github.ref_type == 'tag' | |
name: Determine docker tag (when git tag) | |
run: | | |
echo DOCKER_TAG=${{ github.ref_name }} | tee -a $GITHUB_ENV | |
- name: Store docker tag for following jobs | |
id: store-docker-tag | |
run: | | |
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_OUTPUT | |
outputs: | |
docker_tag: ${{ steps.store-docker-tag.outputs.DOCKER_TAG }} | |
build-and-push-images: | |
needs: determine-docker-tag | |
runs-on: ubuntu-latest | |
env: | |
BUILD_PLATFORMS: linux/amd64,linux/arm64,linux/ppc64le | |
DOCKER_REGISTRY: nvcr.io/nvstaging/mellanox | |
DOCKER_TAG: ${{ needs.determine-docker-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-tag | |
- build-and-push-images | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_TAG: ${{ needs.determine-docker-tag.outputs.docker_tag }} | |
DOCKER_REGISTRY: nvcr.io/nvstaging/mellanox | |
GH_TOKEN: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
path: sriov-network-operator-fork | |
- name: Determine base branch | |
run: | | |
if [[ "${{ github.ref_type }}" == "branch" || "${{ github.ref_name }}" == *"beta"* ]]; then # branch commits and beta tags update values on network-operator's *master* branch | |
echo BASE_BRANCH=master | tee -a $GITHUB_ENV | |
else # GA and `-rc.` tags update values on network-operator's respective *release* branches | |
release_branch=$(echo ${{ github.ref_name }} | sed -E 's/^network-operator-([0-9]+\.[0-9]+).+/v\1.x/') # example: transforms "network-operator-25.1.0-beta.2" to "v25.1.x" | |
echo BASE_BRANCH=$release_branch | tee -a $GITHUB_ENV | |
fi | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} | |
repository: ${{ github.repository_owner }}/network-operator | |
path: network-operator-fork | |
ref: ${{ env.BASE_BRANCH }} | |
- name: Create PR to update image tags in network-operator values | |
run: | | |
cd network-operator-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 '.SriovNetworkOperator.repository = "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i '.SriovNetworkOperator.version = "${{ env.DOCKER_TAG }}"' hack/release.yaml | |
yq -i '.SriovConfigDaemon.repository = "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i '.SriovConfigDaemon.version = "${{ env.DOCKER_TAG }}"' hack/release.yaml | |
yq -i '.SriovNetworkOperatorWebhook.repository = "${{ env.DOCKER_REGISTRY }}"' hack/release.yaml | |
yq -i '.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." | |
--body "Created by the [*${{ github.job }}* job](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})." | |
fi |