-
Notifications
You must be signed in to change notification settings - Fork 0
MI-85: Multi package managers & improvements #10
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
Merged
kai-nguyen-aligent
merged 11 commits into
main
from
feature/MI-85-multi-package-managers
Nov 21, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9417432
MI-85: Refactor & support color on logging
kai-nguyen-aligent 5b895d2
MI-85: Remove ts-node dependency
kai-nguyen-aligent df7c1c3
MI-85: Update docker file
kai-nguyen-aligent 116b2db
MI-85: Update workflow
kai-nguyen-aligent a663245
MI-85: Update document
kai-nguyen-aligent 7898b79
MI-85: Remove redundant pipe.yml
kai-nguyen-aligent d00e93d
MI-85: Use stdio inherit for preserving cli colours
kai-nguyen-aligent eb2d9d1
MI-85: Upgrade docker image build process
kai-nguyen-aligent e0f8881
MI-85: Update document
kai-nguyen-aligent b120ed4
MI-85: Update build steps
kai-nguyen-aligent 135c068
MI-85: Update document
kai-nguyen-aligent 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
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 |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| node_modules | ||
| dist | ||
| .vscode/settings.json |
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 |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| ARG NODE_TAG | ||
| ARG NODE_TAG=latest | ||
kai-nguyen-aligent marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FROM node:${NODE_TAG}-alpine | ||
|
|
||
| RUN mkdir /pipe | ||
| WORKDIR /pipe | ||
|
|
||
| RUN apk add wget | ||
| RUN wget -P / https://bitbucket.org/bitbucketpipelines/bitbucket-pipes-toolkit-bash/raw/0.4.0/common.sh | ||
| # The `--force` flag force replace `yarn` if it exist in base image | ||
| # This ensure we have the latest version of package managers | ||
| RUN npm install -g --force npm pnpm yarn | ||
|
|
||
| COPY tsconfig.json ./ | ||
| COPY pack*.json ./ | ||
| RUN npm ci | ||
| COPY entrypoint.sh ./ | ||
| COPY pipe ./pipe | ||
| RUN chmod a+x ./pipe/*.ts entrypoint.sh | ||
| COPY node_modules ./node_modules | ||
| COPY dist/ ./ | ||
kai-nguyen-aligent marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| COPY entrypoint.sh package.json ./ | ||
|
|
||
| RUN chmod a+x ./**/*.js entrypoint.sh | ||
kai-nguyen-aligent marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ENTRYPOINT ["/pipe/entrypoint.sh"] | ||
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
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,92 @@ | ||
| import chalk from 'chalk'; | ||
| import logSymbols from 'log-symbols'; | ||
| import { runCLICommand } from '../lib/cmd'; | ||
| import { env } from '../lib/env'; | ||
| import { nodeModulesDirectoryExist } from '../lib/findNodeModules'; | ||
| import { findServerlessYaml } from '../lib/findServerlessYaml'; | ||
| import { injectCfnRole } from '../lib/injectCfnRole'; | ||
| import { | ||
| detectPackageManager, | ||
| getInstallCommand, | ||
| } from '../lib/packageManagers'; | ||
| import { isNxServerlessMonorepo } from '../lib/serverlessProjectType'; | ||
| import { uploadDeploymentBadge } from '../lib/uploadDeploymentBadge'; | ||
|
|
||
| async function main() { | ||
| let deploymentStatus = false; | ||
|
|
||
| try { | ||
| const { | ||
| awsAccessKeyId, | ||
| awsSecretAccessKey, | ||
| bitbucketCloneDir, | ||
| cfnRole, | ||
| cmd, | ||
| debug, | ||
| profile, | ||
| servicesPath, | ||
| stage, | ||
| } = env; | ||
|
|
||
| if (!awsAccessKeyId || !awsSecretAccessKey) { | ||
| throw new Error( | ||
| 'AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY not set' | ||
| ); | ||
| } | ||
|
|
||
| const packageManager = detectPackageManager(bitbucketCloneDir); | ||
| const isMonorepo = await isNxServerlessMonorepo(bitbucketCloneDir); | ||
|
|
||
| const searchDirectory = isMonorepo | ||
| ? `${bitbucketCloneDir}/${servicesPath}` | ||
| : bitbucketCloneDir; | ||
|
|
||
| let serverlessFiles = await findServerlessYaml(searchDirectory); | ||
|
|
||
| await Promise.all( | ||
| serverlessFiles.map((file) => injectCfnRole(file, cfnRole)) | ||
| ); | ||
|
|
||
| const commands = [ | ||
| `npx serverless config credentials --provider aws --profile ${profile} --key ${awsAccessKeyId} --secret ${awsSecretAccessKey}`, | ||
| ]; | ||
|
|
||
| const isNodeModulesExists = await nodeModulesDirectoryExist( | ||
| bitbucketCloneDir | ||
| ); | ||
| if (!isNodeModulesExists) { | ||
| const installCmd = getInstallCommand(packageManager); | ||
| commands.unshift(installCmd); | ||
| } | ||
|
|
||
| const baseCommand = isMonorepo | ||
| ? `npx nx run-many -t ${cmd} --` | ||
| : `npx serverless ${cmd}`; | ||
| const verbose = debug ? '--verbose' : ''; | ||
|
|
||
| commands.push( | ||
| `${baseCommand} --stage ${stage} --aws-profile ${profile} ${verbose}` | ||
| ); | ||
|
|
||
| await runCLICommand(commands, bitbucketCloneDir); | ||
|
|
||
| deploymentStatus = true; | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| console.error(logSymbols.error, chalk.redBright(error.message)); | ||
| } | ||
| console.error( | ||
| logSymbols.error, | ||
| chalk.redBright( | ||
| 'Deployment failed! Please check the logs for more details.' | ||
| ) | ||
| ); | ||
| deploymentStatus = false; | ||
| } finally { | ||
| const statusCode = await uploadDeploymentBadge(deploymentStatus); | ||
| process.exit(statusCode); | ||
| } | ||
| } | ||
|
|
||
| // Execute the main function | ||
| main(); |
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 |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| #!/bin/sh | ||
| #set -x | ||
|
|
||
| cd /pipe | ||
| npx ts-node pipe/entrypoint.ts | ||
| node /pipe/bin/index.js |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.