Initial commit
commit
fad319c83b
|
@ -0,0 +1,10 @@
|
|||
# Container Images Shared Library
|
||||
|
||||
This shared library allows jobs to build and publish container images to Gitea
|
||||
very easily:
|
||||
|
||||
```groovy
|
||||
buildContainerImage()
|
||||
```
|
||||
|
||||
That's it!
|
|
@ -0,0 +1,9 @@
|
|||
spec:
|
||||
containers:
|
||||
- name: buildah
|
||||
image: quay.io/containers/buildah:v1
|
||||
command:
|
||||
- sleep
|
||||
- infinity
|
||||
securityContext:
|
||||
privileged: true
|
|
@ -0,0 +1,60 @@
|
|||
// vim: set sw=4 sts=4 ts=4 et :
|
||||
|
||||
def call() {
|
||||
properties([
|
||||
pipelineTriggers([cron('H H H * *')])
|
||||
])
|
||||
|
||||
def registry ='git.pyrocufflink.net'
|
||||
def project = 'containerimages'
|
||||
def name = env.JOB_NAME.
|
||||
split('/')[1].
|
||||
toLowerCase().
|
||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
||||
replaceAll('^[.-]', '_')
|
||||
def tag = env.BRANCH_NAME.
|
||||
toLowerCase().
|
||||
replaceAll('[^a-zA-z0-9._-]', '-').
|
||||
replaceAll('^[.-]', '_')
|
||||
def repo = "${registry}/${project}/${name}"
|
||||
def full_name = "${repo}:${tag}"
|
||||
|
||||
def podTemplateYaml = libraryResource('podTemplate.yaml')
|
||||
|
||||
podTemplate(yaml: podTemplateYaml) {
|
||||
node(POD_LABEL) {
|
||||
checkout scm
|
||||
|
||||
container('buildah') {
|
||||
withEnv([
|
||||
"REGISTRY_AUTH_FILE=${env.WORKSPACE_TMP}/auth.json"
|
||||
]) {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'jenkins-packages',
|
||||
usernameVariable: 'BUILDAH_USERNAME',
|
||||
passwordVariable: 'BUILDAH_PASSWORD',
|
||||
)]) {
|
||||
sh """
|
||||
buildah login \
|
||||
--username \${BUILDAH_USERNAME} \
|
||||
--password \${BUILDAH_PASSWORD} \
|
||||
${registry}
|
||||
"""
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
sh "buildah build -t ${full_name} ."
|
||||
}
|
||||
|
||||
stage('Push') {
|
||||
sh "buildah push ${full_name}"
|
||||
sh "buildah push ${full_name} ${full_name}-${env.BUILD_NUMBER}"
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
sh "buildah push ${full_name} ${repo}:latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue