Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

[OR-305] - Dockerize Orion #304

Merged
merged 20 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 91 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
version: 2
jobs:
build:
---
version: 2.1
executors:
executor_med: # 2cpu, 4G ram
docker:
- image: circleci/openjdk:11.0.2-jdk-stretch
- image: circleci/openjdk:11.0.4-jdk-stretch
- image: postgres:11.4-alpine
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: orion

working_directory: ~/repo

resource_class: medium
working_directory: ~/project
environment:
TERM: dumb
JAVA_TOOL_OPTIONS: -Xmx2048m
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2
GRADLE_MAX_TEST_FORKS: 2
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=2 -Xmx2048m
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: orion

executor_machine:
machine:
image: ubuntu-1604:201903-01 #Ubuntu 16.04, docker 18.09.3, docker-compose 1.23.1
docker_layer_caching: true
working_directory: ~/project

commands:
prepare:
description: "Prepare"
steps:
- checkout

- run:
name: Install Sodium Dependencies
name: Install Dependencies
command: |
sudo apt-get install -y libsodium18

sudo apt-get update
sudo apt-get install -y libsodium18 libsodium-dev apt-transport-https
- restore_cache:
name: Restoring cached gradle dependencies
name: Restore cached gradle dependencies
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
- v1-dependencies-
- deps-{{ checksum "build.gradle" }}-{{ .Branch }}-{{ .Revision }}
- deps-{{ checksum "build.gradle" }}
- deps-

jobs:
build:
executor: executor_med
steps:
- prepare
- run:
name: Spotless checks
command: ./gradlew spotlesscheck
Expand Down Expand Up @@ -120,11 +132,11 @@ jobs:
- run:
name: Collecting JavaDoc
command: |
find . -type d -regex ".*/build/docs/javadoc" | while read dir; do
module=`echo $dir | sed -e 's/build\/docs\/javadoc//'`
mkdir -p ~/docs/"$module"
(cd "$dir" && tar c .) | (cd ~/docs/"$module" && tar x)
done
find . -type d -regex ".*/build/docs/javadoc" | while read dir; do
module=`echo $dir | sed -e 's/build\/docs\/javadoc//'`
mkdir -p ~/docs/"$module"
(cd "$dir" && tar c .) | (cd ~/docs/"$module" && tar x)
done

- store_artifacts:
name: Uploading JavaDoc
Expand All @@ -133,22 +145,43 @@ jobs:

- save_cache:
name: Caching gradle dependencies
key: deps-{{ checksum "build.gradle" }}-{{ .Branch }}-{{ .Revision }}
paths:
- .gradle
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}-{{ .Branch }}-{{ .BuildNum }}
- .gradle
- ~/.gradle

- persist_to_workspace:
root: ~/repo
root: ~/project
paths:
- build/version
- build/distributions/*
- ./

buildDocker:
executor: executor_machine
steps:
- prepare
- run:
name: Install Packages - Java 11
command: |
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt update
sudo apt install -y openjdk-11-jdk
sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
- attach_workspace:
at: ~/project
- run:
name: hadoLint
command: |
docker run --rm -i hadolint/hadolint < docker/Dockerfile
- run:
name: build and test docker image
command: |
mkdir -p docker/reports
./gradlew --no-daemon testDocker

upload-distribution:
docker:
- image: circleci/openjdk:11.0.2-jdk-stretch
executor: executor_med
steps:
- checkout
- prepare
- attach_workspace:
at: ~/project
- run:
Expand All @@ -168,14 +201,40 @@ jobs:
./gradlew deploy
fi

publishDocker:
executor: executor_med
steps:
- prepare
- setup_remote_docker
- attach_workspace:
at: ~/project
- run:
name: Publish Docker
command: |
docker login --username "${DOCKER_USER}" --password "${DOCKER_PASSWORD}"
./gradlew --no-daemon --parallel "-Pbranch=${CIRCLE_BRANCH}" dockerUpload

workflows:
version: 2
pipeline:
jobs:
- build
- buildDocker:
requires:
- build
- upload-distribution:
filters:
branches:
only:
- master
- /^release-.*/
requires:
- build
- publishDocker:
filters:
branches:
only: master
only:
- master
- /^release-.*/
requires:
- buildDocker
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

107 changes: 106 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
import net.ltgt.gradle.errorprone.CheckSeverity

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

buildscript {
repositories { jcenter() }

Expand Down Expand Up @@ -357,7 +361,7 @@ distTar {
delete fileTree(dir:'build/distributions', include: '*.tar.gz')
}
compression = Compression.GZIP
extension = 'tar.gz'
archiveExtension = 'tar.gz'
}

distZip {
Expand All @@ -367,6 +371,107 @@ distZip {
}
}

// rename the top level dir from orion-<version> to orion and this makes it really
// simple for use in docker
tasks.register("dockerDistUntar") {
dependsOn distTar
dependsOn distZip
def dockerBuildDir = "build/docker-orion/"
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}/orion")
}
}

task distDocker(type: Exec) {
dependsOn dockerDistUntar
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
def dockerBuildDir = "build/docker-orion/"
workingDir "${dockerBuildDir}"

doFirst {
copy {
from file("${projectDir}/docker/Dockerfile")
into(workingDir)
}
}

executable "sh"
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
}

task testDocker(type: Exec) {
dependsOn distDocker
def dockerReportsDir = "docker/reports/"
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
workingDir "docker"

doFirst {
new File(dockerReportsDir).mkdir()
}

executable "sh"
args "-c", "bash test.sh ${image}"
}

task dockerUpload(type: Exec) {
dependsOn distDocker
def imageName = "pegasyseng/orion"
def image = project.hasProperty('release.releaseVersion') ? "${imageName}:" + project.property('release.releaseVersion') : "${imageName}:${project.version}"
def cmd = "docker push '${image}'"
def additionalTags = []

if (project.hasProperty('branch') && project.property('branch') == 'master') {
additionalTags.add('develop')
}

if (! version ==~ /.*-SNAPSHOT/) {
additionalTags.add('latest')
additionalTags.add(version.split(/\./)[0..1].join('.'))
}

additionalTags.each { tag -> cmd += " && docker tag '${image}' '${imageName}:${tag.trim()}' && docker push '${imageName}:${tag.trim()}'" }
executable "sh"
args "-c", cmd
}

// http://label-schema.org/rc1/
// using the RFC3339 format "2016-04-12T23:20:50.52Z"
def buildTime() {
return OffsetDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"))
}

def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
// We are in a submodule. The file's contents are `gitdir: <gitFolder>\n`.
// Read the file, cut off the front, and trim the whitespace.
gitFolder = file(gitFolder).text.substring(8).trim() + "/"
}
def takeFromHash = 8
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd

if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb

def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
}

//////
// Runtime
Expand Down
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reports
31 changes: 31 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM openjdk:11.0.5-jre-slim-buster
jframe marked this conversation as resolved.
Show resolved Hide resolved

COPY orion /opt/orion/
WORKDIR /opt/orion

# Install libsodium
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends libsodium23=1.0.17-1; \
jframe marked this conversation as resolved.
Show resolved Hide resolved
apt-get clean; \
rm -rf /var/lib/apt/lists/*

# Expose services ports
# 8080 Node Port, 8888 Client Port
EXPOSE 8080 8888

ENTRYPOINT ["/opt/orion/bin/orion"]

# Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Orion" \
org.label-schema.description="Private Transaction Manager" \
org.label-schema.url="https://docs.orion.pegasys.tech/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/PegaSysEng/orion.git" \
org.label-schema.vendor="PegaSys" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
Loading