Skip to content

Commit 3ef686c

Browse files
authored
Merge pull request #109 from UoA-eResearch/rc2.1.1
Rc2.1.1
2 parents ab16cfd + 8738e25 commit 3ef686c

File tree

76 files changed

+1642
-6913
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1642
-6913
lines changed

Jenkinsfile

Lines changed: 97 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ pipeline {
1111
booleanParam(name: "FORCE_REDEPLOY_SP", defaultValue: false, description: 'Force redeploy the search-proxy Lambda even if there are no code changes.')
1212
}
1313

14-
agent {
14+
agent {
1515
label("uoa-buildtools-ionic")
1616
}
1717

1818
options {
1919
buildDiscarder(
2020
logRotator(
21-
daysToKeepStr: "30"
21+
numToKeepStr: "3"
2222
)
2323
)
2424
}
@@ -108,7 +108,7 @@ pipeline {
108108
}
109109
}
110110

111-
stage('Build projects') {
111+
stage('Build cer-graphql and search-proxy projects') {
112112
stages {
113113
stage('Build search-proxy') {
114114
when {
@@ -139,6 +139,98 @@ pipeline {
139139
}
140140
}
141141
}
142+
}
143+
}
144+
145+
stage('Run cer-graphql and search-proxy tests') {
146+
stages {
147+
stage('Run cer-graphql tests') {
148+
when {
149+
anyOf {
150+
changeset "**/cer-graphql/**/*.*"
151+
equals expected: true, actual: params.FORCE_REDEPLOY_CG
152+
}
153+
}
154+
steps {
155+
script {
156+
if (env.BRANCH_NAME != 'prod') { // tests rely on 2FAB so we do not test in prod
157+
echo 'Testing cer-graphql project'
158+
dir('cer-graphql') {
159+
sh "npm install"
160+
sh "export stage=${BRANCH_NAME} && npm run test -- --aws-profile=${awsProfile}"
161+
}
162+
}
163+
}
164+
}
165+
}
166+
stage('Run search-proxy tests') {
167+
when {
168+
anyOf {
169+
changeset "**/hub-search-proxy/**/*.*"
170+
equals expected: true, actual: params.FORCE_REDEPLOY_SP
171+
}
172+
}
173+
steps {
174+
script {
175+
if (env.BRANCH_NAME != 'prod') {
176+
echo "Testing hub-search-proxy project"
177+
dir('hub-search-proxy') {
178+
sh "npm run test -- --aws-profile ${awsProfile} --stage ${env.BRANCH_NAME}"
179+
}
180+
}
181+
}
182+
}
183+
}
184+
}
185+
}
186+
187+
stage('Deploy cer-graphql and search-proxy projects') {
188+
parallel {
189+
stage('Deploy cer-graphql') {
190+
when {
191+
anyOf {
192+
changeset "**/cer-graphql/**/*.*"
193+
equals expected: true, actual: params.FORCE_REDEPLOY_CG
194+
}
195+
}
196+
steps { // TODO: may need to modify commands once we have both dev & test in nonprod account
197+
echo 'Deploying cer-graphql image to ECR on ' + BRANCH_NAME
198+
echo "Logging in to ECR"
199+
sh "(aws ecr get-login --no-include-email --region ${awsRegion} --profile=${awsProfile}) | /bin/bash"
200+
201+
echo "Tagging built image with ECR tag"
202+
sh "docker tag cer-graphql:latest ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/research-hub/cer-graphql-${BRANCH_NAME}:latest"
203+
204+
echo "Pushing built image to ECR"
205+
sh "docker push ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/research-hub/cer-graphql-${BRANCH_NAME}:latest"
206+
207+
echo 'Deploying cer-graphql image from ECR to Fargate on ' + BRANCH_NAME
208+
sh "aws ecs update-service --profile ${awsProfile} --cluster cer-graphql-cluster-${BRANCH_NAME} --service cer-graphql-service-${BRANCH_NAME} --task-definition cer-graphql-${BRANCH_NAME} --force-new-deployment --region ${awsRegion}"
209+
sh "aws ecs update-service --profile ${awsProfile} --cluster cer-graphql-cluster-${BRANCH_NAME} --service cer-graphql-preview-service-${BRANCH_NAME} --task-definition cer-graphql-preview-${BRANCH_NAME} --force-new-deployment --region ${awsRegion}"
210+
}
211+
}
212+
stage('Deploy search-proxy') {
213+
when {
214+
anyOf {
215+
changeset "**/hub-search-proxy/**/*.*"
216+
equals expected: true, actual: params.FORCE_REDEPLOY_SP
217+
}
218+
}
219+
steps {
220+
echo "Deploying hub-search-proxy Lambda function to ${BRANCH_NAME}"
221+
script {
222+
dir("hub-search-proxy") {
223+
sh "npm run deploy -- --aws-profile ${awsProfile} --stage ${BRANCH_NAME}"
224+
}
225+
}
226+
echo "Deploy to ${BRANCH_NAME} complete"
227+
}
228+
}
229+
}
230+
}
231+
232+
stage('Research Hub Web steps') {
233+
stages {
142234
stage('Build research-hub-web') {
143235
when {
144236
anyOf {
@@ -195,11 +287,7 @@ pipeline {
195287
}
196288
}
197289
}
198-
}
199-
}
200-
201-
stage('Run tests') {
202-
stages {
290+
203291
stage('Run research-hub-web tests') {
204292
when {
205293
anyOf {
@@ -219,48 +307,7 @@ pipeline {
219307
}
220308
}
221309
}
222-
stage('Run cer-graphql tests') {
223-
when {
224-
anyOf {
225-
changeset "**/cer-graphql/**/*.*"
226-
equals expected: true, actual: params.FORCE_REDEPLOY_CG
227-
}
228-
}
229-
steps {
230-
script {
231-
if (env.BRANCH_NAME != 'prod') { // tests rely on 2FAB so we do not test in prod
232-
echo 'Testing cer-graphql project'
233-
dir('cer-graphql') {
234-
sh "npm install"
235-
sh "export stage=${BRANCH_NAME} && npm run test -- --aws-profile=${awsProfile}"
236-
}
237-
}
238-
}
239-
}
240-
}
241-
stage('Run search-proxy tests') {
242-
when {
243-
anyOf {
244-
changeset "**/hub-search-proxy/**/*.*"
245-
equals expected: true, actual: params.FORCE_REDEPLOY_SP
246-
}
247-
}
248-
steps {
249-
script {
250-
if (env.BRANCH_NAME != 'prod') {
251-
echo "Testing hub-search-proxy project"
252-
dir('hub-search-proxy') {
253-
sh "npm run test -- --aws-profile ${awsProfile} --stage ${env.BRANCH_NAME}"
254-
}
255-
}
256-
}
257-
}
258-
}
259-
}
260-
}
261-
262-
stage('Deploy projects') {
263-
parallel {
310+
264311
stage('Deploy research-hub-web') {
265312
when {
266313
anyOf {
@@ -327,47 +374,6 @@ pipeline {
327374
}
328375
}
329376
}
330-
stage('Deploy cer-graphql') {
331-
when {
332-
anyOf {
333-
changeset "**/cer-graphql/**/*.*"
334-
equals expected: true, actual: params.FORCE_REDEPLOY_CG
335-
}
336-
}
337-
steps { // TODO: may need to modify commands once we have both dev & test in nonprod account
338-
echo 'Deploying cer-graphql image to ECR on ' + BRANCH_NAME
339-
echo "Logging in to ECR"
340-
sh "(aws ecr get-login --no-include-email --region ${awsRegion} --profile=${awsProfile}) | /bin/bash"
341-
342-
echo "Tagging built image with ECR tag"
343-
sh "docker tag cer-graphql:latest ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/research-hub/cer-graphql-${BRANCH_NAME}:latest"
344-
345-
echo "Pushing built image to ECR"
346-
sh "docker push ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/research-hub/cer-graphql-${BRANCH_NAME}:latest"
347-
348-
echo 'Deploying cer-graphql image from ECR to Fargate on ' + BRANCH_NAME
349-
sh "aws ecs update-service --profile ${awsProfile} --cluster cer-graphql-cluster-${BRANCH_NAME} --service cer-graphql-service-${BRANCH_NAME} --task-definition cer-graphql-${BRANCH_NAME} --force-new-deployment --region ${awsRegion}"
350-
sh "aws ecs update-service --profile ${awsProfile} --cluster cer-graphql-cluster-${BRANCH_NAME} --service cer-graphql-preview-service-${BRANCH_NAME} --task-definition cer-graphql-preview-${BRANCH_NAME} --force-new-deployment --region ${awsRegion}"
351-
}
352-
}
353-
stage('Deploy search-proxy') {
354-
when {
355-
anyOf {
356-
changeset "**/hub-search-proxy/**/*.*"
357-
equals expected: true, actual: params.FORCE_REDEPLOY_SP
358-
}
359-
}
360-
steps {
361-
echo "Deploying hub-search-proxy Lambda function to ${BRANCH_NAME}"
362-
script {
363-
dir("hub-search-proxy") {
364-
sh "npm run deploy -- --aws-profile ${awsProfile} --stage ${BRANCH_NAME}"
365-
}
366-
}
367-
echo "Deploy to ${BRANCH_NAME} complete"
368-
369-
}
370-
}
371377
}
372378
}
373379
}

cer-graphql/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ async function createServer(config) {
246246
}
247247
})
248248

249+
customQueryResolvers['personCollection'] = (root, args, context, info) => {
250+
if (IS_PREVIEW_ENV) {
251+
// Add preview as a query argument if we are in a preview
252+
// environment.
253+
args.preview = true;
254+
}
255+
if (context.user) { // If the user is signed in, simply forward request
256+
return forwardReqToContentful(args, context, info);
257+
} else { // If the user is not signed in they shouldn't be allowed to request the personCollection
258+
return new AuthenticationError('You cannot query the personCollection unless authenticated.');
259+
}
260+
}
261+
249262
// Function used in resolvers to forward requests on to Contentful
250263
let forwardReqToContentful = (args, context, info) =>
251264
info.mergeInfo.delegateToSchema({
@@ -265,8 +278,12 @@ async function createServer(config) {
265278
resolvers: [{ Query: customQueryResolvers }],
266279
});
267280

281+
const enablePlayground = CONTENTFUL_ENVIRONMENT_ID === 'dev' ? true : false;
282+
268283
return new ApolloServer({
269284
schema,
285+
introspection: true,
286+
playground: enablePlayground,
270287
context: ({ req }) => {
271288
// Log incoming queries
272289
if (req && req.body && (req.body.operationName != 'IntrospectionQuery'))

0 commit comments

Comments
 (0)