未找到错误404-在docker化并部署到服务器后,未映射的URL

问题描述

我有一个Kotling弹簧启动应用程序(Gradle),在本地开发环境中运行没有问题。

代码库放入Bitbucket后,构建管道会自动运行并使用Gradlew命令生成docker映像:./gradlew clean buildDocker asciidoctor -x test;

# This is a sample build configuration for Docker.
# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2

getProperties: &getProperties
  step:
    image: atlassian/default-image:2
    name: Properties
    script:
      # Get variables from deployment file.
      - export DEPLOYMENT_FILE_PATH=$BITBUCKET_CLONE_DIR/deployment/$BITBUCKET_BRANCH/deployment.json
      - if [ -e $DEPLOYMENT_FILE_PATH ] ; 
        then 
        VALUES="$(cat $DEPLOYMENT_FILE_PATH)";
        for s in $(echo $VALUES | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ); 
          do
          export $s;
          echo $s >> ENVIRONMENT_VARIABLES.txt;
          done
        else
        echo "server=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "username=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "credentials=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "buildable=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "deployable=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        echo "tag=\"\"" >> ENVIRONMENT_VARIABLES.txt;
        fi
      - cd <project> && echo "version="`./gradlew properties -q | grep "^version:" | awk '{printf $2}'` >> ../ENVIRONMENT_VARIABLES.txt
      - echo "name="`./gradlew properties -q | grep "name:" | awk '{printf $2}'` >> ../ENVIRONMENT_VARIABLES.txt
      - echo "documentationFolder=/data/<project>/static-server/htdocs/documentation" >> ../ENVIRONMENT_VARIABLES.txt
      - cat ../ENVIRONMENT_VARIABLES.txt
    artifacts: # defining the artifacts to be passed to each future step.
      - ENVIRONMENT_VARIABLES.txt

buildAndPushImage:  &buildPush
  step:
    name: Build / Push
    image: google/cloud-sdk:latest
    services:
      # Use service Docker to have to docker shell command 
      - docker
    caches:
      # Specify a gradle cache
      - gradle
    script:
      # Import all environment variables 
      - if [ -e $BITBUCKET_CLONE_DIR/ENVIRONMENT_VARIABLES.txt ] ;
       then 
         export $(cat ENVIRONMENT_VARIABLES.txt | xargs); 
       fi

      # BUILD
      - if [ $buildable ]; 
       then
         export BRANCH_NAME=$BITBUCKET_BRANCH;
         cd <project> && ./gradlew clean buildDocker asciidoctor -x test;
       fi
      - docker image ls

      # PUSH 
      - if [ $buildable ];
       then
        IMAGE_BUILT="noor/$name:$version-$BITBUCKET_BRANCH";
        IMAGE_NAME=$GCR_HOSTNAME/$GCR_PROJECT_ID/$BITBUCKET_REPO_SLUG;
        echo $GCR_API_KEYFILE > ~/.gcloud-api-key.json;
        gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json;
        gcloud config set project $GCR_PROJECT_ID;
        gcloud auth configure-docker --quiet;
        docker image tag $IMAGE_BUILT $IMAGE_NAME:$BITBUCKET_COMMIT;
        docker image tag $IMAGE_BUILT $IMAGE_NAME:$BITBUCKET_BRANCH;
        docker push $IMAGE_NAME:$BITBUCKET_COMMIT;
        docker push $IMAGE_NAME:$BITBUCKET_BRANCH;
       fi

pullAndPushImageMaster: &pushLatest
  step:
    name: Pull / Push latest
    image: google/cloud-sdk:latest
    services:
      # Use service Docker to have to docker shell command 
      - docker
    caches:
      # Specify a gradle cache
      - gradle
    script:
      - IMAGE_NAME=$GCR_HOSTNAME/$GCR_PROJECT_ID/$BITBUCKET_REPO_SLUG;
      - echo $GCR_API_KEYFILE > ~/.gcloud-api-key.json;
      - gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json;
      - gcloud config set project $GCR_PROJECT_ID;
      - gcloud auth configure-docker --quiet;
      - docker pull $IMAGE_NAME:$IMAGE_TAG_PULLED;
      - docker image tag $IMAGE_NAME:$IMAGE_TAG_PULLED $IMAGE_NAME:$IMAGE_TAG_MASTER;
      - docker push $IMAGE_NAME:$IMAGE_TAG_MASTER;


pipelines:
  custom:
    getProperties:
      - <<: *getProperties
    buildPush:  
      - <<: *buildPush

  branches:
    feature/pipeline:
      - <<: *getProperties
      - <<: *buildPush

    develop:
      - <<: *getProperties
      - <<: *buildPush

    preprod:
      - <<: *getProperties
      - <<: *buildPush

    recette:
      - <<: *getProperties
      - <<: *buildPush

    master:
      - <<: *getProperties
      - <<: *buildPush
      - <<: *pushLatest
  • 这是build.gradle项目文件
import java.text.SimpleDateFormat

