|
| 1 | +# Starter pipeline |
| 2 | +# Start with a minimal pipeline that you can customize to build and deploy your code. |
| 3 | +# Add steps that build, run tests, deploy, and more: |
| 4 | +# https://aka.ms/yaml |
| 5 | +# Build and push sonic-slave-[buster|jessie|stretch] images for amd64/armhf/arm64 |
| 6 | + |
| 7 | +parameters: |
| 8 | +- name: arch |
| 9 | + type: string |
| 10 | + values: |
| 11 | + - amd64 |
| 12 | + - armhf |
| 13 | + - arm64 |
| 14 | +- name: dist |
| 15 | + type: string |
| 16 | + values: |
| 17 | + - bullseye |
| 18 | + - buster |
| 19 | + - stretch |
| 20 | + - jessie |
| 21 | +- name: registry_url |
| 22 | + type: string |
| 23 | + default: sonicdev-microsoft.azurecr.io |
| 24 | +- name: registry_conn |
| 25 | + type: string |
| 26 | + default: sonicdev |
| 27 | +- name: pool |
| 28 | + type: string |
| 29 | + default: sonicbld |
| 30 | + values: |
| 31 | + - sonicbld |
| 32 | + - sonicbld-arm64 |
| 33 | + - sonicbld-armhf |
| 34 | + |
| 35 | +jobs: |
| 36 | +- job: Build_${{ parameters.dist }}_${{ parameters.arch }} |
| 37 | + timeoutInMinutes: 360 |
| 38 | + pool: ${{ parameters.pool }} |
| 39 | + steps: |
| 40 | + - template: cleanup.yml |
| 41 | + - checkout: self |
| 42 | + clean: true |
| 43 | + submodules: recursive |
| 44 | + - bash: | |
| 45 | + set -ex |
| 46 | +
|
| 47 | + SLAVE_DIR=sonic-slave-${{ parameters.dist }} |
| 48 | + if [ x${{ parameters.pool }} == x"sonicbld" ]; then |
| 49 | + if [ x${{ parameters.arch }} == x"amd64" ]; then |
| 50 | + SLAVE_BASE_IMAGE=${SLAVE_DIR} |
| 51 | + SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR} |
| 52 | + elif [ x${{ parameters.pool }} == x"sonicbld" ]; then |
| 53 | + SLAVE_BASE_IMAGE=${SLAVE_DIR}-march-${{ parameters.arch }} |
| 54 | + SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-march-${{ parameters.arch }} |
| 55 | + fi |
| 56 | + elif [[ x${{ parameters.pool }} == x"sonicbld-armhf" && x${{ parameters.arch }} == x"armhf" ]]; then |
| 57 | + SLAVE_BASE_IMAGE=${SLAVE_DIR} |
| 58 | + SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-armhf |
| 59 | + elif [[ x${{ parameters.pool }} == x"sonicbld-arm64" && x${{ parameters.arch }} == x"arm64" ]]; then |
| 60 | + SLAVE_BASE_IMAGE=${SLAVE_DIR} |
| 61 | + SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-arm64 |
| 62 | + else |
| 63 | + echo "do not support build ${{ parameters.arch }} on ${{ parameters.pool }}" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + if [ x"$(Build.SourceBranchName)" == x"202012" ]; then |
| 68 | + BUILD_OPTIONS = 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker' |
| 69 | + fi |
| 70 | +
|
| 71 | + containers=$(docker container ls | grep "sonic-slave" | awk '{ print $1 }') |
| 72 | + if [ ! -z "$containers" ]; then |
| 73 | + docker container kill $containers || true |
| 74 | + sleep 5 |
| 75 | + fi |
| 76 | + images=$(docker images 'sonic-slave-*' -a -q) |
| 77 | + if [ ! -z "$images" ]; then |
| 78 | + docker rmi -f $images |
| 79 | + fi |
| 80 | +
|
| 81 | + tmpfile=$(mktemp) |
| 82 | +
|
| 83 | + echo ${{ parameters.arch }} > .arch |
| 84 | +
|
| 85 | + DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ parameters.dist }} $(BUILD_OPTIONS) make -f Makefile.work sonic-slave-build | tee $tmpfile |
| 86 | + SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}') |
| 87 | + SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}') |
| 88 | +
|
| 89 | + mkdir -p target |
| 90 | +
|
| 91 | + docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:latest |
| 92 | + docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:$SLAVE_BASE_TAG |
| 93 | + set +x |
| 94 | + echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_IMAGE]$SLAVE_BASE_IMAGE_UPLOAD" |
| 95 | + echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_TAG]$SLAVE_BASE_TAG" |
| 96 | + env: |
| 97 | + REGISTRY_SERVER: ${{ parameters.registry_url }} |
| 98 | + displayName: Build sonic-slave-${{ parameters.dist }}-${{ parameters.arch }} |
| 99 | +
|
| 100 | + - task: Docker@2 |
| 101 | + displayName: Upload image |
| 102 | + inputs: |
| 103 | + containerRegistry: ${{ parameters.registry_conn }} |
| 104 | + repository: $(VARIABLE_SLAVE_BASE_IMAGE) |
| 105 | + command: push |
| 106 | + tags: | |
| 107 | + $(VARIABLE_SLAVE_BASE_TAG) |
| 108 | + latest |
0 commit comments