node('jenkins-jnlp') {
    //checkout源代码
    stage('Checkout') {
        checkout scm
    }
    //npm编译
    stage('Build npm') {
        sh "rm -rf /usr/bin/node"
        sh "rm -rf /usr/bin/npm"
        sh "rm -rf /usr/bin/npx"
        sh "rm -rf /usr/bin/yarn"

        sh "ln -s /usr/local/node-v18.18.0-linux-x64-glibc-217/bin/node /usr/bin/node"
        sh "ln -s /usr/local/node-v18.18.0-linux-x64-glibc-217/bin/npm /usr/bin/npm"
        sh "ln -s /usr/local/node-v18.18.0-linux-x64-glibc-217/bin/npx /usr/bin/npx"
        sh "ln -s /usr/local/node-v18.18.0-linux-x64-glibc-217/bin/yarn /usr/bin/yarn"
        
        sh "yarn install"
        sh "yarn run build:prod"
    }
    //dockerfile编译
    stage('Build docker') {
		try { sh "docker build -t ruoyi-ui:latest -f deploy/Dockerfile ." } catch (e) {}
		try { sh "docker images | grep none | xargs -t -r docker rmi" } catch (e) {}
		try { sh "docker rm -f ruoyi-ui" } catch (e) {}
		try { sh "docker run -it -d -p 9004:8080 --name ruoyi-ui ruoyi-ui:latest" } catch (e) {}
    }
}
