aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile17
-rw-r--r--Jenkinsfile74
2 files changed, 91 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..354f0d8
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,17 @@
+FROM jenkins/agent:latest
+USER root
+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends ca-certificates curl gnupg && \
+ install -m 0755 -d /etc/apt/keyrings && \
+ curl -fsSL https://download.docker.com/linux/debian/gpg |\
+ gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
+ chmod a+r /etc/apt/keyrings/docker.gpg && \
+ echo \
+ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
+ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
+ tee /etc/apt/sources.list.d/docker.list > /dev/null && \
+ apt-get update && \
+ apt-get install -y --no-install-recommends docker-ce-cli && \
+ rm -rf /var/lib/apt/lists/*
+USER jenkins
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..4426a26
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,74 @@
+String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
+pipeline {
+ agent {
+ docker {
+ image 'quay.io/buildah/stable'
+ args '--privileged=true'
+ }
+ }
+ options { parallelsAlwaysFailFast() }
+ triggers { cron(cron_string) }
+ environment {
+ PROJECT = 'jenkins-agent-docker-cli'
+ IMAGE_NAME = "docker.io/chn2guevara/$PROJECT"
+ }
+ stages {
+ stage('Prepare') {
+ steps {
+ sh 'dnf install git -y'
+ script {
+ env.TAG_NAME = sh(
+ returnStdout: true,
+ script: 'git name-rev --name-only --tags HEAD | sed \'s/^undefined$//\'').trim()
+ }
+ }
+ }
+ stage('Manifest') {
+ steps { sh "buildah manifest create $PROJECT" }
+ }
+ stage('Build') {
+ parallel {
+ stage('arm64/v8') {
+ steps {
+ sh"""
+ buildah build --pull --platform linux/arm64/v8 --network host \
+ --tag $IMAGE_NAME:latest --manifest $PROJECT .
+ """
+ }
+ }
+ stage('amd64') {
+ steps {
+ sh"""
+ buildah build --pull --platform linux/amd64 --network host \
+ --tag $IMAGE_NAME:latest --manifest $PROJECT .
+ """
+ }
+ }
+ }
+ }
+ stage('docker.io login') {
+ when { branch 'master' }
+ steps {
+ withCredentials([string(
+ credentialsId: 'dockerhub-personal',
+ variable: 'CREDENTIALS')
+ ]) {
+ sh '''#!/bin/bash
+ IFS=" " read -r username password <<<"$CREDENTIALS"
+ buildah login \
+ --username "$username" \
+ --password-stdin <<< "$password" docker.io
+ '''
+ }
+ }
+ }
+ stage('Push latest') {
+ when { branch 'master' }
+ steps { sh "buildah manifest push --all $PROJECT docker://$IMAGE_NAME:latest" }
+ }
+ stage('Push tag') {
+ when { allOf { branch 'master'; expression { return env.TAG_NAME == '' ? false : true } } }
+ steps { sh "buildah manifest push --all $PROJECT docker://$IMAGE_NAME:$TAG_NAME" }
+ }
+ }
+}