New release docker image (#1664)

* removing unused docker image, switching to new docker image

* switch to using the new release image and pipeline

* pr fixes

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Joshua Fernandes 5 years ago committed by GitHub
parent 17a7985c7f
commit 29c3c14263
  1. 46
      Jenkinsfile
  2. 71
      Jenkinsfile.release
  3. 9
      build.gradle
  4. 3
      docker/.gitignore
  5. 39
      docker/Dockerfile
  6. 205
      docker/entrypoint.sh
  7. 15
      docker/test.sh
  8. 37
      docker/tests/01/goss.yaml
  9. 12
      docker/tests/01/goss_wait.yaml
  10. 3
      kubernetes/.gitignore
  11. 28
      kubernetes/Dockerfile
  12. 24
      kubernetes/test.sh
  13. 40
      kubernetes/tests/01/goss.yaml
  14. 17
      kubernetes/tests/01/goss_wait.yaml
  15. 113
      kubernetes/tests/dgoss
  16. BIN
      kubernetes/tests/goss-linux-amd64

46
Jenkinsfile vendored

@ -178,13 +178,13 @@ try {
}
}
}
}, KubernetesDockerImage: {
def stage_name = 'Kubernetes Docker image node: '
def image = imageRepos + '/pantheon-kubernetes:' + imageTag
def kubernetes_folder = 'kubernetes'
}, DockerImage: {
def stage_name = 'Docker image node: '
def image = imageRepos + '/pantheon:' + imageTag
def docker_folder = 'docker'
def version_property_file = 'gradle.properties'
def reports_folder = kubernetes_folder + '/reports'
def dockerfile = kubernetes_folder + '/Dockerfile'
def reports_folder = docker_folder + '/reports'
def dockerfile = docker_folder + '/Dockerfile'
node {
checkout scm
docker.image(build_image).inside() {
@ -212,7 +212,7 @@ try {
try {
stage(stage_name + 'Test image') {
sh "mkdir -p ${reports_folder}"
sh "cd ${kubernetes_folder} && bash test.sh ${image}"
sh "cd ${docker_folder} && bash test.sh ${image}"
}
} finally {
junit "${reports_folder}/*.xml"
@ -228,38 +228,6 @@ try {
}
}
}
}
if (env.BRANCH_NAME == "master") {
node {
def stage_name = 'Docker image node: '
def image = imageRepos + '/pantheon:' + imageTag
checkout scm
unstash 'distTarBall'
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(docker_image).inside("-e DOCKER_HOST=tcp://docker:2375 --link ${d.id}:docker") {
stage(stage_name + 'build image') {
sh "cd docker && cp ../build/distributions/pantheon-*.tar.gz ."
pantheon = docker.build(image, "docker")
}
try {
stage('test image') {
sh "apk add bash"
sh "mkdir -p docker/reports"
sh "cd docker && bash test.sh ${image}"
}
} finally {
junit 'docker/reports/*.xml'
sh "rm -rf docker/reports"
}
stage(stage_name + 'push image') {
docker.withRegistry(registry, userAccount) {
pantheon.push()
}
}
}
}
}
}
}
} catch (e) {

@ -1,3 +1,7 @@
#!/usr/bin/env groovy
import java.util.regex.Matcher
void tryAddKnownHost(String hostUrl){
// ssh-keygen -F ${hostUrl} will fail (in bash that means status code != 0) if ${hostUrl} is not yet a known host
def statusCode = sh script:"ssh-keygen -F ${hostUrl}", returnStatus:true
@ -7,13 +11,20 @@ void tryAddKnownHost(String hostUrl){
}
}
@NonCPS
String getShortVersion(String version) {
def regexCheck = (version =~ /^(\d+)\.(\d+)\.\d+.*$/)
def shortReleaseVersion = (regexCheck.size() > 0) ? "${regexCheck[0][1]}.${regexCheck[0][2]}" : ""
return shortReleaseVersion
}
pipeline {
agent {
docker { image 'pegasyseng/pantheon-build:0.0.7-jdk11' }
}
parameters {
string(name: 'BRANCH_NAME', defaultValue: 'master', description: '[MANDATORY] The name of the branch to create the release from')
string(name: 'RELEASE_VERSION', defaultValue: '', description: '[OPTIONAL] When empty: defaults to the current project version')
string(name: 'RELEASE_VERSION', defaultValue: 'x.y.z', description: '[MANDATORY] The version you are deploying')
string(name: 'NEXT_VERSION', defaultValue: '', description: '[OPTIONAL] When empty: defaults to next patch version after current project version')
}
@ -42,20 +53,72 @@ pipeline {
releaseVersion = ''
if( params.RELEASE_VERSION?.trim() ){
releaseVersion = "-Prelease.releaseVersion=${params.RELEASE_VERSION}"
}
}
nextVersion = ''
if( params.NEXT_VERSION?.trim() ){
nextVersion = "-Prelease.newVersion=${params.NEXT_VERSION}"
}
}
}
sh "./gradlew release -Prelease.useAutomaticVersion=true -Prelease.branch=${params.BRANCH_NAME} ${releaseVersion} ${nextVersion}"
}
}
}
}
}
stage('Docker') {
steps {
script {
def docker_folder = 'docker'
def reports_folder = docker_folder + '/reports'
def pantheon = "pegasyseng/pantheon:develop"
def releaseVersion = "${params.RELEASE_VERSION.trim()}"
def shortReleaseVersion = getShortVersion(releaseVersion)
def additionalTags = [releaseVersion]
stage(stage_name + 'Build image') {
sh "echo Building docker image for release ${releaseVersion} with short version ${shortReleaseVersion}"
sh "./gradlew distDocker -x test -Prelease.releaseVersion=${releaseVersion} "
}
try {
stage(stage_name + 'Test image') {
sh "mkdir -p ${reports_folder}"
sh "cd ${docker_folder} && bash test.sh ${pantheon}"
}
} finally {
junit "${reports_folder}/*.xml"
sh "rm -rf ${reports_folder}"
}
stage(stage_name + 'Push image') {
def dockerImage = docker.image(pantheon)
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub-pegasysengci') {
dockerImage.push()
// if this is a stable release add extra docker image tags
if (!releaseVersion.contains('-')) {
additionalTags.add('latest')
if (shortReleaseVersion != "") {
additionalTags.add(shortReleaseVersion)
}
}
additionalTags.each { tag ->
dockerImage.push tag.trim()
}
sh "./gradlew release -Prelease.useAutomaticVersion=true -Prelease.branch=${params.BRANCH_NAME} ${releaseVersion} ${nextVersion}"
}
}
}
}
}
}
}

