Skip to content

Commit

Permalink
[sonic-slave]: build amd64/arm64/armhf sonic-slave dockers
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <lguohan@gmail.com>
  • Loading branch information
lguohan committed Dec 26, 2020
1 parent 0acf2f3 commit e187ae2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
3 changes: 1 addition & 2 deletions jenkins/bldenv/sonic-slave-buster.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pipeline {
agent { node { label 'jenkins-worker-1' } }
agent { node { label 'jenkins-workers-slow' } }

options {
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10'))
}

environment {
DISTRO = 'buster'
ARCH = 'amd64'
SONIC_TEAM_WEBHOOK = credentials('public-jenkins-builder')
}

Expand Down
1 change: 0 additions & 1 deletion jenkins/bldenv/sonic-slave-jessie.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pipeline {

environment {
DISTRO = 'jessie'
ARCH = 'amd64'
SONIC_TEAM_WEBHOOK = credentials('public-jenkins-builder')
}

Expand Down
1 change: 0 additions & 1 deletion jenkins/bldenv/sonic-slave-stretch.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pipeline {

environment {
DISTRO = 'stretch'
ARCH = 'amd64'
SONIC_TEAM_WEBHOOK = credentials('public-jenkins-builder')
}

Expand Down
65 changes: 38 additions & 27 deletions scripts/bldenv/sonic-slave/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,58 @@

cd sonic-buildimage

echo "Building docker containers for $DISTRO and $ARCH"
echo "Building docker containers for $DISTRO"

docker --version

USER=`id -un`
SLAVE_DIR=sonic-slave-$DISTRO

if [ ${ARCH} == 'amd64' ]; then
SLAVE_BASE_IMAGE=${SLAVE_DIR}
else
SLAVE_BASE_IMAGE=${SLAVE_DIR}-${ARCH}
fi
build_and_push_docker()
{
arch=$1

tmpfile=$(mktemp)
echo "Build docker container for $DISTRO and $arch"

echo $ARCH > .arch
if [ x$arch == x"amd64" ]; then
SLAVE_BASE_IMAGE=${SLAVE_DIR}
else
SLAVE_BASE_IMAGE=${SLAVE_DIR}-${arch}
fi

BLDENV=$DISTRO make -f Makefile.work sonic-slave-build | tee $tmpfile
tmpfile=$(mktemp)

SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}')
SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}')
echo $arch > .arch

echo $USER
echo $SLAVE_BASE_TAG
echo $SLAVE_TAG
DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=$DISTRO make -f Makefile.work sonic-slave-build | tee $tmpfile

docker images
SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}')
SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}')

mkdir -p target
echo $USER
echo $SLAVE_BASE_TAG
echo $SLAVE_TAG

docker save $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG | gzip -c > target/$SLAVE_BASE_IMAGE.gz
docker images

REGISTRY_PORT=443
REGISTRY_SERVER=sonicdev-microsoft.azurecr.io
mkdir -p target

docker tag $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG local/$SLAVE_BASE_IMAGE-$USER:latest
docker tag $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE-$USER:latest
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:latest
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG
docker save $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG | gzip -c > target/$SLAVE_BASE_IMAGE.gz

docker login -u $REGISTRY_USERNAME -p "$REGISTRY_PASSWD" $REGISTRY_SERVER:$REGISTRY_PORT
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:latest
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE-$USER:latest
REGISTRY_PORT=443
REGISTRY_SERVER=sonicdev-microsoft.azurecr.io

docker tag $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG local/$SLAVE_BASE_IMAGE-$USER:latest
docker tag $SLAVE_BASE_IMAGE-$USER:$SLAVE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE-$USER:latest
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:latest
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG

docker login -u $REGISTRY_USERNAME -p "$REGISTRY_PASSWD" $REGISTRY_SERVER:$REGISTRY_PORT
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:latest
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG
docker push $REGISTRY_SERVER:$REGISTRY_PORT/$SLAVE_BASE_IMAGE-$USER:latest
}

for arch in amd64 arm64 armhf; do
build_and_push_docker $arch
done

0 comments on commit e187ae2

Please sign in to comment.