Skip to content

Commit

Permalink
Jenkinsfile build deploy POC (#2591)
Browse files Browse the repository at this point in the history
* Adding inital Jenkinsfile

* Fixing pipeline file

* Adding dockerfile, helper script, updtes to jenkinsfile

* Forcing pipeline run

* Adding scripts, update to docker test image

* More script changes, run scripts in jenkins stages

* Changed name of container for lint

* Cypress script, Jenkinsfile update
  • Loading branch information
maknop authored Jul 26, 2023
1 parent 4e94ad0 commit 76fc38a
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM registry.access.redhat.com/ubi9/nodejs-18:1-53
USER 0

WORKDIR /workspace

COPY package.json ./
COPY package-lock.json ./
RUN npm install

COPY . .
104 changes: 103 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,115 @@
def secrets = [
[path: params.VAULT_PATH_SVC_ACCOUNT_EPHEMERAL, engineVersion: 1, secretValues: [
[envVar: 'OC_LOGIN_TOKEN', vaultKey: 'oc-login-token'],
[envVar: 'OC_LOGIN_SERVER', vaultKey: 'oc-login-server']]],
[path: params.VAULT_PATH_SVC_ACCOUNT_EPHEMERAL, engineVersion: 1, secretValues: [
[envVar: 'OC_LOGIN_TOKEN_DEV', vaultKey: 'oc-login-token-dev'],
[envVar: 'OC_LOGIN_SERVER_DEV', vaultKey: 'oc-login-server-dev']]],
[path: params.VAULT_PATH_QUAY_PUSH, engineVersion: 1, secretValues: [
[envVar: 'QUAY_USER', vaultKey: 'user'],
[envVar: 'QUAY_TOKEN', vaultKey: 'token']]],
[path: params.VAULT_PATH_RHR_PULL, engineVersion: 1, secretValues: [
[envVar: 'RH_REGISTRY_USER', vaultKey: 'user'],
[envVar: 'RH_REGISTRY_TOKEN', vaultKey: 'token']]],
]

pipeline {
agent { label 'insights' }
options {
timestamps()
}
environment {
PROJECT_NAME="insights-chrome"

MASTER_BRANCH="master"
MASTER_STABLE_BRANCH="master-stable"

IMG_TAG=$(script: "git rev-parse --short=8 HEAD", stdout: true).trim()

}

stages {
stage('Initial Setup') {
steps {
sh 'echo Placeholder Jenkinsfile'
script {
env.ENV_TEST = DefineEnv(env.ghprbTargetBranch)

echo "environment: ${ENV_NAME}"
echo "Source branch: ${ghprbSourceBranch}"
}
}
}

stage('Parallel Stages') {
parallel {
stage('Unit Testing') {
environment {
TEST_CONT="${PROJECT_NAME}-unit-tests"
}
steps {
sh "echo 'ephemeral testing'"

script {
withVault([configuration: configuration, vaultSecrets: secrets]) {
sh '''
./ci/unit_tests.sh
'''
}
}
}
}

stage('Lint') {
steps {
sh "echo 'Lint'"

script {
withVault([configuration: configuration, vaultSecrets: secrets]) {
sh '''
./ci/lint.sh
'''
}
}
}
}

stage('Test E2E') {
steps {
script {
withVault([configuration: configuration, vaultSecrets: secrets]) {
sh '''
./ci/cypress.sh
'''
}
}
}
}

stage('Build') {
steps {
script {
withVault([configuration: configuration, vaultSecrets: secrets]) {
sh '''
./ci/build.sh
'''
}
}
}
}
}
}
}
}

def DefineEnv(branch) {
if (ghprbTargetBranch == 'main') {
echo 'Setting environment to "stage-preview"'
return env.ENV_NAME="stage-preview"
} else if (ghprbTargetBranch == 'stable') {
echo 'Setting environment to "stage-stable"'
return env.ENV_NAME="stage-stable"
}

echo 'Git branch is not "master" or "master-stable"'
return
}
18 changes: 18 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

source ./ci/helpers.sh

PROJECT_NAME="insights-chrome"
TEST_CONT="${PROJECT_NAME}-build"
IMG_TAG=$(git rev-parse --short=8 HEAD)

docker build -t "${TEST_CONT}:${IMG_TAG}" -f Dockerfile.test .

docker run -i \
"${TEST_CONT}:${IMG_TAG}" \
npm run build
RESULT=$?

if [[ $RESULT -ne 0 ]]; then
exit $RESULT
fi
18 changes: 18 additions & 0 deletions ci/cypress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

source ./ci/helpers.sh

PROJECT_NAME="insights-chrome"
TEST_CONT="${PROJECT_NAME}-cypress"
IMG_TAG=$(git rev-parse --short=8 HEAD)

docker build -t "${TEST_CONT}:${IMG_TAG}" -f Dockerfile.test .

docker run -i \
"${TEST_CONT}:${IMG_TAG}" \
npm run test:e2e
RESULT=$?

if [[ $RESULT -ne 0 ]]; then
exit $RESULT
fi
12 changes: 12 additions & 0 deletions ci/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

function get_commit_hash() {

local LATEST_COMMIT_HASH

if ! LATEST_COMMIT=$(_github_api_request "pulls/$ghprbPullId" | jq -r '.head.sha'); then
echo "Error retrieving PR information"
fi

return LATEST_COMMIT_HASH
}
18 changes: 18 additions & 0 deletions ci/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

source ./ci/helpers.sh

PROJECT_NAME="insights-chrome"
TEST_CONT="${PROJECT_NAME}-lint"
IMG_TAG=$(git rev-parse --short=8 HEAD)

docker build -t "${TEST_CONT}:${IMG_TAG}" -f Dockerfile.test .

docker run -i \
"${TEST_CONT}:${IMG_TAG}" \
npm run lint
RESULT=$?

if [[ $RESULT -ne 0 ]]; then
exit $RESULT
fi
18 changes: 18 additions & 0 deletions ci/unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

source ./ci/helpers.sh

PROJECT_NAME="insights-chrome"
TEST_CONT="${PROJECT_NAME}-unit-tests"
IMG_TAG=$(git rev-parse --short=8 HEAD)

docker build -t "${TEST_CONT}:${IMG_TAG}" -f Dockerfile.test .

docker run -i \
"${TEST_CONT}:${IMG_TAG}" \
npm run test -- --coverage
RESULT=$?

if [[ $RESULT -ne 0 ]]; then
exit $RESULT
fi

0 comments on commit 76fc38a

Please sign in to comment.