buildscript {
    ext {
        kotlinVersion = '1.3.20'
        springBootVersion = '2.0.4.RELEASE'
        restEasyVersion = '3.5.1.Final'
        keyCloakVersion = '4.4.0.Final'
        sonarVersion = '2.6.2'
        snippetsDir = file('build/generated-snippets')
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
        classpath("org.asciidoctor:asciidoctor-gradle-plugin:1.5.3")
        classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarVersion}"
        classpath("org.infinispan:infinispan-core:9.4.11.Final")
    }
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.asciidoctor.convert'
//apply from: "$project.rootDir/tools/sonar-jacoco.gradle"

version = '0.1'
sourceCompatibility = 1.8

//keep it after version
apply from: 'gradle/docker.gradle'

asciidoctor {
    sourceDir 'src/main/asciidoc'
    outputDir 'build/docs'
    separateOutputDirs false
    attributes 'snippets': snippetsDir,"version": 1.0,"date": new SimpleDateFormat("dd-MM-yyyy").format(new Date())
    backends = ['pdf','html5']
}

compileKotlin {
    kotlinoptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinoptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}
configurations {
    jaxb
    @R_657_5027@
}
repositories {
    mavenCentral()
    jcenter()
}

test {
    forkEvery = 1
    filter {
        includeTestsMatching System.getProperty("includeTests","**")
    }
    reports {
        html.enabled = true
    }
}
// MARK[AMABIS REMoval] - START
/*task genJaxb {
    ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
    ext.classesDir = "${buildDir}/classes/jaxb"
    ext.schema = "http://sw1.amabis.ma:5200?wsdl"

    outputs.dir classesDir

    doLast() {
        project.ant {
            taskdef name: "xjc",classname: "com.sun.tools.xjc.XJCTask",classpath: configurations.jaxb.asPath
            mkdir(dir: sourcesDir)
            mkdir(dir: classesDir)

            xjc(destdir: sourcesDir,schema: schema,package: "amabis.wsdl") {
                arg(value: "-wsdl")
                produces(dir: sourcesDir,includes: "**//*.java")
            }

            javac(destdir: classesDir,source: 1.8,target: 1.8,debug: true,debugLevel: "lines,vars,source",classpath: configurations.jaxb.asPath) {
                src(path: sourcesDir)
                include(name: "**//*.java")
                include(name: "*.java")
            }

            copy(todir: classesDir) {
                fileset(dir: sourcesDir,erroronmissingdir: false) {
                    exclude(name: "**//*.java")
                }
            }
        }
    }
}*/
// MARK[AMABIS REMoval] - END
dependencies {
    //Spring Boot
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile group: 'org.springframework.boot',name: 'spring-boot-starter-mail',version: '2.0.2.RELEASE'
    compile group: 'org.springframework',name: 'spring-context-support',version: '5.0.6.RELEASE'
    compile("org.springframework.ws:spring-ws-core")
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: 'spring-boot-starter-tomcat'
    }
    
    compile('org.springframework:spring-aop:5.0.1.RELEASE')
    compile('org.aspectj:aspectjweaver:1.8.12')
    compile "org.springframework.boot:spring-boot-starter-undertow"
    compile "org.springframework.boot:spring-boot-starter-actuator"

    compile group: 'org.springframework.boot',name: 'spring-boot-starter-thymeleaf',version: '2.0.2.RELEASE'

    // Kotlin
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'

    //Swagger
    implementation("io.springfox:springfox-swagger-ui:2.9.2")
    compile group: 'io.springfox',name: 'springfox-swagger-common',version: '2.9.2'
    compile group: 'io.springfox',name: 'springfox-core',name: 'springfox-swagger2',name: 'springfox-bean-validators',version: '2.9.2'

    implementation 'com.opencsv:opencsv:5.0'

    //Cache
    compile group: 'org.infinispan',name: 'infinispan-spring-boot-starter-embedded',version: '2.1.0.Final'

    //Keycloak
    compile group: 'org.keycloak',name: 'keycloak-spring-security-adapter',version: keyCloakVersion
    compile group: 'org.keycloak',name: 'keycloak-authz-client',name: 'keycloak-admin-client',version: keyCloakVersion
    compile group: 'org.jboss.resteasy',name: 'resteasy-client',version: restEasyVersion
    compile group: 'org.jboss.resteasy',name: 'resteasy-jaxrs',name: 'resteasy-jackson2-provider',name: 'resteasy-spring',version: restEasyVersion

    // PDF
    // https://mvnrepository.com/artifact/com.lowagie/itext
    // https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-core
    compile group: 'org.xhtmlrenderer',name: 'flying-saucer-core',version: '9.1.16'
    // https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-pdf
    compile group: 'org.xhtmlrenderer',name: 'flying-saucer-pdf',version: '9.1.16'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
    compile group: 'org.springframework.boot',version: springBootVersion
    // https://mvnrepository.com/artifact/org.springframework.retry/spring-retry
    compile group: 'org.springframework.retry',name: 'spring-retry',version: '1.2.4.RELEASE'
    compile('org.springframework:spring-aspects')


    //Minio server
    compile 'io.minio:minio:6.0.11'

    //JaxB
    // MARK[AMABIS REMoval] - START

    /*compile(files(genJaxb.classesDir).builtBy(genJaxb))
    compile group: 'com.sun.xml.bind',name: 'jaxb-impl',version: '2.2.11'
    compile group: 'com.sun.xml.bind',name: 'jaxb-core',version: '2.2.11'
    compile group: 'javax.xml.bind',name: 'jaxb-api',version: '2.2.11'
    compile group: 'javax.xml.ws',name: 'jaxws-api',version: '2.2.11'
    compile group: 'javax.xml.soap',name: 'javax.xml.soap-api',version: '1.4.0'
    compile group: 'javax.activation',name: 'activation',version: '1.1.1'

    jaxb 'com.sun.xml.bind:jaxb-core:2.2.11'
    jaxb 'com.sun.xml.bind:jaxb-impl:2.2.11'
    jaxb "com.sun.xml.bind:jaxb-xjc:2.2.11"*/

    // MARK[AMABIS REMoval] - END


    //Jsonb api (need for resteasy client)
    compile group: 'org.apache.geronimo.specs',name: 'geronimo-json_1.1_spec',version: '1.0'
    compile group: 'org.apache.johnzon',name: 'johnzon-jsonb',version: '1.1.7'

    //Jolt
    compile group: 'com.bazaarvoice.jolt',name: 'jolt-core',version: '0.1.1'
    compile group: 'com.bazaarvoice.jolt',name: 'json-utils',version: '0.1.1'

    //Kotlin
    compile('com.fasterxml.jackson.module:jackson-module-kotlin')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")

    //Utils
    compile group: 'org.apache.commons',name: 'commons-lang3',version: '3.7'
    compile group: 'com.fasterxml.jackson.datatype',name: 'jackson-datatype-jsr310',version: '2.9.6'

    // Facebook
    // https://developers.facebook.com/docs/apis-and-sdks
    compile group: 'com.restfb',name: 'restfb',version: '2.6.0'
    compile 'com.google.api-client:google-api-client:1.30.9'
    compile group: 'com.google.apis',name: 'google-api-services-oauth2',version: 'v2-rev157-1.25.0'
    // https://mvnrepository.com/artifact/org.bitbucket.b_c/jose4j
    compile group: 'org.bitbucket.b_c',name: 'jose4j',version: '0.7.2'


    // Schedule
    compile "org.springframework.boot:spring-boot-starter-quartz"
    // If used with external database
    compile "org.springframework.boot:spring-boot-starter-jdbc"
    // https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
    compile group: 'org.mariadb.jdbc',name: 'mariadb-java-client',version: '2.2.5'

    // Logback Json support
    compile "ch.qos.logback.contrib:logback-json-classic:0.1.5"
    compile "ch.qos.logback.contrib:logback-jackson:0.1.5"
    compile "net.logstash.logback:logstash-logback-encoder:5.1"

    compile group: 'com.h2database',name: 'h2',version: '1.4.197'

    // https://mvnrepository.com/artifact/org.apache.tika/tika-core
    compile group: 'org.apache.tika',name: 'tika-core',version: '1.20'

    //Test
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
    testCompile "org.mockito:mockito-core"

    //testCompile "com.github.tomakehurst:wiremock:2.18.0"
    testCompile group: 'org.springframework.restdocs',name: 'spring-restdocs-mockmvc',version: '2.0.2.RELEASE'

    testCompile group: 'org.mock-server',name: 'mockserver-netty',version: '5.4.1'

    testCompile group: 'com.squareup.okhttp',name: 'mockwebserver',version: '2.7.5'

    // https://mvnrepository.com/artifact/com.icegreen/greenmail
    testCompile group: 'com.icegreen',name: 'greenmail',version: '1.5.7'

    @R_657_5027@ "com.github.shyiko:@R_657_5027@:0.29.0"
}

