generated from UCSB-PSTAT/rstudio-container-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
83 lines (83 loc) · 4.64 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pipeline {
agent none
triggers{
upstream(upstreamProjects: 'UCSB-PSTAT GitHub/base-rstudio/main', threshold: hudson.model.Result.SUCCESS)
}
environment {
IMAGE_NAME = 'pstat215'
}
stages {
stage('Build Test Deploy') {
agent {
label 'jupyter'
}
stages{
stage('Build') {
steps {
script {
if (currentBuild.getBuildCauses('com.cloudbees.jenkins.GitHubPushCause').size() || currentBuild.getBuildCauses('jenkins.branch.BranchIndexingCause').size()) {
scmSkip(deleteBuild: true, skipPattern:'.*\\[ci skip\\].*')
}
}
echo "NODE_NAME = ${env.NODE_NAME}"
sh 'podman build -t localhost/$IMAGE_NAME --pull --force-rm --no-cache .'
}
post {
unsuccessful {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
stage('Test') {
steps {
sh 'podman run -it --rm localhost/$IMAGE_NAME which rstudio'
sh 'podman run -it --rm localhost/$IMAGE_NAME find /usr/share -type f -name lmodern.sty'
sh 'podman run -it --rm localhost/$IMAGE_NAME R -q -e "getRversion() >= \\"4.1.3\\"" | tee /dev/stderr | grep -q "TRUE"'
sh 'podman run -it --rm localhost/$IMAGE_NAME R -e "library(\"INLA\");library(\"fmesher\");library(\"tidyverse\");library(\"tidybayes\");library(\"rstan\");library(\"shinystan\");library(\"loo\");library(\"coda\");library(\"HDInterval\");library(\"testthat\");library(\"MASS\");library(\"palmerpenguins\");library(\"packrat\");library(\"cmdstanr\");library(\"rsconnect\");library(\"StanHeaders\");cmdstan_version()"'
sh 'podman run -it --rm -v${PWD}/test.stan:/tmp/test.stan:z localhost/$IMAGE_NAME R -e "library(\"rstan\");library(\"tidyverse\");library(\"tidybayes\");sm <- stan_model(\\"/tmp/test.stan\\"); res <- sampling(sm, data=list(N=100, y=rnorm(100)))"'
sh 'podman run -d --name=$IMAGE_NAME --rm -p 8888:8888 localhost/$IMAGE_NAME start-notebook.sh --NotebookApp.token="jenkinstest"'
sh 'sleep 10 && curl -v http://localhost:8888/rstudio?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s[1-3][0-9][0-9]\\s+[\\w\\s]+\\s*$"'
sh 'curl -v http://localhost:8888/lab?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s200\\s+[\\w\\s]+\\s*$"'
sh 'curl -v http://localhost:8888/tree?token=jenkinstest 2>&1 | grep -P "HTTP\\S+\\s200\\s+[\\w\\s]+\\s*$"'
}
post {
always {
sh 'podman rm -ifv $IMAGE_NAME'
}
unsuccessful {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
stage('Deploy') {
when { branch 'main' }
environment {
DOCKER_HUB_CREDS = credentials('DockerHubToken')
}
steps {
sh 'skopeo copy containers-storage:localhost/$IMAGE_NAME docker://docker.io/ucsb/$IMAGE_NAME:latest --dest-username $DOCKER_HUB_CREDS_USR --dest-password $DOCKER_HUB_CREDS_PSW'
sh 'skopeo copy containers-storage:localhost/$IMAGE_NAME docker://docker.io/ucsb/$IMAGE_NAME:v$(date "+%Y%m%d") --dest-username $DOCKER_HUB_CREDS_USR --dest-password $DOCKER_HUB_CREDS_PSW'
}
post {
always {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
post {
always {
sh 'podman rmi -i localhost/$IMAGE_NAME || true'
}
}
}
}
post {
success {
slackSend(channel: '#infrastructure-build', username: 'jenkins', color: 'good', message: "Build ${env.JOB_NAME} ${env.BUILD_NUMBER} just finished successfull! (<${env.BUILD_URL}|Details>)")
}
failure {
slackSend(channel: '#infrastructure-build', username: 'jenkins', color: 'danger', message: "Uh Oh! Build ${env.JOB_NAME} ${env.BUILD_NUMBER} had a failure! (<${env.BUILD_URL}|Find out why>).")
}
}
}