Skip to content

Commit 55f6eae

Browse files
uoa-noelTrombach
andauthored
Add Contentful link checker app deployment to CI pipeline (#290)
* Add token references for CI build * Add missing package * Fix npm shrinkwrap issue * Fix wrong org id * Update readme * Update documentation * Add indentation and minor fixes to README * FIx minor heading issue with readme Co-authored-by: Lukas Trombach <[email protected]>
1 parent 9924d77 commit 55f6eae

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

Jenkinsfile

+41-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pipeline {
99
booleanParam(name: "FORCE_REDEPLOY_WEB", defaultValue: false, description: 'Force redeploy the web frontend even if there are no code changes.' )
1010
booleanParam(name: "FORCE_REDEPLOY_CG", defaultValue: false, description: 'Force redeploy the cer-graphql API even if there are no code changes.')
1111
booleanParam(name: "FORCE_REDEPLOY_SP", defaultValue: false, description: 'Force redeploy the search-proxy Lambda even if there are no code changes.')
12+
booleanParam(name: "FORCE_REDEPLOY_SLC", defaultValue: false, description: 'Force redeploy the subhub-link-checker Contentful App even if there are no code changes.')
1213
}
1314

1415
agent {
@@ -108,7 +109,7 @@ pipeline {
108109
}
109110
}
110111

111-
stage('Build cer-graphql and search-proxy projects') {
112+
stage('Build cer-graphql, subhub-link-checker and search-proxy projects') {
112113
stages {
113114
stage('Build search-proxy') {
114115
when {
@@ -139,6 +140,23 @@ pipeline {
139140
}
140141
}
141142
}
143+
stage('Build subhub-link-checker') {
144+
when {
145+
anyOf {
146+
changeset "**/subhub-link-checker/**/*.*"
147+
equals expected: true, actual: params.FORCE_REDEPLOY_SLC
148+
}
149+
}
150+
steps {
151+
echo 'Building subhub-link-checker project'
152+
dir("subhub-link-checker") {
153+
echo 'Installing subhub-link-checker dependencies...'
154+
sh "npm ci"
155+
sh "npm run build"
156+
}
157+
}
158+
159+
}
142160
}
143161
}
144162

@@ -184,7 +202,7 @@ pipeline {
184202
}
185203
}
186204

187-
stage('Deploy cer-graphql and search-proxy projects') {
205+
stage('Deploy cer-graphql, search-proxy and subhub-link-checker projects') {
188206
parallel {
189207
stage('Deploy cer-graphql') {
190208
when {
@@ -226,6 +244,27 @@ pipeline {
226244
echo "Deploy to ${BRANCH_NAME} complete"
227245
}
228246
}
247+
stage('Deploy subhub-link-checker') {
248+
when {
249+
anyOf {
250+
changeset "**/subhub-link-checker/**/*.*"
251+
equals expected: true, actual: params.FORCE_REDEPLOY_SLC
252+
}
253+
}
254+
steps {
255+
dir("subhub-link-checker") {
256+
// Grab relevant credentials
257+
withCredentials([
258+
string(credentialsId: "contentful-pat", variable: "contentfulPat"),
259+
string(credentialsId: "contentful-link-checker-app-id-${BRANCH_NAME}", variable: "contentfulSLCAppId"),
260+
string(credentialsId: "contentful-org-id", variable: "contentfulOrgId")
261+
]) {
262+
sh "npm run upload-ci -- --organization-id ${contentfulOrgId} --definition-id ${contentfulSLCAppId} --token ${contentfulPat}"
263+
}
264+
265+
}
266+
}
267+
}
229268
}
230269
}
231270

subhub-link-checker/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ Part of the Hub Expansion project. This is required due to SubHub routing logic
1414
There are three instances of the Contentful App - one for dev, test and prod. [Read more...](https://www.contentful.com/developers/docs/extensibility/app-framework/)
1515

1616
## Seeing and deploying your changes
17+
Build and deployment for the SubHub Link Checker app are part of the Jenkins CI process.
18+
19+
ResearchHub has three Contentful environments - `dev`, `test`, and `prod`, and `prod` is the one content authors see. An [app definition](https://www.contentful.com/developers/docs/extensibility/app-framework/app-definition/) is set up for in three different environments, which means different versions of the link checker app can run in each environment. Deploy changes to `dev` for previewing your changes and manual testing - Contentful Apps can't be run locally. Deployment to `test` and `prod` should only be done as part of [the official release process](https://wiki.auckland.ac.nz/display/APPLCTN/Release+to+prod) and content authors need to be notified before deploying updates.
20+
1721
This assumes the Contentful environments are set up with the required app definitions. See the First time deployment section if you need to redo those steps.
1822

19-
ResearchHub has three Contentful environments - `dev`, `test`, and `prod`, and `prod` is the one content authors see. Use `dev` for previewing your changes and manual testing - Contentful Apps can't be run locally. Deployment to `test` and `prod` should only be done as part of [the official release process](https://wiki.auckland.ac.nz/display/APPLCTN/Release+to+prod) and content authors need to be notified before deploying updates.
23+
## Manual deployment
24+
If you would like to manually deploy the App (for example, if you would like to preview changes in the dev Contentful environment without having to commit and push into your dev branch), follow these instructions.
2025

21-
1. If you are deploying to `test` and `prod`, first check-in your changes to Git and merge them into `master`.
2226
1. Run `npm run build` to build a new bundle.
2327
2. Run `npm run upload`.
2428
1. For the bundle comment, put in the hash of Git commit you built the bundle from if applicable.
@@ -28,6 +32,7 @@ ResearchHub has three Contentful environments - `dev`, `test`, and `prod`, and `
2832
3. Go to Contentful to see your changes.
2933

3034
## First time deployment
35+
These instructions are for deploying to a fresh Contentful instance.
3136

3237
1. Create three Apps on Contentful. In the `subhub-link-checker` folder, run the command:
3338

@@ -59,6 +64,11 @@ ResearchHub has three Contentful environments - `dev`, `test`, and `prod`, and `
5964
6065
Open a SubHub to verify the Internal Pages field is still editable. If it is, then the App setup is complete!
6166
67+
4. Create a [Contentful personal access token](https://www.contentful.com/developers/docs/references/authentication/#getting-a-personal-access-token), preferably using a service account. Add these five secrets to Jenkins credentials store, so the Jenkins CI process can refer to the values. Read `Jenkinsfile` to see how these values are used.
68+
* Personal Access Token: `contentful-pat`
69+
* The App definition ID for each app definition: `contentful-link-checker-app-id-dev`, `contentful-link-checker-app-id-test`, and `contentful-link-checker-app-id-prod`.
70+
* Organisation ID: `contentful-org-id`
71+
6272
## Development
6373
This project was bootstrapped with [Create Contentful App](https://github.com/contentful/create-contentful-app).
6474

subhub-link-checker/package-lock.json

+2-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

subhub-link-checker/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@types/node": "^16.0.2",
1717
"@types/react": "^17.0.14",
1818
"@types/react-dom": "^17.0.11",
19+
"contentful-management": "^7.51.3",
1920
"cross-env": "^7.0.3",
2021
"gh-pages": "^3.1.0",
2122
"react": "^17.0.2",
@@ -29,7 +30,7 @@
2930
"test": "react-scripts test",
3031
"eject": "react-scripts eject",
3132
"upload": "contentful-app-scripts upload --bundle-dir ./build",
32-
"upload-ci": "contentful-app-scripts upload --ci --bundle-dir ./build --organization-id $CONTENTFUL_ORG_ID --definition-id $CONTENTFUL_APP_DEF_ID --token $CONTENTFUL_ACCESS_TOKEN"
33+
"upload-ci": "contentful-app-scripts upload --ci --bundle-dir ./build"
3334
},
3435
"eslintConfig": {
3536
"extends": "react-app"

0 commit comments

Comments
 (0)