node('jenkins-jnlp') {
    //checkout源代码
    stage('Checkout') {
        checkout scm
    }
    //npm编译
    stage('Build pnpm') {
        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 /opt/node-v20.9.0-linux-x64-glibc-217/bin/node /usr/bin/node"
        sh "ln -s /opt/node-v20.9.0-linux-x64-glibc-217/bin/npm /usr/bin/npm"
        sh "ln -s /opt/node-v20.9.0-linux-x64-glibc-217/bin/npx /usr/bin/npx"
        sh "ln -s /opt/node-v20.9.0-linux-x64-glibc-217/bin/yarn /usr/bin/yarn"

        sh "npm install -g pnpm"
        sh "pnpm install"
        sh "npm run build"
    }
    //dockerfile编译
    stage('Build docker') {
        try { sh "docker build -t shop-vite:latest -f deploy/Dockerfile ." } catch (e) {}
        try { sh "docker images | grep none | xargs -t -r docker rmi" } catch (e) {}
        try { sh "docker rm -f shop-vite" } catch (e) {}
        try { sh "docker run -it -d -p 9001:8080 --name shop-vite shop-vite:latest" } catch (e) {}
    }
}
