summaryrefslogtreecommitdiffci
path: root/Jenkinsfile
blob: f5652101e9e12497be342215b47050b8ad2e70a9 (plain)
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
pipeline {
    agent none

    stages {
        stage('Compile Tailwind CSS') {
            agent {
                docker {
                    image 'node:26.3.1-alpine3.24'
                    args  '-v /tmp:/tmp -v /.npm:/.npm'
                }
            }
            steps {
                checkout scm
                sh '''
                    npm install tailwindcss @tailwindcss/cli @tailwindcss/forms
                    npx tailwindcss -i static/input.css -o static/output.css --watch
                '''
                stash name: 'tailwindcss-output', includes: 'static/output.css'
            }
        }
        
        stage('Build') {
            agent {
                kubernetes {
                    defaultContainer 'kaniko'
                    yaml """
apiVersion: v1
kind: Pod
metadata:
  name: kaniko-sayauz-web
  namespace: jenkins
spec:
  containers:
    - name: kaniko
      image: gcr.io/kaniko-project/executor:v1.24.0-debug
      imagePullPolicy: Always
      command: [ /busybox/cat ]
      tty: true
"""
                }
            }
            environment {
                IMAGE_PUSH_DESTINATION="registry.sayag.it/sayauz/web"
            }
            steps {
                checkout scm
                unstash 'tailwindcss-output'
                container(name: 'kaniko', shell: '/busybox/sh') {
                    withCredentials([file(credentialsId: 'registry-sayagit-jenkins-password', variable: 'REGISTRY_SAYAGIT_JENKINS_PASSWORD')]) {
                        withEnv(['PATH+EXTRA=/busybox']) {
                            try {
                                sh '''#!/busybox/sh
                                    mkdir -p /kaniko/.docker
                                    echo "{\"auths\":{\"https://registry.sayag.it\":{\"username\":\"jenkins\",\"password\":\"$REGISTRY_SAYAGIT_JENKINS_PASSWORD\"}}}" > /kaniko/.docker/config.json
                                    pushToTags="$IMAGE_PUSH_DESTINATION:latest $IMAGE_PUSH_DESTINATION:commit-`git rev-parse --short HEAD`"
                                    if [ "$TAG_NAME" != "" ]; then
                                        pushToTags="$pushToTags $IMAGE_PUSH_DESTINATION:stable $IMAGE_PUSH_DESTINATION:$TAG_NAME"
                                    fi
                                    /kaniko/executor --context `pwd` --destination $pushToTags
                                '''
                            } catch (Exception e) {
                                echo "Caught exception: ${e.getMessage()}"
                                currentBuild.result = 'FAILURE'
                                throw e
                            }
                        }
                    }
                }
            }
        }
    }
}