@ -497,20 +497,21 @@ tasks.register("dockerDistUntar") {
task distDocker(type: Exec) {
dependsOn dockerDistUntar
def image_tag = "develop"
def image="pegasyseng/pantheon-kubernetes:${image_tag}"
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def image="pegasyseng/pantheon:develop"
def dockerBuildDir = "build/docker-pantheon/"
workingDir "${dockerBuildDir}"
doFirst {
copy {
from file("${projectDir}/kubernetes/Dockerfile")
from file("${projectDir}/docker/Dockerfile")
into(workingDir)
}
}
executable "sh"
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${rootProject.version} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ."
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {

3
docker/.gitignore vendored

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

@ -1,21 +1,28 @@
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
FROM openjdk:11.0.2-jre-slim-stretch
RUN mkdir /var/lib/pantheon
RUN mkdir /etc/pantheon/
COPY entrypoint.sh /opt/pantheon/pantheon-entrypoint.sh
RUN chmod +x /opt/pantheon/pantheon-entrypoint.sh
WORKDIR /var/lib/pantheon
VOLUME ["/var/lib/pantheon"]
COPY pantheon /opt/pantheon/
WORKDIR /opt/pantheon
EXPOSE 8545 8546 30303
# Expose services ports
# 8545 HTTP JSON-RPC
# 8546 WS JSON-RPC
# 8547 HTTP GraphQL
# 30303 P2P
EXPOSE 8545 8546 8547 30303
ENV PANTHEON_OPTS="-Dpantheon.docker=true"
ENTRYPOINT ["/opt/pantheon/bin/pantheon"]
ENTRYPOINT ["/opt/pantheon/pantheon-entrypoint.sh"]
# 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="Pantheon" \
org.label-schema.description="Enterprise Ethereum client" \
org.label-schema.url="https://docs.pantheon.pegasys.tech/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/PegaSysEng/pantheon.git" \
org.label-schema.vendor="Pegasys" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"

@ -1,205 +0,0 @@
#!/bin/bash
set -e
if ! { [ "${1#-}" != "$1" ] || [ "$#" == 0 ] || [ "$1" == "blocks" ] || [ "$1" == "public-key" ] || [ "$1" == "password" ]; }; then
exec "$@"
fi
p2plistenset=false
rpclistenset=false
wslistenset=false
for i in "$@"; do
case "$i" in
--rpc-http-host) rpclistenset=true ;;
--rpc-http-host=*) rpclistenset=true ;;
--rpc-http-port) rpclistenset=true ;;
--rpc-http-port=*) rpclistenset=true ;;
--rpc-ws-host) wslistenset=true ;;
--rpc-ws-host=*) wslistenset=true ;;
--rpc-ws-port) wslistenset=true ;;
--rpc-ws-port=*) wslistenset=true ;;
--p2p-host) p2plistenset=true ;;
--p2p-host=*) p2plistenset=true ;;
--p2p-port) p2plistenset=true ;;
--p2p-port=*) p2plistenset=true ;;
esac
done
if $p2plistenset ; then
echo "ERROR: p2p host and port cannot be set by argument under docker, define your custom port by mapping it into the containers 30303 port"
exit 1
else
set -- "--p2p-host=0.0.0.0" "$@"
set -- "--p2p-port=30303" "$@"
fi
if $rpclistenset ; then
echo "ERROR: rpc http host and port cannot be set by argument under docker, define your custom port by mapping it into the containers 8545 port"
exit 1
else
set -- "--rpc-http-host=0.0.0.0" "$@"
set -- "--rpc-http-port=8545" "$@"
fi
if $wslistenset ; then
echo "ERROR: rpc ws host and port cannot be set by argument under docker, define your custom port by mapping it into the containers 8546 port"
exit 1
else
set -- "--rpc-ws-host=0.0.0.0" "$@"
set -- "--rpc-ws-port=8546" "$@"
fi
if [ "$P2P_ENABLED" == "false" ] || [ "$P2P_ENABLED" == "0" ]; then
set -- "--p2p-enabled=false" "$@"
fi
if [ "$DISCOVERY_ENABLED" == "false" ] || [ "$DISCOVERY_ENABLED" == "0" ]; then
set -- "--discovery-enabled=false" "$@"
fi
if [[ ! -z "$BOOTNODES" ]]; then
set -- "--bootnodes=$BOOTNODES" "$@"
fi
if [[ ! -z "$MAX_PEERS" ]]; then
set -- "$@" "--max-peers=$MAX_PEERS"
fi
if [[ ! -z "$BANNED_NODE_IDS" ]]; then
set -- "--banned-node-ids=$BANNED_NODE_IDS" "$@"
fi
if [[ ! -z "$BANNED_NODE_ID" ]]; then
set -- "--banned-node-id=$BANNED_NODE_ID" "$@"
fi
if [[ ! -z "$SYNC_MODE" ]]; then
set -- "--sync-mode=$SYNC_MODE" "$@"
fi
if [[ ! -z "$NETWORK" ]]; then
set -- "--network=$NETWORK" "$@"
fi
if [[ ! -z "$NETWORK_ID" ]]; then
set -- "--network-id=$NETWORK_ID" "$@"
fi
if [ "$RPC_HTTP_ENABLED" == "true" ] || [ "$RPC_HTTP_ENABLED" == "1" ]; then
set -- "--rpc-http-enabled=true" "$@"
fi
if [[ ! -z "$RPC_HTTP_CORS_ORIGINS" ]]; then
set -- "--rpc-http-cors-origins=$RPC_HTTP_CORS_ORIGINS" "$@"
fi
if [[ ! -z "$RPC_HTTP_API" ]]; then
set -- "--rpc-http-api=$RPC_HTTP_API" "$@"
fi
if [[ ! -z "$RPC_HTTP_APIS" ]]; then
set -- "--rpc-http-apis=$RPC_HTTP_APIS" "$@"
fi
if [ "$RPC_WS_ENABLED" == "true" ] || [ "$RPC_WS_ENABLED" == "1" ]; then
set -- "--rpc-ws-enabled=true" "$@"
fi
if [[ ! -z "$RPC_WS_API" ]]; then
set -- "--rpc-ws-api=$RPC_WS_API" "$@"
fi
if [[ ! -z "$RPC_WS_APIS" ]]; then
set -- "--rpc-ws-apis=$RPC_WS_APIS" "$@"
fi
if [[ ! -z "$RPC_WS_REFRESH_DELAY" ]]; then
set -- "--rpc-ws-refresh_delay=$RPC_WS_REFRESH_DELAY" "$@"
fi
if [ "$METRICS_ENABLED" == "true" ] || [ "$METRICS_ENABLED" == "1" ]; then
set -- "--metrics-enabled=true" "$@"
fi
if [[ ! -z "$METRICS_HOST" ]]; then
set -- "--metrics-host=$METRICS_HOST" "$@"
fi
if [[ ! -z "$METRICS_PORT" ]]; then
set -- "--metrics-port=$METRICS_PORT" "$@"
fi
if [ "$METRICS_PUSH_ENABLED" == "true" ] || [ "$METRICS_PUSH_ENABLED" == "1" ]; then
set -- "--metrics-push-enabled=true" "$@"
fi
if [[ ! -z "$METRICS_PUSH_INTERVAL" ]]; then
set -- "--metrics-push-interval=$METRICS_PUSH_INTERVAL" "$@"
fi
if [[ ! -z "$METRICS_PUSH_HOST" ]]; then
set -- "--metrics-push-host=$METRICS_PUSH_HOST" "$@"
fi
if [[ ! -z "$METRICS_PUSH_PORT" ]]; then
set -- "--metrics-push-port=$METRICS_PUSH_PORT" "$@"
fi
if [[ ! -z "$METRICS_PUSH_PROMETHEUS_JOB" ]]; then
set -- "--metrics-push-prometheus-job=$METRICS_PUSH_PROMETHEUS_JOB" "$@"
fi
if [[ ! -z "$HOST_WHITELIST" ]]; then
set -- "--host-whitelist=$HOST_WHITELIST" "$@"
fi
if [[ ! -z "$LOGGING" ]]; then
set -- "--logging=$LOGGING" "$@"
fi
if [ "$MINER_ENABLED" == "true" ] || [ "$MINER_ENABLED" == "1" ]; then
set -- "--miner-enabled=true" "$@"
fi
if [[ ! -z "$MINER_COINBASE" ]]; then
set -- "--miner-coinbase=$MINER_COINBASE" "$@"
fi
if [[ ! -z "$MIN_GAS_PRICE" ]]; then
set -- "--min-gas-price=$MIN_GAS_PRICE" "$@"
fi
if [[ ! -z "$MINER_EXTRA_DATA" ]]; then
set -- "--miner-extra-data=$MINER_EXTRA_DATA" "$@"
fi
if [ "$PERMISSIONS_NODES_ENABLED" == "true" ] || [ "$PERMISSIONS_NODES_ENABLED" == "1" ]; then
set -- "--permissions_nodes_enabled=true" "$@"
fi
if [ "$PERMISSIONS_ACCOUNTS_ENABLED" == "true" ] || [ "$PERMISSIONS_ACCOUNTS_ENABLED" == "1" ]; then
set -- "--permissions_accounts_enabled=true" "$@"
fi
if [ "$PRIVACY_ENABLED" == "true" ] || [ "$PRIVACY_ENABLED" == "1" ]; then
set -- "--privacy-enabled=true" "$@"
fi
if [[ ! -z "$PRIVACY_URL" ]]; then
set -- "--privacy-url=$PRIVACY_URL" "$@"
fi
if [[ ! -z "$PRIVACY_PUBLIC_KEY_FILE" ]]; then
set -- "--privacy-public-key-file=$PRIVACY_PUBLIC_KEY_FILE" "$@"
fi
if [[ ! -z "$PRIVACY_PRECOMPILED_ADDRESS" ]]; then
set -- "--privacy-precompiled-address=$PRIVACY_PRECOMPILED_ADDRESS" "$@"
fi
set -- "/opt/pantheon/bin/pantheon" "$@"
exec "$@"

