Skip to content

Commit

Permalink
Revert "cleaning up the build process for docker (PegaSysEng#1590)"
Browse files Browse the repository at this point in the history
This reverts commit 8dbca1c.
  • Loading branch information
ajsutton committed Jul 4, 2019
1 parent 3b842c9 commit 2e0900c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 50 deletions.
7 changes: 3 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,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 './gradlew docker'
sh "${kubernetes_image_build_script} '${image}'"
}

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 @@ -208,7 +208,6 @@ try {
${image} \
| grep ${version}"
}

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

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 @@ -24,7 +22,6 @@ 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 @@ -477,35 +474,6 @@ 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 @@ -531,14 +499,6 @@ 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: 0 additions & 1 deletion docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pantheon-*.tar.gz
pantheon/*
18 changes: 13 additions & 5 deletions kubernetes/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# 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 pantheon /opt/pantheon/
# Copy extracted binaries from the previous step image
COPY --from=extract-stage /tmp/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: 39 additions & 0 deletions kubernetes/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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}

0 comments on commit 2e0900c

Please sign in to comment.