diff --git a/Jenkinsfile_k8s b/Jenkinsfile_k8s index abfedf5df..04e842762 100644 --- a/Jenkinsfile_k8s +++ b/Jenkinsfile_k8s @@ -145,6 +145,7 @@ pipeline { } axis { name 'agent_type' + // make sure to port any addition to the list of agent types to the Build Docker Manifest stage if it's docker related values 'ubuntu-20.04', 'windows-2019', 'windows-2022' } axis { @@ -242,12 +243,16 @@ pipeline { // Execute build only for this matrix cell's setup retry(count: 2, conditions: [kubernetesAgent(handleNonKubernetes: true), nonresumable()]) { sh 'packer build -timestamp-ui -force -only="${PKR_VAR_image_type}.${PKR_VAR_agent_os_type}" ./' + // adding manually a cpu architecture tag to the docker image + if (pkr_var_image_type == 'docker') { + sh 'docker tag "jenkinsciinfra/jenkins-agent-${PKR_VAR_agent_os_type}-${PKR_VAR_agent_os_version}:latest" "jenkinsciinfra/jenkins-agent-${PKR_VAR_agent_os_type}-${PKR_VAR_agent_os_version}:${PKR_VAR_architecture}"' + } } // if docker and building a tag, push to dockerhub from inside the node // else we would loose the docker image if (pkr_var_image_type == 'docker' && pkr_var_tag_name != null) { stage('Publish all tags for Docker image') { - echo "Pushing jenkinsciinfra/jenkins-agent-${pkr_var_agent_os_type}:${pkr_var_tag_name} & jenkinsciinfra/jenkins-agent-${pkr_var_agent_os_type}:latest" + echo "Pushing jenkinsciinfra/jenkins-agent-${pkr_var_agent_os_type}:${pkr_var_tag_name} & jenkinsciinfra/jenkins-agent-${pkr_var_agent_os_type}:latest for ${pkr_var_architecture}" infra.withDockerPushCredentials { sh 'docker push --all-tags jenkinsciinfra/jenkins-agent-${agent_type}' } @@ -260,5 +265,34 @@ pipeline { } } } + stage('Build Docker Manifest') { + when { + expression { + return env.TAG_NAME != null + } + } + environment { + // Static variable definition as this stage is outside the matrix scope + // Improvement: pass dynamically the list of images from the matrix (e.g. use full scripted pipeline) to support other Docker agent types (such as windows-2019 or windows-2022) + agent_type = 'ubuntu-20.04' + } + steps { + script { + infra.withDockerPushCredentials { + sh 'docker manifest create \ + jenkinsciinfra/jenkins-agent-${agent_type}:latest \ + --amend jenkinsciinfra/jenkins-agent-${agent_type}:arm64 \ + --amend jenkinsciinfra/jenkins-agent-${agent_type}:amd64' + sh 'docker manifest push jenkinsciinfra/jenkins-agent-"${agent_type}":latest' + + sh 'docker manifest create \ + jenkinsciinfra/jenkins-agent-${agent_type}:${TAG_NAME} \ + --amend jenkinsciinfra/jenkins-agent-${agent_type}:arm64 \ + --amend jenkinsciinfra/jenkins-agent-${agent_type}:amd64' + sh 'docker manifest push jenkinsciinfra/jenkins-agent-"${agent_type}":"${TAG_NAME}"' + } + } + } + } } } diff --git a/provisioning/ubuntu-provision.sh b/provisioning/ubuntu-provision.sh index b96a8c509..a5bb03b1b 100755 --- a/provisioning/ubuntu-provision.sh +++ b/provisioning/ubuntu-provision.sh @@ -737,14 +737,15 @@ function main() { install_ssh_requirements # Ensure that OpenSSH CLI and SSH agent are installed setuser # Define user Jenkins before all (to allow installing stuff in its home dir) install_asdf # Before all the others but after the jenkins home is created + install_goss # needed by the pipeline + install_docker # needed by the pipeline + install_jdk # needed by the pipeline install_chromium - install_docker install_datadog install_JA_requirements install_qemu install_python install_git_gitlfs - install_jdk install_docker_compose install_maven install_hadolint @@ -762,7 +763,6 @@ function main() { install_terraform install_kubectl install_tfsec - install_goss install_nodejs install_playwright_dependencies cleanup