I am having trouble installing a private github package with my lerna monorepo using AWS Amplify hosting.
I have updated the build settings to create a .npmrc file at the time of build and install the package in the preBuild stage, however when it begins the build stage it cannot find the module.
Reproduction steps
Set up amplify hosting for react app as monorepo (Lerna)
Update build settings to create .npmrc and install package
Run build
Build settings
version: 1
applications:
- backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install --frozen-lockfile
- echo -e "always-auth=true\n#apptractive:registry=https://npm.pkg.github.com/\n//npm.pkg.github.com/:_authToken=$NPM_AUTH_TOKEN" > .npmrc
- yarn add #apptractive/shared
- yarn add #apptractive/design-system-web
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
appRoot: packages/backoffice-app
Error that shows
Okay I found that I needed to build the packages within the build script as they were being imported from the monorepo itself and not github packages.
Probably can be done with a better approach, but this got me over the line for now
version: 1
applications:
- backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn global add lerna
- npm config set registry https://npm.pkg.github.com
- npm config set always-auth true
- npm config set //https://npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}
- lerna bootstrap --include-dependencies
- cd ../shared && yarn build
- cd ../design-web && yarn build
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
appRoot: packages/backoffice-app
Related
Problem: A variety of tutorials from AWS for integrating automated testing with CI/CD look to integrate the testing stage after, or within the build process by using a localhost:3000 server.
However, as AWS Amplify developers know, the local environment can sometimes offer a different user experience to deploying to a development environment, and using that environment with AWS Amplify's hosting service.
Therefore, how do I add testing not only at the build stage with localhost:3000, but also for the development environment's hosted url?
I'm looking to build all my resources (backend and front-end), with a git push to the code commit repository.
Idea of Stages:
Source
Build
Test
Deploy Cloud Formation Stacks
Test
Roll back if failure
Current amplify.yml:
Note: this currently does not work so please do not copy it for your build. Please refer to the hyperlink above.
version: 0.2
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
test:
phases:
preTest:
commands:
- npm ci
- npm install wait-on
- npm install pm2
- npm install mocha mochawesome mochawesome-merge mochawesome-report-generator
- npx pm2 start npm -- dev
- 'npx wait-on --timeout 300 http://localhost:3000'
test:
commands:
- 'npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
- npx pm2 kill
artifacts:
baseDirectory: cypress
configFilePath: '**/mochawesome.json'
files:
- '**/*.png'
- '**/*.mp4'
Running into several problems while trying to deploy NextJS applications within my mono-repo to AWS Amplify-
Amplify has difficulty detecting that this is a NextJS application
Confusion on where to run build commands from / the location of dist
I found (limited) documentation on creating an amplify.yml spec for a monorepo deployment on AWS Amplify. I'm not quite sure what I want to configure particular variables as, since I'm not sure what Amplify is doing under the hood when you deploy.
Here's what I'm working with:
version: 1
applications:
- appRoot: ./apps/myNextJsApp
frontend:
phases:
preBuild:
commands:
- cd ../..
- yarn install
build:
commands:
- npx nx build myNextJsApp --prod
artifacts:
files:
- dist/apps/myNextJsApp/.next
discard-paths: yes
baseDirectory: location
cache:
paths:
- dist/apps/myNextJsApp/cache
test:
phases:
preTest:
commands:
- *enter command*
test:
commands:
- *enter command*
postTest:
commands:
- *enter command*
artifacts:
files:
- location
- location
configFilePath: *location*
baseDirectory: *location*
My specific questions:
What is the proper appRoot? It would seem to me that it would be the apps/myApp directory, however I see some documentation within Nx that it should be just ./.
Is yarn install my only necessary pre-build command? In that .yml I have it configured for starting in the apps/myApp directory and the cd'ing out to the root where my yarn.lock & package.json are located.
Is npx nx build myApp --prod sufficient?
Is this the correct location in my amplify.yml to specify my .next and cache directories?
What do baseDirectory and discard-paths do?
Thank you in advance to anyone who can help me demystify the amplify.yml.
I am trying to add a pipeline to my project. The project is a AWS Lambda written in dotnet. I want to build a pipeline so that it is deployed to AWS whenever I update the code of my Lambda. Here is my code for the pipeline:
image: mcr.microsoft.com/dotnet/core/sdk:3.1
stages:
- build
- deploy
- production
before_script:
- apt update
- apt-get -y install zip
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install -g Amazon.Lambda.Tools
build:
stage: 'build'
script:
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- echo `aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION` | sh
- dotnet nuget add sourceĀ url
- dotnet restore
- cd SmoothRunningsAuth
- dotnet lambda package -o publish/$CI_PIPELINE_ID.zip
when: always
artifacts:
name: "$CI_JOB_NAME"
paths:
- project/publish/$CI_PIPELINE_ID.zip
I have tested all of these commands locally and they work fine when I build the package. dotnet nuget add source url is required as I am using packages from a private repository I am using.
However when I push this to GitLab it returns the following errors:
I am not sure why this is happening, it runs all the other dotnet commands fine and this is the command I use when I am trying to add sources.
I'm struggling to create a BitBucket Pipeline script which can compile a DotNet Core application, run it and then deploy the output html files to Firebase using the CLI.
image: microsoft/dotnet:sdk
pipelines:
default:
- step:
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build MySolution.sln
branches:
master:
- step:
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build MySolution.sln
- cd MySolution
- dotnet run MySolution.
- npm install -g firebase-tool
- firebase deploy --token "$FIREBASE_TOKEN"
The image microsoft/dotnet:sdk doesn't contain npm or the Firebase-Tools package I require. I'm struggling to find an alternative Docker Image which contains both dotnet and npm / Firebase-Tools. Is there a simpler way to deploy the output of the application to Firebase directly from BitBucket?
I think you should dig into the multi-step approach of Bitbucket pipelines. There you will be able to run each of the steps with different docker images.
More documentation you may find at Bitbucket here
For example:
pipelines:
default:
- step:
name: Build and test
image: microsoft/dotnet:sdk
script:
- dotnet restore
- dotnet build
- dotnet publish -o /out -c Release
artifacts:
- out/**
- step:
name: Run npm
image: node:8
script:
- npm install -g firebase-tool
- firebase deploy --token "$FIREBASE_TOKEN"
- step
name: Run app
image: microsoft/dotnet:sdk
script:
- dotnet run MySolution .
I added .travis.yml to my project and each time I commit to master branch, it runs all tests / scripts ok but last firebase deploy fails consistently with error like below:
But certainly I am installing dependencies under functions folder and can deploy on localhost with no problem.
My .travis.yml looks like:
language: node_js
node_js:
- 6
branches:
only:
- master
install:
- yarn
- CI=false yarn build:ssr
- yarn fns:deps
after_success:
- node_modules/.bin/firebase deploy --non-interactive --token "$FIREBASE_TOKEN" --project react-joanne
deploy:
provider: firebase
skip_cleanup: true
token:
secure: "$FIREBASE_TOKEN"
project: "react-joanne"