-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jenkinsfile build deploy POC (#2591)
* 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
Showing
7 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |