-
Notifications
You must be signed in to change notification settings - Fork 9
[AC-xx: CI-CD] Ci cd/jenkinsfile yibo #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yibowdevops
wants to merge
4
commits into
A-Comosus:develop
Choose a base branch
from
yibowdevops:ci-cd/jenkinsfile-yibo
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,111 @@ | ||
| pipeline { | ||
| agent any | ||
|
|
||
| options { | ||
| // Keep artifacts and logs of last 10 builds | ||
| buildDiscarder(logRotator(numToKeepStr: '10')) | ||
| // Disallows concurrent executions of the Pipeline. | ||
| disableConcurrentBuilds() | ||
| // Sets a timeout period for the Pipeline run, after which Jenkins should abort the Pipeline. | ||
| // Set timeout period as 1 hour to prevent infinite blocks in our Jenkins. | ||
| timeout(time: 1, unit: 'HOURS') | ||
| // Prepends all console output generated by the Pipeline run with the time at which the line was emitted. | ||
| timestamps() | ||
| } | ||
|
|
||
| tools { | ||
| dockerTool 'docker-latest' | ||
| } | ||
|
|
||
| environment { | ||
| IMAGE_VERSION = "${env.BUILD_ID}" | ||
| AWS_REGION = 'ap-southeast-2' | ||
| CYPRESS_RECORD_KEY = credentials('cypress-record-key') | ||
| N_G_ENDPOINT = credentials('N_G_ENDPOINT') | ||
| ECR_URL = credentials('ECR_REGISTRY_URL') | ||
| AWS_ECR_URL = credentials('AWS_ECR_URL') | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| stages { | ||
| stage('Cleanup Worker space') { | ||
| steps { | ||
| cleanWs() | ||
| checkout scm | ||
| } | ||
| } | ||
|
|
||
| stage('Git check out') { | ||
| steps{ | ||
| echo 'Git check out...' | ||
| // Get source code from a GitHub repository | ||
| git branch: env.BRANCH_NAME, url:'https://github.com/A-Comosus/comosus-client.git' | ||
| } | ||
| } | ||
| stage('Install dependencies') { | ||
| steps { | ||
| echo 'Install dependencies...' | ||
| sh 'yarn' | ||
| sh 'yarn codegen' | ||
| } | ||
| } | ||
|
|
||
| stage('Test') { | ||
| steps { | ||
| echo 'Testing..' | ||
| sh 'yarn test:coverage' | ||
| sh 'yarn e2e:start-server:record' | ||
| } | ||
| } | ||
|
|
||
| stage('Checking for linter error') { | ||
| steps { | ||
| echo 'Checking for linter error....' | ||
| sh 'yarn lint' | ||
| } | ||
| } | ||
|
|
||
| stage('Build') { | ||
| steps { | ||
| echo 'Building....' | ||
| sh 'yarn build:with-codegen' | ||
| } | ||
| } | ||
|
|
||
| stage('Build and Upload Image to ECR') { | ||
|
|
||
| when { | ||
| anyOf { | ||
| branch 'develop' | ||
| branch 'CI-CD' | ||
yibowdevops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| steps { | ||
| script{ | ||
| docker.withRegistry("https://${AWS_ECR_URL}", 'ecr:ap-southeast-2:AWS_CREDENTIAL') { | ||
| app = docker.build("${ECR_URL}:${env.BUILD_NUMBER}", "--build-arg N_G_ENDPOINT=${N_G_ENDPOINT} -f Dockerfile.yibo .") | ||
| app.push() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| post { | ||
| always { | ||
| withCredentials([string(credentialsId: 'AWS_REPOSITORY_URL_SECRET', variable: 'AWS_ECR_URL')]) { | ||
| deleteDir() | ||
yibowdevops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| success { | ||
| echo 'Pipeline Successed :)' | ||
| } | ||
| failure { | ||
| mail to: 'Norris.wu.au@outlook.com', | ||
| subject: "Failed Pipeline: ${currentBuild.fullDisplayName}", | ||
| body: "Project: ${env.JOB_NAME}, Build Number: ${env.BUILD_NUMBER}, Something is wrong with ${env.BUILD_URL}" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,48 @@ | ||
| # Install dependencies only when needed | ||
| FROM node:16-alpine AS build_env | ||
| # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
| COPY package.json yarn.lock ./ | ||
| RUN yarn install --frozen-lockfile | ||
|
|
||
| # Rebuild the source code only when needed | ||
| FROM node:16-alpine AS builder | ||
| WORKDIR /app | ||
|
|
||
| COPY --from=build_env /app/node_modules ./node_modules | ||
| COPY . . | ||
|
|
||
| ARG N_G_ENDPOINT | ||
|
|
||
| ENV NEXT_PUBLIC_GRAPHQL_ENDPOINT ${N_G_ENDPOINT} | ||
|
|
||
| RUN yarn codegen && yarn build | ||
|
|
||
| FROM node:16-alpine AS runner | ||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV production | ||
|
|
||
| RUN addgroup --system --gid 1001 nodejs | ||
| RUN adduser --system --uid 1001 nextjs | ||
|
|
||
| # You only need to copy next.config.js if you are NOT using the default configuration | ||
| COPY --from=builder /app/next.config.js ./ | ||
| COPY --from=builder /app/public ./public | ||
| COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next | ||
| COPY --from=builder /app/node_modules ./node_modules | ||
| COPY --from=builder /app/package.json ./package.json | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV PORT 3000 | ||
|
|
||
| # Next.js collects completely anonymous telemetry data about general usage. | ||
| # Learn more here: https://nextjs.org/telemetry | ||
| # Uncomment the following line in case you want to disable telemetry. | ||
| # ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
|
||
| CMD ["node_modules/.bin/next", "start"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个stage可以不加