Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Age wrong #1158

Closed
gluehbirnenkopf opened this issue Oct 18, 2018 · 7 comments
Closed

Image Age wrong #1158

gluehbirnenkopf opened this issue Oct 18, 2018 · 7 comments

Comments

@gluehbirnenkopf
Copy link

gluehbirnenkopf commented Oct 18, 2018

Description of the issue:
When I run gradle build with jib, the images which get produced are 48 years old.
Does not matter if i build on windows, unix or jenkins

$ date
Thu Oct 18 12:50:57 CEST 2018

$ docker images | grep 19.100
registry.eu-de.bluemix.net/XXXXXXX/testservice 19.100.01-SNAPSHOT 46359d31bb35 48 years ago 491MB

Expected behavior:
Image age should be properly set.

Steps to reproduce:
This happens when executing "gradle jib" and "gradle jibDockerBuild"
It does not matter if the image gets pubished locally or in private registry

Environment:
$ ./gradlew -version


Gradle 4.10

Build time: 2018-08-27 18:35:06 UTC
Revision: ee3751ed9f2034effc1f0072c2b2ee74b5dce67d

Kotlin DSL: 1.0-rc-3
Kotlin: 1.2.60
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Linux 4.9.0-8-amd64 amd64
jib-maven-plugin Configuration:

plugins {
	id 'org.springframework.boot' version '2.0.4.RELEASE'
	id 'org.sonarqube' version '2.6.2'
	id 'com.palantir.docker' version '0.20.1'
	id 'com.palantir.docker-run' version '0.20.1'
	id 'com.google.cloud.tools.jib' version '0.9.11'
}

apply plugin: 'java-library' // Apply the java-library plugin to add support for Java Library
apply plugin: 'io.spring.dependency-management' //plugin allowing spring dependency management
apply plugin: 'org.springframework.boot' //building jar via spring boot
apply plugin: 'com.palantir.docker'  //building docker image directly from gradle

// Define repository
repositories {
    mavenCentral()
    maven {
        credentials {
            username camundaRepoUser
            password camundaRepoPassword
        }
        url 'https://app.camunda.com/nexus/content/repositories/camunda-bpm-ee'
	}
}

//define bill of materials
dependencyManagement {
    imports {
        mavenBom 'org.springframework.boot:spring-boot-dependencies:2.0.2.RELEASE'
    }
    imports {
        mavenBom 'org.camunda.bpm:camunda-bom:7.9.1-ee'
    }
}

//define dependencies
dependencies {
	compile 'org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp-ee:3.0.0'
	compile 'com.h2database:h2'
    testImplementation 'junit:junit'
}

compileJava   {
	sourceCompatibility = '1.8'
	targetCompatibility = '1.8'
}



//***************************Task configuration starts here***************************

//Definition of variables for proper docker image, container and release (helm) naming 
project.ext.projectName_RFC1123_calc = projectName_RFC1123 ?: project.name.toLowerCase()
project.ext.dockerImageName = "${registryName}/${registryNamespace}/${projectName_RFC1123_calc}:${releaseName}${versionSuffix}" 
project.ext.dockerContainerName = "${projectName_RFC1123_calc}-${releaseName}${versionSuffix}"
bootJar.archiveName="${dockerContainerName}.jar"
project.ext.versionSuffixKube=releaseName.replace('.','-')

//Method to get the name of the current branch for helmUpgrade Task
def gitBranch() {
    def branch = ""
    def proc = "git rev-parse --abbrev-ref HEAD".execute()
    proc.in.eachLine { line -> branch = line }
    proc.err.eachLine { line -> println line }
    proc.waitFor()
    branch
}

//Check if this build.gradle is executed in CI or locally
if (project.hasProperty("isCI")) {
            println("featureBranch property gets set by jenkins")
} else {
        println("featureBranch property gets set by exeuting git cmd")
	featureBranch=gitBranch()
        }

docker {
	dependsOn build
	name dockerImageName
	files bootJar.archivePath
	buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}


dockerRun {
	name dockerContainerName
	image dockerImageName
	ports '8080:8080'
	daemonize true
}
tasks.dockerRun.dependsOn(tasks.docker)

tasks.dockerRemoveContainer.dependsOn(tasks.dockerStop)

