Skip to content

Commit 4260c5d

Browse files
authored
Merge pull request #91 from jduimovich/ci-updates-jenkins
update to ci-test
2 parents 0db8b38 + 75f9fe4 commit 4260c5d

File tree

8 files changed

+115
-23
lines changed

8 files changed

+115
-23
lines changed

ci-test.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ source setup-local-dev-repos.sh
33
source init-tas-vars.sh
44
eval "$(hack/get-trustification-env.sh)"
55

6+
# setting secrets for the dev repos is slow
7+
# after the first setting, you can skip this step
8+
# warning, if your secrets are stale, do not skip this step
9+
SKIP_SECRETS=${SKIP_SECRETS:-false}
10+
11+
if [ $SKIP_SECRETS == "true" ]; then
12+
echo "WARNING SKIP_SECRETS set to true, skipping configuration of secrets"
13+
fi
14+
615
if [ $TEST_REPO_ORG == "redhat-appstudio" ]; then
716
echo "Cannot do CI testing using the redhat-appstudio org"
817
echo "You must create forks in your own org and set up MY_TEST_REPO_ORG (github) and MY_TEST_REPO_GITLAB_ORG"
@@ -13,6 +22,7 @@ function updateGitAndQuayRefs() {
1322
if [ -f $1 ]; then
1423
sed -i "s!quay.io/redhat-appstudio/rhtap-task-runner.*!quay.io/$MY_QUAY_USER/rhtap-task-runner:dev!g" $1
1524
sed -i "s!https://github.com/redhat-appstudio!https://github.com/$MY_GITHUB_USER!g" $1
25+
sed -i "s!RHTAP_Jenkins@main!RHTAP_Jenkins@dev!g" $1
1626
fi
1727
}
1828