/**
 * Setups taks
 */
apply from: rootProject.file('gradle/setup/setup.gradle')

/**
 * KLINT
 */
task @R_657_5027@(type: JavaExec,group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.@R_657_5027@
    main = "com.github.shyiko.@R_657_502[email protected]"
    args "src/**/*.kt"
    // to generate report in checkstyle format prepend following args:
    // "--reporter=plain","--reporter=checkstyle,output=${buildDir}/@R_657_502[email protected]"
    // see https://github.com/shyiko/@R_657_5027@#usage for more
}
check.dependsOn @R_657_5027@

task @R_657_5027@Format(type: JavaExec,group: "formatting") {
    description = "Fix Kotlin code style deviations."
    classpath = configurations.@R_657_5027@
    main = "com.github.shyiko.@R_657_502[email protected]"
    args "-F","src/**/*.kt"
}

此构建管道始终具有相同的构建成功日志模板(管道构建没有问题)

构建完成后,我们运行docker compose命令将Docker容器部署到服务器中: docker-compose pull && docker-compose up -d

一旦完成部署,在尝试到达某些端点(springfox和某些其他端点)时,我会随机出现404错误(找不到页面)。

解决此问题,我只需重新运行构建管道并重新部署应用程序,它便可以正常工作。

请帮助解决此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)