Skip to content

Commit

Permalink
Run in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gl-johnson committed May 9, 2023
1 parent 4051f29 commit 324b1ee
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 45 deletions.
30 changes: 30 additions & 0 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.19-alpine
MAINTAINER CyberArk Software Ltd.
LABEL id="secrets-provider-for-k8s-test-runner"

# On CyberArk dev laptops, golang module dependencies are downloaded with a
# corporate proxy in the middle. For these connections to succeed we need to
# configure the proxy CA certificate in build containers.
#
# To allow this script to also work on non-CyberArk laptops where the CA
# certificate is not available, we copy the (potentially empty) directory
# and update container certificates based on that, rather than rely on the
# CA file itself.
ADD build_ca_certificate /usr/local/share/ca-certificates/
RUN update-ca-certificates

WORKDIR /secrets-provider-for-k8s

RUN apk add -u curl \
gcc \
git \
mercurial \
musl-dev

COPY go.mod go.sum /secrets-provider-for-k8s/

RUN go mod download

COPY . .

ENTRYPOINT [ "go", "test", "-v" ]
70 changes: 38 additions & 32 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,37 @@ pipeline {
}
}

stage('Run Unit Tests') {
// stage('Run Unit Tests') {
// steps {
// sh './bin/test_unit'
// }
// post {
// always {
// sh './bin/coverage'
// junit 'junit.xml'
// cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, lineCoverageTargets: '70, 0, 0', methodCoverageTargets: '70, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
// ccCoverage("gocov", "--prefix github.com/cyberark/secrets-provider-for-k8s")
// }
// }
// }

stage('Run E2E Tests') {
steps {
sh './bin/test_unit'
}
post {
always {
sh './bin/coverage'
junit 'junit.xml'
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, lineCoverageTargets: '70, 0, 0', methodCoverageTargets: '70, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
ccCoverage("gocov", "--prefix github.com/cyberark/secrets-provider-for-k8s")
}
sh './bin/test_e2e'
}
}

stage ("DAP Integration Tests on GKE") {
steps {
script {
def tasks = [:]
tasks["Kubernetes GKE, DAP"] = {
sh "./bin/start --docker --dap --gke"
}
parallel tasks
}
}
}
// stage ("DAP Integration Tests on GKE") {
// steps {
// script {
// def tasks = [:]
// tasks["Kubernetes GKE, DAP"] = {
// sh "./bin/start --docker --dap --gke"
// }
// parallel tasks
// }
// }
// }

stage ("DAP Integration Tests on OpenShift") {
when {
Expand Down Expand Up @@ -226,17 +232,17 @@ pipeline {
// We want to avoid running in parallel.
// When we have 2 build running on the same environment (gke env only) in parallel,
// we get the error "gcloud crashed : database is locked"
stage ("OSS Integration Tests on GKE") {
steps {
script {
def tasks = [:]
tasks["Kubernetes GKE, oss"] = {
sh "./bin/start --docker --oss --gke"
}
parallel tasks
}
}
}
// stage ("OSS Integration Tests on GKE") {
// steps {
// script {
// def tasks = [:]
// tasks["Kubernetes GKE, oss"] = {
// sh "./bin/start --docker --oss --gke"
// }
// parallel tasks
// }
// }
// }

// Allows for the promotion of images.
stage('Push images to internal registry') {
Expand Down
19 changes: 17 additions & 2 deletions bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export RUN_IN_DOCKER
export CONJUR_DEPLOYMENT
export DEV
export SUMMON_ENV
export TEST
export TEMPLATE_OVERRIDE

echo $TEMPLATE_OVERRIDE
Expand All @@ -81,7 +80,23 @@ export CONJUR_MAJOR_VERSION=5
# make sure we are in the project root
cd $(git rev-parse --show-toplevel)

source bootstrap.env
# source bootstrap.env
export UNIQUE_TEST_ID="$(uuidgen | tr "[:upper:]" "[:lower:]" | head -c 10)"
export CONJUR_MINOR_VERSION=5.0
export CONJUR_APPLIANCE_IMAGE=registry.tld/conjur-appliance:$CONJUR_MINOR_VERSION-stable
export CONJUR_FOLLOWER_COUNT=1
export CONJUR_ACCOUNT=account-$UNIQUE_TEST_ID
export AUTHENTICATOR_ID=conjur-$UNIQUE_TEST_ID-test
export CONJUR_ADMIN_PASSWORD=ADmin123!!!!
export DEPLOY_MASTER_CLUSTER=true
export CONJUR_NAMESPACE_NAME=conjur-$UNIQUE_TEST_ID
export TEST_RUNNER_IMAGE=runner-$UNIQUE_TEST_ID
export DEV=false
export APP_NAMESPACE_NAME=app-$UNIQUE_TEST_ID
export SUMMON_ENV=gke
export RUN_IN_DOCKER=true

export SECRETS_MODE=k8s # Supported: [k8s, k8s-rotation, p2f, p2f-rotation]

pushd deploy
if [[ $RUN_IN_DOCKER = true ]]; then
Expand Down
16 changes: 16 additions & 0 deletions bin/test_e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -exo pipefail

echo "NOTE: Running this locally requires that you have the DEV environment values uncommented in bootstrap.env!"
echo "It also assumes that you have Kubernetes enabled in Docker Desktop."

docker build -f Dockerfile.e2e -t secrets-provider-for-k8s-e2e-test-runner:latest .

docker run --rm -t \
--volume "$PWD"/:/secrets-provider-for-k8s/test/ \
secrets-provider-for-k8s-e2e-test-runner:latest \
./e2e \
$@

echo "E2E test exit status: $?"
6 changes: 0 additions & 6 deletions e2e/kind-config.yaml

This file was deleted.

24 changes: 19 additions & 5 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -26,24 +27,40 @@ var (
k8sClient klient.Client
)

var platform = flag.String("platform", "gke", "Kubernetes platform to run tests on (gke, next, current, oldest)")
var oss = flag.Bool("oss", false, "Use Conjur OSS (default is DAP)")

func TestMain(m *testing.M) {
fmt.Printf("1")

testenv = env.New()
path := conf.ResolveKubeConfigFile()
cfg := envconf.NewWithKubeConfig(path)
testenv = env.NewWithConfig(cfg)

testenv.Setup(
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
fmt.Println("Setup")
fmt.Printf("2")

k8sClient = cfg.Client()

// Build the Secrets Provider image
cmd1 := exec.Command("../bin/build")
out, err := cmd1.CombinedOutput()
if err != nil {
fmt.Printf("Failed to execute command. %v, %s", err, out)
}

cmd2 := exec.Command("../bin/start", "--dev")
// Run the dev environment start script
// NOTE - this won't work in CI - we probably need to run it
// with the following flag combinations based on parameters from the test script:
// --docker --oss --gke
// --docker --dap --gke
// --docker --oss --current/next/oldest
cmd2 := exec.Command("../bin/start", "--"+*platform)
if *oss {
cmd2.Args = append(cmd2.Args, "--oss")
}
out, err = cmd2.CombinedOutput()
if err != nil {
fmt.Printf("Failed to execute command. %v, %s", err, out)
Expand All @@ -67,9 +84,6 @@ func TestMain(m *testing.M) {
fmt.Print(err)
}

// Setup complete
fmt.Println("Setup done")

return ctx, nil
},
)
Expand Down

0 comments on commit 324b1ee

Please sign in to comment.