cleaning up the build process for docker (#1590)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Joshua Fernandes 6 years ago committed by GitHub
parent 61d19411ba
commit 491012159a
  1. 7
      Jenkinsfile
  2. 40
      build.gradle
  3. 1
      docker/.gitignore
  4. 6
      docker/Dockerfile
  5. 18
      kubernetes/Dockerfile
  6. 39
      kubernetes/build_image.sh

7
Jenkinsfile vendored

@ -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()
@ -211,6 +211,7 @@ try {
${image} \
| grep ${version}"
}
try {
stage(stage_name + 'Test image') {
sh "mkdir -p ${reports_folder}"

@ -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'
@ -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'
@ -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)
@ -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() {

1
docker/.gitignore vendored

@ -1 +1,2 @@
pantheon-*.tar.gz
pantheon/*

@ -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/

@ -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

@ -1,39 +0,0 @@
#!/bin/sh -e
# This script presents a sample way to build Pantheon Docker image
# with automatic build arguments from the current build workspace.
# It must be started from the same path as where the Dockerfile is located.
# you have to pass the imnage tag as an argument like for instance :
# build_image.sh "pegasyseng/pantheon-kubernetes:develop"
CONTEXT_FOLDER=kubernetes/
PANTHEON_BUILD_SOURCE='build/distributions/pantheon-*.tar.gz'
# Checking that you passed the tag for the image to be build
if [ -z "$1" ]
then
me=`basename "$0"`
echo "No image tag argument supplied to ${me}"
echo "ex.: ${me} \"pegasyseng/pantheon-kubernetes:develop\""
exit 1
fi
# looking for the distribution archive, either form CI step that builds form this
# workspace sources but with multiple test steps first
# or it builds it if you don't have one as you are probably
# not in a CI step.
if ls ${PANTHEON_BUILD_SOURCE} 1> /dev/null 2>&1; then
cp ${PANTHEON_BUILD_SOURCE} ${CONTEXT_FOLDER}
else
echo "No pantheon-*.tar.gz archive found."
echo "You are probably not running this from CI so running './gradlew distTar' first to have a local build"
./gradlew distTar
cp ${PANTHEON_BUILD_SOURCE} ${CONTEXT_FOLDER}
fi
# Builds docker image with tags matching the info form this current workspace
docker build \
-t "$1" \
--build-arg BUILD_DATE="`date`" \
--build-arg VCS_REF="`git show -s --format=%h`" \
--build-arg VERSION="`grep -oE "version=(.*)" gradle.properties | cut -d= -f2`" \
${CONTEXT_FOLDER}
Loading…
Cancel
Save