@@ -39,6 +49,12 @@ function updateBuild() {
3949
updateGitAndQuayRefs $SETUP_ENV
4050
cat $SETUP_ENV
4151
}
52+
53+
# create latest images for dev github and gitlab
54+
make build-push-image
55+
# update the jenkins library in the dev branch
56+
bash hack/update-jenkins-library
57+
4258
# Repos on github and gitlab, github and jenkins
4359
# source repos are updated with the name of the corresponding GITOPS REPO for update-deployment
4460
updateBuild $BUILD $TEST_GITOPS_REPO
@@ -89,22 +105,30 @@ function updateRepos() {
89105
# set secrets and then push to repos to ensure pipeline runs are
90106
# with correct values
91107
# github
92-
bash hack/ghub-set-vars $TEST_BUILD_REPO
93-
bash hack/ghub-set-vars $TEST_GITOPS_REPO
108+
if [ $SKIP_SECRETS == "false" ]; then
109+
bash hack/ghub-set-vars $TEST_BUILD_REPO
110+
bash hack/ghub-set-vars $TEST_GITOPS_REPO
111+
fi
112+
94113
updateRepos $BUILD
95114
updateRepos $GITOPS
96115

97116
# gitlab
98-
bash hack/glab-set-vars $(basename $TEST_BUILD_GITLAB_REPO)
99-
bash hack/glab-set-vars $(basename $TEST_GITOPS_GITLAB_REPO)
117+
if [ $SKIP_SECRETS == "false" ]; then
118+
bash hack/glab-set-vars $(basename $TEST_BUILD_GITLAB_REPO)
119+
bash hack/glab-set-vars $(basename $TEST_GITOPS_GITLAB_REPO)
120+
fi
100121
updateRepos $GITLAB_BUILD
101122
updateRepos $GITLAB_GITOPS
102123

103124
# Jenkins
104125
# note, jenkins secrets are global so set once"
105-
bash hack/jenkins-set-secrets
126+
if [ $SKIP_SECRETS == "false" ]; then
127+
bash hack/jenkins-set-secrets
128+
fi
106129
updateRepos $JENKINS_BUILD
107130
updateRepos $JENKINS_GITOPS
131+
bash hack/jenkins-run-pipeline $(basename $TEST_BUILD_JENKINS_REPO)
108132

109133
echo
110134
echo "Github Build and Gitops Repos"

generated/gitops-template/githubactions/.github/workflows/gitops-promotion.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ jobs:
4343
runs-on: ubuntu-24.04
4444
container:
4545
image: quay.io/redhat-appstudio/rhtap-task-runner:latest
46+
options: --privileged
4647
environment: production
4748

4849
steps:
4950
- name: Check for required secrets
50-
uses: actions/github-script@v6
51+
uses: actions/github-script@v7
5152
with:
5253
script: |
5354
const secrets = {
@@ -83,7 +84,7 @@ jobs:
8384
core.info(`✅ All the required secrets are set`);
8485
}
8586
- name: Check out repository
86-
uses: actions/checkout@v3
87+
uses: actions/checkout@v4
8788
with:
8889
fetch-depth: '2'
8990
- name: Pre-init

generated/source-repo/githubactions/.github/workflows/build-and-update-gitops.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151

5252
steps:
5353
- name: Check for required secrets
54-
uses: actions/github-script@v6
54+
uses: actions/github-script@v7
5555
with:
5656
script: |
5757
const secrets = {
@@ -88,7 +88,7 @@ jobs:
8888
core.info(`✅ All the required secrets are set`);
8989
}
9090
- name: Check out repository
91-
uses: actions/checkout@v3
91+
uses: actions/checkout@v4
9292
with:
9393
fetch-depth: '2'
9494
- name: Pre-init

hack/jenkins-run-pipeline

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/bin/bash
22
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
33

4-
ENV="MY_JENKINS_SERVER MY_JENKINS_USER MY_JENKINS_BUILD_TOKEN MY_JENKINS_TOKEN COSIGN_SECRET_PASSWORD COSIGN_SECRET_KEY COSIGN_PUBLIC_KEY "
5-
6-
ENV+=" ACS__API_TOKEN ACS__CENTRAL_ENDPOINT GITOPS_AUTH_PASSWORD "
7-
source $SCRIPTDIR/../rhtap/verify-deps-exist "$ENV" "java "
4+
ENV="MY_JENKINS_SERVER MY_JENKINS_USER MY_JENKINS_BUILD_TOKEN MY_JENKINS_TOKEN"
5+
source $SCRIPTDIR/../rhtap/verify-deps-exist "$ENV" "curl "
86

97
PNAME=$1
108
if [ -z $PNAME ]; then
119
echo $0 pipelinename
1210
exit 0
1311
fi
1412

15-
curl -X POST -u $MY_JENKINS_USER:$MY_JENKINS_TOKEN \
16-
$MY_JENKINS_SERVER/job/$PNAME/build?token=$MY_JENKINS_BUILD_TOKEN
13+
http_code=$(curl -s -w "%{http_code}" -u $MY_JENKINS_USER:$MY_JENKINS_TOKEN \
14+
${MY_JENKINS_SERVER}job/$PNAME/build?token=$MY_JENKINS_BUILD_TOKEN)
15+
16+
echo "Started pipeline $PNAME http_code = $http_code"

hack/update-jenkins-library

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
3+
4+
# Copy the jenkins file contents the shared library
5+
# Can be used to update the release by setting
6+
# JENKIN_SHARED_LIB_USER=redhat-appstudio
7+
# JENKIN_SHARED_LIB_BRANCH=main
8+
# For dev the default is MY_GITHUB_USER and dev branch
9+
# see ci-test for branch munging in scripts
10+
# JENKIN_SHARED_LIB_USER=$MY_GITHUB_USER
11+
# JENKIN_SHARED_LIB_BRANCH=dev
12+
13+
JENKIN_SHARED_LIB_USER=${JENKIN_SHARED_LIB_USER:-$MY_GITHUB_USER}
14+
JENKIN_SHARED_LIB_BRANCH=${JENKIN_SHARED_LIB_BRANCH:-dev}
15+
16+
echo "Updating Jenkins shared lib for $JENKIN_SHARED_LIB_USER in branch $JENKIN_SHARED_LIB_BRANCH"
17+
18+
WORKDIR=$(mktemp -d)
19+
JENKINS_SHARED_LIB=$WORKDIR/jenkins-library
20+
REPO=https://github.com/$JENKIN_SHARED_LIB_USER/tssc-sample-jenkins
21+
22+
MULTI_CI=$(pwd)
23+
GEN_SRC=$MULTI_CI/generated/source-repo
24+
GEN_GITOPS=$MULTI_CI/generated/gitops-template
25+
26+
git clone --quiet $REPO $JENKINS_SHARED_LIB
27+
cd $JENKINS_SHARED_LIB
28+
if [ $(git rev-parse --verify $JENKIN_SHARED_LIB_BRANCH 2> /dev/null) ]; then
29+
echo "$JENKIN_SHARED_LIB_BRANCH exists"
30+
git checkout $JENKIN_SHARED_LIB_BRANCH
31+
git pull
32+
else
33+
echo "$JENKIN_SHARED_LIB_BRANCH branch created"
34+
git checkout -b $JENKIN_SHARED_LIB_BRANCH
35+
git branch --set-upstream-to=origin/$JENKIN_SHARED_LIB_BRANCH
36+
fi
37+
38+
# copy scripts and groovy files in to proper locations
39+
# delete extra files - We should move these outside of ./rhtap
40+
# so we don't copy extra files by mistake
41+
cp $MULTI_CI/rhtap/* $JENKINS_SHARED_LIB/resources
42+
cp $MULTI_CI/rhtap.groovy $JENKINS_SHARED_LIB/vars
43+
# skip the env.template.sh files, they are not for the library
44+
# we should consider copying the Jenkins files for gitops and src into a jenkinsfile-samples
45+
# so the latest Jenkinsfile is up to date in the library
46+
rm -rf $JENKINS_SHARED_LIB/resources/env.template.sh
47+
rm -rf $JENKINS_SHARED_LIB/resources/signing-secret-env.sh
48+
git add .
49+
git commit -m "Jenkins library update from tssc-dev-multi-ci"
50+
git status
51+
pwd
52+
git pull
53+
git push --set-upstream origin $JENKIN_SHARED_LIB_BRANCH

hack/wait-for-gitops-update.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ function promoteIfUpdated() {
3131
echo "P: ${!PREV_IMAGE_ENV_NAME}"
3232
echo "C: $CURRENT_IMAGE"
3333

34+
DEFAULT_INIT_IMAGE="quay.io/redhat-appstudio/dance-bootstrap-app:latest"
3435
if [[ "${!PREV_IMAGE_ENV_NAME}" != "$CURRENT_IMAGE" ]]; then
35-
echo "$REPO being updated from ${!PREV_IMAGE_ENV_NAME} to $CURRENT_IMAGE"
36-
bash $SCRIPTDIR/rhtap-promote --repo $REPO
36+
echo "$REPO dev changes, from ${!PREV_IMAGE_ENV_NAME} to $CURRENT_IMAGE"
37+
if [[ "$CURRENT_IMAGE" == "$DEFAULT_INIT_IMAGE" ]]; then
38+
echo "Image changed back to default, skipping using PR to promote image"
39+
else
40+
bash $SCRIPTDIR/rhtap-promote --repo $REPO
41+
fi
3742
eval "$PREV_IMAGE_ENV_NAME"="$CURRENT_IMAGE"
3843
fi
3944
}
@@ -47,8 +52,16 @@ function pushIfUpdated() {
4752
echo "C: $CURRENT_IMAGE"
4853

4954
if [[ "${!PREV_IMAGE_ENV_NAME}" != "$CURRENT_IMAGE" ]]; then
50-
echo "$REPO being updated from ${!PREV_IMAGE_ENV_NAME} to $CURRENT_IMAGE"
51-
bash $SCRIPTDIR/rhtap-push-dev --repo $REPO
55+
echo "$REPO dev changes, from ${!PREV_IMAGE_ENV_NAME} to $CURRENT_IMAGE"
56+
if [[ "$CURRENT_IMAGE" == "$DEFAULT_INIT_IMAGE" ]]; then
57+
echo "Image changed, skipping reset for default base image"
58+
else
59+
# jenkins update the gitops repo with a push and then run the job
60+
bash $SCRIPTDIR/rhtap-push-dev --repo $REPO
61+
JOB=$(basename $REPO)
62+
echo "Running Jenkins Job"
63+
bash $SCRIPTDIR/jenkins-run-pipeline $JOB
64+
fi
5265
eval "$PREV_IMAGE_ENV_NAME"="$CURRENT_IMAGE"
5366
fi
5467
}

templates/gitops-template/gitops-promotion.yml.njk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ jobs:
3939
runs-on: ubuntu-24.04
4040
container:
4141
image: quay.io/redhat-appstudio/rhtap-task-runner:latest
42+
options: --privileged
4243
environment: production
4344

4445
steps:
4546
- name: Check for required secrets
46-
uses: actions/github-script@v6
47+
uses: actions/github-script@v7
4748
with:
4849
script: |
4950
{#-
@@ -78,7 +79,7 @@ jobs:
7879
core.info(`✅ All the required secrets are set`);
7980
}
8081
- name: Check out repository
81-
uses: actions/checkout@v3
82+
uses: actions/checkout@v4
8283
with:
8384
fetch-depth: '2'
8485
- name: Pre-init

templates/source-repo/build-and-update-gitops.yml.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
steps:
5252
- name: Check for required secrets
53-
uses: actions/github-script@v6
53+
uses: actions/github-script@v7
5454
with:
5555
script: |
5656
{#-
@@ -89,7 +89,7 @@ jobs:
8989
core.info(`✅ All the required secrets are set`);
9090
}
9191
- name: Check out repository
92-
uses: actions/checkout@v3
92+
uses: actions/checkout@v4
9393
with:
9494
fetch-depth: '2'
9595
- name: Pre-init

0 commit comments

Comments
 (0)