@ -7,7 +7,18 @@ DOCKER_IMAGE=$1
i=0
# Test for normal unconfigured startup
GOSS_FILES_PATH=tests/01 bash tests/dgoss run $DOCKER_IMAGE > ./reports/01.xml || i=`expr $i + 1`
# Test for normal startup with ports opened
GOSS_FILES_PATH=tests/01 \
bash tests/dgoss \
run $DOCKER_IMAGE \
--network=dev \
--p2p-host=0.0.0.0 \
--rpc-http-enabled \
--rpc-http-host=0.0.0.0 \
--rpc-ws-enabled \
--rpc-ws-host=0.0.0.0 \
--graphql-http-enabled \
--graphql-http-host=0.0.0.0 \
> ./reports/01.xml || i=`expr $i + 1`
exit $i

@ -1,11 +1,4 @@
file:
/etc/pantheon:
exists: true
mode: "0755"
owner: root
group: root
filetype: directory
contains: []
/opt/pantheon/bin/pantheon:
exists: true
mode: "0755"
@ -13,45 +6,27 @@ file:
group: root
filetype: file
contains: []
/opt/pantheon/pantheon-entrypoint.sh:
exists: true
mode: "0755"
owner: root
group: root
filetype: file
contains: []
/tmp/pantheon.tar.gz:
exists: false
contains: []
/var/lib/pantheon:
/opt/pantheon/database:
exists: true
mode: "0755"
owner: root
group: root
filetype: directory
contains: []
/var/lib/pantheon/database:
exists: true
mode: "0755"
owner: root
group: root
filetype: directory
contains: []
/var/lib/pantheon/key:
/opt/pantheon/key:
exists: true
mode: "0600"
owner: root
group: root
filetype: file
contains: []
package:
libc6:
installed: true
port:
tcp:8545:
listening: false
listening: true
tcp:8546:
listening: false
listening: true
tcp:8547:
listening: true
tcp:30303:
listening: true
ip:

@ -3,3 +3,15 @@ port:
listening: true
ip:
- 0.0.0.0
tcp:8545:
listening: true
ip:
- 0.0.0.0
tcp:8546:
listening: true
ip:
- 0.0.0.0
tcp:8547:
listening: true
ip:
- 0.0.0.0

@ -1,3 +0,0 @@
pantheon-*.tar.gz
pantheon/*
pantheon-*

@ -1,28 +0,0 @@
FROM openjdk:11.0.2-jre-slim-stretch
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
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Pantheon" \
org.label-schema.description="Enterprise Ethereum client" \
org.label-schema.url="https://docs.pantheon.pegasys.tech/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/PegaSysEng/pantheon.git" \
org.label-schema.vendor="Pegasys" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"

@ -1,24 +0,0 @@
#!/bin/bash
export GOSS_PATH=tests/goss-linux-amd64
export GOSS_OPTS="$GOSS_OPTS --format junit"
export GOSS_FILES_STRATEGY=cp
DOCKER_IMAGE=$1
i=0
# Test for normal startup with ports opened
GOSS_FILES_PATH=tests/01 \
bash tests/dgoss \
run $DOCKER_IMAGE \
--network=dev \
--p2p-host=0.0.0.0 \
--rpc-http-enabled \
--rpc-http-host=0.0.0.0 \
--rpc-ws-enabled \
--rpc-ws-host=0.0.0.0 \
--graphql-http-enabled \
--graphql-http-host=0.0.0.0 \
> ./reports/01.xml || i=`expr $i + 1`
exit $i

@ -1,40 +0,0 @@
file:
/opt/pantheon/bin/pantheon:
exists: true
mode: "0755"
owner: root
group: root
filetype: file
contains: []
/opt/pantheon/database:
exists: true
mode: "0755"
owner: root
group: root
filetype: directory
contains: []
/opt/pantheon/key:
exists: true
mode: "0600"
owner: root
group: root
filetype: file
contains: []
port:
tcp:8545:
listening: true
tcp:8546:
listening: true
tcp:8547:
listening: true
tcp:30303:
listening: true
ip:
- 0.0.0.0
udp:30303:
listening: true
ip:
- 0.0.0.0
process:
java:
running: true

@ -1,17 +0,0 @@
port:
tcp:30303:
listening: true
ip:
- 0.0.0.0
tcp:8545:
listening: true
ip:
- 0.0.0.0
tcp:8546:
listening: true
ip:
- 0.0.0.0
tcp:8547:
listening: true
ip:
- 0.0.0.0

@ -1,113 +0,0 @@
#!/bin/bash
set -e
USAGE="USAGE: $(basename "$0") [run|edit] <docker_run_params>"
GOSS_FILES_PATH="${GOSS_FILES_PATH:-.}"
info() {
echo -e "INFO: $*" >&2;
}
error() {
echo -e "ERROR: $*" >&2;
exit 1;
}
cleanup() {
set +e
{ kill "$log_pid" && wait "$log_pid"; } 2> /dev/null
rm -rf "$tmp_dir"
if [[ $id ]];then
info "Deleting container"
docker rm -vf "$id" > /dev/null
fi
}
run(){
# Copy in goss
cp "${GOSS_PATH}" "$tmp_dir/goss"
chmod 755 "$tmp_dir/goss"
[[ -e "${GOSS_FILES_PATH}/goss.yaml" ]] && cp "${GOSS_FILES_PATH}/goss.yaml" "$tmp_dir"
[[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir"
[[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir"
# Switch between mount or cp files strategy
GOSS_FILES_STRATEGY=${GOSS_FILES_STRATEGY:="mount"}
case "$GOSS_FILES_STRATEGY" in
mount)
info "Starting docker container"
id=$(docker run -d -v "$tmp_dir:/goss:z" "${@:2}")
docker logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
;;
cp)
info "Creating docker container"
id=$(docker create ${@:2})
info "Copy goss files into container"
docker cp $tmp_dir/. $id:/goss
info "Starting docker container"
docker start $id > /dev/null
;;
*) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"."
esac
log_pid=$!
info "Container ID: ${id:0:8}"
}
get_docker_file() {
if docker exec "$id" sh -c "test -e $1" > /dev/null;then
mkdir -p "${GOSS_FILES_PATH}"
info "Copied '$1' from container to '${GOSS_FILES_PATH}'"
docker cp "$id:$1" "${GOSS_FILES_PATH}"
fi
}
# Main
tmp_dir=$(mktemp -d /tmp/tmp.XXXXXXXXXX)
chmod 777 "$tmp_dir"
trap 'ret=$?;cleanup;exit $ret' EXIT
GOSS_PATH="${GOSS_PATH:-$(which goss 2> /dev/null || true)}"
[[ $GOSS_PATH ]] || { error "Couldn't find goss installation, please set GOSS_PATH to it"; }
[[ ${GOSS_OPTS+x} ]] || GOSS_OPTS="--color --format documentation"
[[ ${GOSS_WAIT_OPTS+x} ]] || GOSS_WAIT_OPTS="-r 30s -s 1s > /dev/null"
GOSS_SLEEP=${GOSS_SLEEP:-0.2}
case "$1" in
run)
run "$@"
if [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]]; then
info "Found goss_wait.yaml, waiting for it to pass before running tests"
if [[ -z "${GOSS_VARS}" ]]; then
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml validate $GOSS_WAIT_OPTS"; then
error "goss_wait.yaml never passed"
fi
else
if ! docker exec "$id" sh -c "/goss/goss -g /goss/goss_wait.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_WAIT_OPTS"; then
error "goss_wait.yaml never passed"
fi
fi
fi
[[ $GOSS_SLEEP ]] && { info "Sleeping for $GOSS_SLEEP"; sleep "$GOSS_SLEEP"; }
# info "Container health"
# if ! docker top $id; then
# docker logs $id
# fi
info "Running Tests"
if [[ -z "${GOSS_VARS}" ]]; then
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml validate $GOSS_OPTS"
else
docker exec "$id" sh -c "/goss/goss -g /goss/goss.yaml --vars='/goss/${GOSS_VARS}' validate $GOSS_OPTS"
fi
;;
edit)
run "$@"
info "Run goss add/autoadd to add resources"
docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh'
get_docker_file "/goss/goss.yaml"
get_docker_file "/goss/goss_wait.yaml"
[[ ! -z "${GOSS_VARS}" ]] && get_docker_file "/goss/${GOSS_VARS}"
;;
*)
error "$USAGE"
esac

Binary file not shown.
Loading…
Cancel
Save