task dockerRerun {
	group = 'Docker Run'
	description = 'Recreates the container by running tasks dockerStop, dockerRemoveContainer, dockerRun, which are idempotent.'
	dependsOn tasks.dockerStop 
	dependsOn tasks.dockerRemoveContainer
	dependsOn tasks.dockerRun
	tasks.findByName('dockerRemoveContainer').mustRunAfter 'dockerStop'
	tasks.findByName('dockerRun').mustRunAfter 'dockerRemoveContainer'
	doLast {
		println "Docker container '${projectName_RFC1123_calc}' has been recreated" 
	}
}

//***************************Helm Specific Tasks ***************************

/*task CloudAuth(type:Exec) {
	group = 'Helm'
	description = 'Login to IBMCloud and retrieve KUBECONFIG'
	commandLine 'sh', '-c', 'bx login --apikey Phc9RgWxEPahU2f7-pth9HxbWOOOa3HyO96Ss9hdo0F3 -a https://api.eu-de.bluemix.net'
	commandLine 'sh', '-c', 'KubeEnvVar=$(bx ks cluster-config --cluster XXXXXXXX --export -s) && $KubeEnvVar'
}
*/
task helmDelete(type:Exec) {
	group = 'Helm'
	description = 'Helm Delete'
	commandLine 'sh', '-c', "helm delete --purge '${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}'"
}

task helmUpgradeDb(type:Exec) {
	//dependsOn tasks.CloudAuth
	group = 'Helm'
	description = 'Helm Upgrade'
	workingDir 'helm/db'
	
	commandLine 'sh', '-c', 'helm init --client-only'
	commandLine 'sh', '-c', "helm upgrade --install '${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}-db' --set appname='${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}-db' ."
}
	
task helmUpgrade(type:Exec) {
	//dependsOn tasks.CloudAuth
	group = 'Helm'
	description = 'Helm Upgrade'
	workingDir 'helm/main'
	
	commandLine 'sh', '-c', 'helm init --client-only'
	commandLine 'sh', '-c', "helm upgrade --install '${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}' --set appname='${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}' --set image='${dockerImageName}' --set ingressSubdomain='${projectName_RFC1123_calc}-${versionSuffixKube}-${featureBranch}' ."
	
	//Gradle exec tasks doesnt support $path variable, therefore explixit shell needs to be used.
	
}

tasks.build.dependsOn tasks.jib
//tasks.build.dependsOn tasks.jibDockerBuild

jib {
	from {
	  image = 'registry.eu-de.bluemix.net/XXXXXXXXX/openjdk18-openshift:latest'
	  auth {
      username = registryUser // Defined in 'gradle.properties'.
      password = registryPassword
		}
	}
	to {
	  image = dockerImageName
	  auth {
      username = registryUser // Defined in 'gradle.properties'.
      password = registryPassword
	}
	}
}

Log output:

Additional Information:

@gluehbirnenkopf
Copy link
Author

gluehbirnenkopf commented Oct 18, 2018

docker image inspect gives interesting details:
],
"RepoDigests": [],
"Parent": "",
"Comment": "",
"Created": "1970-01-01T00:00:00Z",
"Container": "",
"ContainerConfig": {
"Hostname": "",

the creation date is somehow not acurate.

Seems like this could have something to do with this issue, although we are not using maven/docker plugin at all.
spotify/docker-maven-plugin#58

@zy475459736
Copy link

I am using Jib's maven-plugin. And I solved the same kind of problem by setting useCurrentTimestamp true in the pom.xml .

@zy475459736
Copy link

As far as I know ,not only the Image , but also the resources classes and other things related to your app are having the 1970-01-01 timestamp.
You can find more details searching through the issues.

@gluehbirnenkopf
Copy link
Author

@zy475459736 bazelbuild/rules_docker#52

Or is as designed?

@zy475459736
Copy link

As far as I know ,yes. It is designed to be that way.

@TadCordle
Copy link
Contributor

As mentioned above, this is intended behavior, as we wipe timestamps to maintain reproducibility. You can use the useCurrentTimestamp configuration parameter to set the correct creation date.

It's also worth noting that we are tracking the ability to add a custom timestamp in this issue: #1079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants