Skip to content

Commit

Permalink
cleaning up the build process for docker (hyperledger#1590)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
  • Loading branch information
joshuafernandes authored Jun 21, 2019
1 parent 61d1941 commit 4910121
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 60 deletions.
7 changes: 4 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,20 @@ try {
def stage_name = 'Kubernetes Docker image node: '
def image = imageRepos + '/pantheon-kubernetes:' + imageTag
def kubernetes_folder = 'kubernetes'
def kubernetes_image_build_script = kubernetes_folder + '/build_image.sh'
def version_property_file = 'gradle.properties'
def reports_folder = kubernetes_folder + '/reports'
def dockerfile = kubernetes_folder + '/Dockerfile'
node {
checkout scm
unstash 'distTarBall'
docker.image(build_image).inside() {
stage(stage_name + 'Dockerfile lint') {
sh "docker run --rm -i hadolint/hadolint < ${dockerfile}"
}

stage(stage_name + 'Build image') {
sh "${kubernetes_image_build_script} '${image}'"
sh './gradlew docker'
}

stage(stage_name + "Test image labels") {
shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
version = sh(returnStdout: true, script: "grep -oE \"version=(.*)\" ${version_property_file} | cut -d= -f2").trim()
Expand All @@ -211,6 +211,7 @@ try {
${image} \
| grep ${version}"
}

try {
stage(stage_name + 'Test image') {
sh "mkdir -p ${reports_folder}"
Expand Down
40 changes: 40 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import net.ltgt.gradle.errorprone.CheckSeverity

import java.text.SimpleDateFormat

plugins {
id 'com.diffplug.gradle.spotless' version '3.23.1'
id 'com.jfrog.bintray' version '1.8.4'
Expand All @@ -22,6 +24,7 @@ plugins {
id 'me.champeau.gradle.jmh' version '0.4.8' apply false
id 'net.ltgt.errorprone' version '0.8.1'
id 'net.researchgate.release' version '2.7.0'
id "com.palantir.docker" version "0.22.1"
}

group = 'tech.pegasys.pantheon'
Expand Down Expand Up @@ -397,6 +400,35 @@ distZip {
}
}

// rename the top level dir from pantheon-<version> to pantheon and this makes it really
// simple for use in docker
tasks.register("dockerDistUntar") {
dependsOn distTar
def dockerBuildDir = "build/distributions/docker-pantheon/"
def distTarFile = distTar.outputs.files.singleFile
def distTarFileName = distTar.outputs.files.singleFile.name.replace(".tar.gz", "")

doFirst {
new File(dockerBuildDir).mkdir()
copy {
from tarTree(distTarFile)
into (dockerBuildDir)
}
file("${dockerBuildDir}/${distTarFileName}").renameTo("${dockerBuildDir}/pantheon")
}
}

docker {
def image_tag = "develop"
dependsOn dockerDistUntar
name "pegasyseng/pantheon-kubernetes:${image_tag}"
dockerfile file('kubernetes/Dockerfile')
files "build/distributions/docker-pantheon/"
buildArgs(['BUILD_DATE': buildTime(), 'VERSION': rootProject.version, 'VCS_REF': getCheckedOutGitCommitHash()])
pull true
noCache true
}

task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
additionalSourceDirs.from files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.from files(subprojects.sourceSets.main.allSource.srcDirs)
Expand All @@ -422,6 +454,14 @@ configure(subprojects.findAll {it.name != 'errorprone-checks'}) {
}
}

// http://label-schema.org/rc1/
// using the RFC3339 format "2016-04-12T23:20:50.52Z"
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}

// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT
// with the git commit version.
def calculateVersion() {
Expand Down
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pantheon-*.tar.gz
pantheon/*
6 changes: 1 addition & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
FROM openjdk:11.0.2-jre-slim-stretch

COPY pantheon-*.tar.gz /tmp/.
RUN tar xzf /tmp/pantheon-*.tar.gz -C /tmp && \
rm /tmp/pantheon-*.tar.gz && \
mv /tmp/pantheon-* /opt/pantheon

COPY pantheon /opt/pantheon/

RUN mkdir /var/lib/pantheon
RUN mkdir /etc/pantheon/
Expand Down
18 changes: 5 additions & 13 deletions kubernetes/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
# extract image stage
# extractin here reduces the number of layers in the final image
FROM alpine:3.9 AS extract-stage
# Copy Pantheon binaries from previous jenkins artefact step
# or from the result of ./gradlew distTar
# and lett ADD unpack them
ADD pantheon-*.tar.gz /tmp/

# Run image stage
# Use openJDK JRE only for running pantheon
FROM openjdk:11.0.2-jre-slim-stretch
# Copy extracted binaries from the previous step image
COPY --from=extract-stage /tmp/pantheon* /opt/pantheon

COPY pantheon /opt/pantheon/
WORKDIR /opt/pantheon

# Expose services ports
# 8545 HTTP JSON-RPC
# 8546 WS JSON-RPC
# 8547 HTTP GraphQL
# 30303 P2P
EXPOSE 8545 8546 8547 30303

ENTRYPOINT ["/opt/pantheon/bin/pantheon"]

# Build-time metadata as defined at http://label-schema.org
# Use the build_image.sh script in the kubernetes directory of this project to
# easily build this image or as an example of how to inject build parameters.
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
Expand Down
39 changes: 0 additions & 39 deletions kubernetes/build_image.sh

This file was deleted.

0 comments on commit 4910121

Please sign in to comment.